![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#4
|
||||
|
||||
|
Pues si lo haces con builder aqui va un ejemplo que rula en internet desde hace tiempo
Solo hay que poner 1 TTimer y 2 TImage... Código: void __fastcall TForm1::FormCreate(TObject *Sender) { Timer1->Enabled = false; DoubleBuffered = true; Form1->Caption = "GAME"; Form1->ClientWidth = 200; Form1->ClientHeight = 200; Form1->BorderStyle = bsDialog; Form1->Position = poDesktopCenter; Image1->Top = 0; Image1->Left = 0; Image1->Width = 200; Image1->Height= 200; Image1->Visible = false; Image2->Top = 0; Image2->Left = 0; Image2->Width = 200; Image2->Height= 200; jx = 100; jy = 175; sf = 0; ef = 1; ex = 100; ey = 15; eh = 0; score = 0; miss = 0; Image1->Canvas->Brush->Color = clBlack; Image1->Canvas->FillRect( Rect( 0, 0, 200,200) ); Timer1->Interval = 45; Timer1->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { switch ( Key ) { case VK_SPACE: KS = 1; break; case VK_LEFT : K4 = 1; break; case VK_RIGHT: K6 = 1; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { switch ( Key ) { case VK_SPACE: KS = 0; break; case VK_LEFT : K4 = 0; break; case VK_RIGHT: K6 = 0; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Image1->Canvas->FillRect( Rect( 0, 0, 200, 200 ) ); Image1->Canvas->Font->Size = 11; Image1->Canvas->Font->Color = clSilver; Image1->Canvas->TextOut( 20, 1, "Score" ); Image1->Canvas->TextOut( 132, 1, "Miss" ); Image1->Canvas->Font->Color = clFuchsia; Image1->Canvas->TextOut( 66, 1, IntToStr( score ) ); Image1->Canvas->TextOut( 175, 1, IntToStr( miss ) ); Image1->Canvas->Font->Size = 16; if ( miss > 2 ) { Image1->Canvas->Font->Color = clYellow; Image1->Canvas->TextOut( 50, 100, "Game Over" ); Timer1->Enabled = false; } if ( K4 == 1 ) { if ( jx > 10 ) jx -= 5; } if ( K6 == 1 ) { if ( jx < 185 ) jx += 5; } Image1->Canvas->Font->Color = clAqua; Image1->Canvas->TextOut( jx-9, jy, "<>" ); if ( sf == 0 && KS == 1 ) { sf = 1; sx = jx; sy = jy-5; } if ( sf == 1 ) { sy -= 6; Image1->Canvas->Font->Color = clYellow; Image1->Canvas->TextOut( sx-9, sy, "¨" ); if ( (ex-sx) > -26 && (ex-sx) < 23 ) { if ( (ey-sy) > -13 && (ey-sy) < 13 ) { ef = 2; sf = 0; score += 10; } } if ( sy < -10 ) { ++miss; sf = 0; } } if ( ef == 1 ) { if ( eh == 0 ) { ex -= 4; if ( ex < 22 ) eh = 1; } else { ex += 4; if ( ex > 195 ) eh = 0; } } if ( ef == 1 ) { Image1->Canvas->Font->Color = clRed; Image1->Canvas->TextOut( ex-19, ey, "oo" ); } else { Image1->Canvas->Font->Color = clYellow; if ( ef%2 == 0 ) { Image1->Canvas->TextOut( ex-19, ey, "oo" ); } else { Image1->Canvas->TextOut( ex-19, ey, "oo" ); } if ( ++ef > 20 ) ef = 0; } if ( ef == 0 ) { ex = 100; eh = random(2); } Image2->Canvas->CopyRect( Image2->Canvas->ClipRect, Image1->Canvas, Image2->Canvas->ClipRect); } //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TImage *Image1; TImage *Image2; TTimer *Timer1; void __fastcall FormCreate(TObject *Sender); void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift); void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift); void __fastcall Timer1Timer(TObject *Sender); private: // User declarations int jx, jy; int sx, sy; int ex, ey; int sf; int ef; int eh; int score; int miss; int K4, K6, KS; public: // User declarations __fastcall TForm1(TComponent* Owner); }; // y ya esta |
|
|
|