Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #13  
Antiguo 05-10-2015
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.210
Poder: 22
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
He preparado un ejemplo simple con el componente TNMUDP. Lo he probado contra la IP Local 127.0.0.1 en tres copias de la misma aplicación configurando los puertos para que la pelotita salte de una a otra. El Timer está a 5 ms. Publico un pequeño vídeo.

Código PHP:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include <math.h>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Unit2"
#pragma resource "*.dfm"
TForm1 *Form1;

struct TData{
  
char HEADER[3];
  
char SD;
  
double Vx;
  
double Vy;
  
double X;
  
double Y;
};


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponentOwner)
  : 
TForm(Owner)
{
  
Connect();
  
Timer1->Enabled false;
  
Frame1->Visible false;
  
Frame1->DoubleBuffered true;
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  
double t 0.01;
  
double Vy 9.8*t;

  
+= 1000*(Vy+Voy)*t;
  if(
Frame1->Height >= Panel1->Height){
    
Panel1->Height Frame1->Height;
    
Voy = -Voy*0.95;   // reducción Y
    
Vox *= 0.98;      // reducción X
  
}else
    
Voy += Vy;

  
+= Vox*t;
  
Frame1->Top Y;
  
Frame1->Left X;

  if(
Frame1->Width >= Panel1->Width && IsPelota){
    
TData Data;
    
Data.Vx Vox;
    
Data.Vy Voy;
    
Data.X;
    
Data.Y;
    
NMUDP1->SendBuffer((char*)&Datasizeof(TData), sizeof(TData));
    
IsPelota false;
  }
  if(
>= Panel1->Width){
    
Timer1->Enabled false;
  }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button2Click(TObject *Sender)
{
  
Connect();
  
IsPelota true;
  
Vox 800;     // Velocidad inicial X
  
Voy 0;       // Velocidad inicial Y
  
0;
  
0;
  
Frame1->Top 0;
  
Frame1->Left 0;
  
Frame1->Visible true;
  
Timer1->Enabled true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NMUDP1DataReceived(TComponent *Sender,
      
int NumberBytesAnsiString FromIPint Port)
{
  if(
NumberBytes == sizeof(TData)){
    
TData Data;
    
NMUDP1->ReadBuffer((char*)&Datasizeof(TData), NumberBytes);
    
Vox Data.Vx;
    
Voy Data.Vy;
    
0;
    
Data.Y;
    
Frame1->Left 0;
    
Frame1->Top Y;
    
Frame1->Visible true;
    
Timer1->Enabled true;
    
IsPelota true;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Connect()
{
  
NMUDP1->RemoteHost Edit1->Text;
  
NMUDP1->RemotePort StrToIntDef(Edit2->Text0);
  
NMUDP1->LocalPort  StrToIntDef(Edit3->Text0);
}

//---------------------------------------------------------------------------
void __fastcall TForm1::EditChange(TObject *Sender)
{
  
Connect();
}
//--------------------------------------------------------------------------- 
https://youtu.be/dowjot2OILo

Última edición por escafandra fecha: 05-10-2015 a las 17:38:48.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Como hago para cargar el Socket Server como un servicio en cualquier windows ferdanjua Servers 1 07-09-2010 12:05:46
como hacer consulta para crear dos campos a partir de uno Rom@n SQL 2 24-12-2008 17:56:37
Crear componente de socket para cliente Belaix Internet 5 23-11-2008 15:20:01
como transferir tablas dbf en uso Rom@n Conexión con bases de datos 1 01-03-2008 23:51:59
Como transferir datos de un ADOquery a un Formulario maru1981 OOP 10 30-07-2007 02:52:02


La franja horaria es GMT +2. Ahora son las 21:00:32.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi