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 Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 27-10-2016
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Poder: 0
Snaked Va por buen camino
Ecfisa: ya lo he solucionado.... he adaptado tu funcion al TTimer de la siguiente manera

1) declaro como globales las siguientes variables

Código PHP:
TPoint INICIO_NAVE;
TPoint DESTINO_NAVE;
bool STOP_MOVIMIENTO_NAVE = false;
int x = 0; int y = 0;
int dx = 0;
int dy = 0; 
y luego en el TTimer tengo puesto esto

Código PHP:
  if(x < DESTINO_NAVE.x) { x++; y = INICIO_NAVE.y + dy * (x - INICIO_NAVE.x) / dx; }
  else 
STOP_MOVIMIENTO_NAVE = true; 
de forma que cada vez que se produce un tick del timer avanza por la linea

y luego en el dibujado del mapa en pantalla tengo asi

Código PHP:
 void Muestra_Mapa(void)
{

   
SECTOR_VEGA();

   
//Dibuja la nave 1
      
Form1->g2 = 0;
      
Form1->g2 = Form2->Image_explorer1->Picture->Graphic;
      
Form1->tablero->Canvas->Draw(x, y,  Form1->g2);

    if(
rejilla) Muestra_Rejilla();


 
Form1->tablero->Repaint();
 
Form1->skreen->Picture->Graphic = Form1->tablero->Picture->Graphic;
 
Application->ProcessMessages();

} 

y para comenzar el proceso de animacion, esto en un TButton (enviar nave de exploracion)

Código PHP:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 
pos_nave1X = 40 + Form2->Image2->Picture->Graphic->Width-80;
 
pos_nave1Y = 40 + Form2->Image2->Picture->Graphic->Height;
 
INICIO_NAVE = Point( 40 + Form2->Image2->Picture->Graphic->Width/2, 40 + Form2->Image2->Picture->Graphic->Width/2);
 
DESTINO_NAVE = Point( 240, 410);

  
dx = DESTINO_NAVE.x - INICIO_NAVE.x;
  
dy = DESTINO_NAVE.y - INICIO_NAVE.y;
  
x = INICIO_NAVE.x;
}
//--------------------------------------------------------------------------- 
Responder Con Cita
  #2  
Antiguo 27-10-2016
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Snaked.

Me alegro que encontraras una solución ( y muchas gracias por compartirla )

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #3  
Antiguo 27-10-2016
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Poder: 0
Snaked Va por buen camino
Aqui os dejo el video de lo que intentaba hacer Ecfisa

Responder Con Cita
  #4  
Antiguo 27-10-2016
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.714
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
Cuando sea mayor también haré videojuegos
Responder Con Cita
  #5  
Antiguo 28-10-2016
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Poder: 0
Snaked Va por buen camino
Ecfisa: A ver si me puedes ayudar un poco tu que creo que entiendes de C++

ahora que ya he solucionado lo de la nave que se mueve por las lineas-ruta..... bien, solo lo hace con una nave pero como haria si tuviese que mover mas naves?? es decir, como podria declarar un array de naves o algo asi teniendo en cuenta la informacion que hemos estado manejando??? quiero decir...mover varias naves simultaneamente y que cada una vaya por una ruta distinta del mapa

simplemente alguna idea y luego ya la trabajo yo

Última edición por Snaked fecha: 28-10-2016 a las 12:50:54.
Responder Con Cita
  #6  
Antiguo 28-10-2016
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Snaked.

A ver... fijate si esta idea te puede servir aunque sea como puntapié inicial.
Código PHP:
//...
const int MAX_X = 1366;

class 
Ship {
private:
  
TPoint _route[MAX_X];
  
TPoint _start;
  
TPoint _stop;
  
int _toproute;
  
int calcRoute();
  const 
TPoint &getPt(const int &ix) { return _route[ix]; }
public:
  
Ship( const TPoint& start, const TPoint& stop);
  
__property int topRoute = { read = _toproute };
  
__property TPoint route[int] = { read = getPt };
};

Ship::Ship( const TPoint& start, const TPoint& stop) {
  
_start = start;
  
_stop  = stop;
  
_toproute  = calcRoute();
}

int Ship::calcRoute()
{
  
int dx = _stop.x - _start.x;
  
int dy = _stop.y - _start.y;
  
int c, x;

  for(
c=0, x = _start.x; x < _stop.x; c++, x++ ) {
    
int y = _start.y + dy * ( x - _start.x ) / dx;
    
_route[c].x = _start.x + x;
    
_route[c].y = y;
  }
  return 
c;
}

Ship ship1 = Ship(Point(  10, 100 ), Point( 240, 200 ));
Ship ship2 = Ship(Point(  50,  50 ), Point( 150, 300 ));
Ship ship3 = Ship(Point(  80, 90 ), Point(  220, 100 ));
int c1, c2, c3;

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  
Image1->Visible  = false;
  
Image2->Visible  = false;
  
Image3->Visible  = false;
  
Timer1->Interval = 15;
  
Timer2->Interval = 15;
  
Timer3->Interval = 15;
  
Timer1->Enabled  = false;
  
Timer2->Enabled  = false;
  
Timer3->Enabled  = false;
}

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  
Image1->Visible = c1 < ship1.topRoute;
  
Timer1->Enabled = Image1->Visible;
  if (
Image1->Visible) {
    
Image1->Left = ship1.route[c1].x;
    
Image1->Top  = ship1.route[c1].y;
  }
  ++
c1;
}

void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
  
Image2->Visible = c2 < ship2.topRoute;
  
Timer2->Enabled = Image2->Visible;
  if (
Image2->Visible) {
    
Image2->Left = ship2.route[c2].x;
    
Image2->Top  = ship2.route[c2].y;
  }
  ++
c2;
}

void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
  
Image3->Visible = c3 < ship3.topRoute;
  
Timer3->Enabled = Image3->Visible;
  if (
Image3->Visible) {
    
Image3->Left = ship3.route[c3].x;
    
Image3->Top  = ship3.route[c3].y;
  }
  ++
c3;
}

void __fastcall TForm1::btnStartClick(TObject *Sender)
{
  
c1 = c2 = c3 = 0;
  
Timer1->Enabled = true;
  
Timer2->Enabled = true;
  
Timer3->Enabled = true;
}

//... 
Efecto:



Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #7  
Antiguo 29-10-2016
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola de nuevo.

La idea anterior, encapsulada y un poco mas organizada :

Ship.h
Código PHP:
#ifndef ShipH
#define ShipH

#include <ExtCtrls.hpp>
#include <jpeg.hpp>

const int MAX_X = 1366;

class 
Ship {
private:
  
TImage*      _image;
  
TTimer*      _timer;
  
TWinControl* _parent;
  
TPoint       _route[MAX_X];
  
TPoint       _start;
  
TPoint       _stop;
  
int          _inx;
  
int          _toproute;
  
int calcRoute();
  const 
TPoint &getPt( const int &ix );
  
void setParent( TWinControl* parent );
  
void __fastcall _timerTimer(TObject *Sender);
public:
  
Ship( TWinControl* parent, const TPoint& start, const TPoint& stop);
  ~
Ship();
  
__property TWinControl* Parent = { read = _parent, write = setParent };
  
__property TImage* Image = { read = _image, write = _image };
  
__property TTimer* Timer = { read = _timer, write = _timer };
  
__property int TopRoute = { read = _toproute };
  
__property TPoint Route[int] = { read = getPt };
};
 
#endif 
Ship.cpp
Código PHP:
#pragma hdrstop
#include "Ship.h"  
#pragma package(smart_init)

Ship::Ship( TWinControl* parent, const TPoint& start, const TPoint& stop ) {
  
_start     = start;
  
_stop      = stop;
  
_inx       = 0;
  
_toproute  = calcRoute();
  
_image = new TImage(NULL);
  
_image->Visible  = false;
  
_image->Parent   = parent;
  
_image->Left     = start.x;
  
_image->Top      = start.y;
  
_timer = new TTimer(NULL);
  
_timer->Interval = 20; 
  
_timer->Enabled  = false;
  
_timer->OnTimer  = _timerTimer;
}

Ship::~Ship()
{
  
delete _timer;
  
delete _image;
}

/* private */
int Ship::calcRoute()
{
  
int dx = _stop.x - _start.x;
  
int dy = _stop.y - _start.y;
  
int c, x;

  for(
c=0, x = _start.x; x < _stop.x; c++, x++ ) {
    
int y = _start.y + dy * ( x - _start.x ) / dx;
    
_route[c].x = _start.x + x;
    
_route[c].y = y;
  }
  return 
c;
}

const 
TPoint& Ship::getPt( const int &ix )
{
  return 
_route[ix];
}

void Ship::setParent( TWinControl* parent )
{
  
_image->Parent = parent;
}

void __fastcall Ship::_timerTimer(TObject *Sender)
{
  
_image->Visible = _inx < _toproute;
  
_timer->Enabled = _image->Visible;
  if (
_image->Visible) {
    
_image->Left = _route[_inx].x;
    
_image->Top  = _route[_inx].y;
  }
  else {
    
_inx = 0;
  }
  ++
_inx;
} 
Ejemplo del uso:
Código PHP:
#pragma hdrstop
#include "Unit1.h"
#include "Ship.h"
#pragma package(smart_init)
#pragma resource "*.dfm"


TForm1 *Form1;

__fastcall TForm1::TForm1(TComponent* Owner)
  : 
TForm(Owner)
{
}
Ship* s1;
Ship* s2;
Ship* s3;

void __fastcall TForm1::FormCreate(TObject *Sender)
{
 
s1 = new Ship( this, Point(10,100), Point( 240,200) );
 
s2 = new Ship( this, Point(  50,  50 ), Point( 150, 300 ) );
 
s3 = new Ship( this, Point(  80, 90 ), Point(  220, 100 ) );

 
s1->Image->Picture->LoadFromFile("face-smile.jpg");
 
s2->Image->Picture->LoadFromFile("face-sad.jpg");
 
s3->Image->Picture->LoadFromFile("face-monkey.jpg");

 
s1->Timer->Interval = 10;
 
s2->Timer->Interval = 10;
 
s3->Timer->Interval = 10;
}

void __fastcall TForm1::btnStartClick(TObject *Sender)
{
  
s1->Timer->Enabled = true;
  
s2->Timer->Enabled = true;
  
s3->Timer->Enabled = true;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  
delete s1;
  
delete s2;
  
delete s3;
} 
Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #8  
Antiguo 29-10-2016
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 14
aguml Va por buen camino
Ecfisa eso último ¿sería un componente? SI no es asi ¿que le faltaría ya para serlo? Lo digo porque tiene propiedades y métodos al igual que un componente.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
Copiar TLabel.Canvas sobre TBitmap.Canvas @CSE1970 Gráficos 2 23-10-2013 13:46:53
Impresion linea por linea en tiquete de caja Livey Impresión 2 21-12-2010 01:21:05
uso de DLL creada con VB6 lichi OOP 0 12-09-2005 17:55:46
Como imprimir por canvas un caracter de salto de linea buitrago Impresión 3 30-08-2004 12:10:05
¿Cómo borrar un grid sin tener que ir línea a línea? Isaac Varios 2 18-02-2004 17:13:14


La franja horaria es GMT +2. Ahora son las 20:38:52.


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