Ir al contenido


Foto

Juego; "Mata mosca" v2


  • Por favor identifícate para responder
45 respuestas en este tema

#41 cHackAll

cHackAll

    Advanced Member

  • Administrador
  • 599 mensajes

Escrito 18 febrero 2009 - 02:28

Adjunto el codigo fuente del juego en lenguaje C, para ser exacto en BCB6. Puesto que el juego pretende ser educativo la presente es solo una respuesta a una nueva necesidad del foro ;)



c
  1. //...
  2.  
  3. WAVEHDR WaveHdr = {(LPSTR)&Buffer, sizeof(Buffer), 0, NULL, WHDR_BEGINLOOP | WHDR_ENDLOOP, INFINITE};
  4. int w2, h2, Start;
  5. HWAVEOUT hSound;
  6. double max;
  7. bool Last;
  8.  
  9. char *Elapsed()
  10. {
  11. static char Time[12] = "00:00:00.00";
  12. asm
  13. {
  14.   call GetTickCount; sub eax, [Start]; push ebx;
  15.   xor edx, edx; push 0Ah; pop ecx; div ecx;
  16.   mov ecx, 183C3C64h; lea ebx, Time[12];
  17. @loop: push ecx; xor edx, edx; movzx ecx, cl; div ecx;
  18.   xchg edx, eax; mov cl, 0Ah; div cl;
  19.   or ax, '00'; sub ebx, 3; mov [ebx], ax;
  20.   xchg edx, eax; pop ecx; shr ecx, 8; jnz @loop; pop ebx
  21. }
  22. return Time;
  23. }
  24.  
  25. #define pitagoras(a, b) sqrt(pow(a, 2) + pow(b, 2))
  26.  
  27. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
  28. {
  29. Bitmap->Width = ClientWidth;
  30. Bitmap->Height = ClientHeight;
  31. Bitmap->Canvas->Pen->Color = clGray;
  32.  
  33. Timer1->Interval = 33;
  34. randomize();
  35.  
  36. fly[0] = Image1->Picture->Bitmap;
  37. fly[1] = Image2->Picture->Bitmap;
  38. hand[true] = Image4->Picture->Graphic;
  39. hand[false] = Image3->Picture->Graphic;
  40.  
  41. w2 = ClientWidth / 2;
  42. h2 = ClientHeight / 2;
  43. max = pitagoras(w2, h2);
  44.  
  45. waveOutOpen(&hSound, WAVE_MAPPER, (PWAVEFORMATEX)"\1\0\1\0\x70\x17\0\0\x70\x17\0\0\1\0\x8\0\x10\0", 0, 0, 0);
  46. waveOutPrepareHeader(hSound, &WaveHdr, sizeof(WaveHdr));
  47. waveOutWrite(hSound, &WaveHdr, sizeof(WaveHdr));
  48.  
  49. b1Click(NULL);
  50.  
  51. SetProcessWorkingSetSize((HANDLE)-1, INFINITE, INFINITE);
  52. }
  53.  
  54. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  55. {
  56. Bitmap->Canvas->Rectangle(ClientRect);
  57. for (int Index = 0; Index <= HIGH_VECTOR; Index++)
  58. {
  59.   TPoint Value = Index ? Vector[Index - 1] : Point(random(ClientWidth * 2) - w2, random(ClientHeight * 2) - h2);
  60.   Vector[Index].x += (Value.x - Vector[Index].x) * 0.666;
  61.   Vector[Index].y += (Value.y - Vector[Index].y) * 0.666;
  62. }
  63.  
  64. Tag = (Tag + 1) % 2;
  65. POINT Points[3] = {{-fly[Tag]->Width, fly[Tag]->Height}, {fly[Tag]->Width, fly[Tag]->Height}, {-fly[Tag]->Width, -fly[Tag]->Height}};
  66. double Direction = atan2(Vector[HIGH_VECTOR].y - Vector[HIGH_VECTOR - 2].y, Vector[HIGH_VECTOR].x - Vector[HIGH_VECTOR - 2].x + 0.000666) - M_PI_2,
  67.         Radio = pitagoras(fly[Tag]->Width / 2, fly[Tag]->Height / 2);
  68. for (int Index = 0; Index < 3; Index++)
  69. {
  70.   double Angle = atan((double)Points[Index].y / Points[Index].x) - Direction;
  71.   if (Points[Index].x < 0) Angle += M_PI;
  72.   Points[Index] = Point(((cos(Angle) * Radio) + Radio) + Vector[HIGH_VECTOR].x, (Radio - (sin(Angle) * Radio)) + Vector[HIGH_VECTOR].y);
  73. }
  74. PlgBlt(Bitmap->Canvas->Handle, Points, fly[Tag]->Canvas->Handle, 0, 0, fly[Tag]->Width, fly[Tag]->Height, 0, 0, 0);
  75.  
  76. Center = Point(Vector[HIGH_VECTOR].x + Radio, Vector[HIGH_VECTOR].y + Radio);
  77. double Angle = pitagoras(Center.x - w2, Center.y - h2);
  78. int Volume = (Angle > max)? 0 : (((max - Angle) / max) * 0xFFFF);
  79. waveOutSetVolume(hSound, Volume | (Volume << 16));
  80.  
  81. bool Down = GetKeyState(VK_LBUTTON) & 0x80;
  82. TPoint Value = ScreenToClient(Mouse->CursorPos);
  83. Bitmap->Canvas->Draw(Value.x - 20, Value.y - 20, hand[Down]);
  84. if ((pitagoras(Center.x - Value.x, Center.y - Value.y) < 15) && Down && (Last != Down))
  85. {
  86.   b1->Visible++;
  87.   b2->Visible++;
  88.   Timer1->Enabled--;
  89.   Bitmap->Canvas->Rectangle(ClientRect);
  90.   Bitmap->Canvas->Font->Color = clBlack;
  91.   Bitmap->Canvas->Draw(Value.x - (Image5->Width / 2), Value.y - (Image5->Height / 2), Image5->Picture->Graphic);
  92.   waveOutPause(hSound);
  93.   ShowCursor(True);
  94. }
  95. Last = Down;
  96.  
  97. SetBkMode(Bitmap->Canvas->Handle, TRANSPARENT);
  98. TextOut(Bitmap->Canvas->Handle, 4, 1, Elapsed(), 11);
  99. Bitmap->Canvas->TextOut(ClientWidth - 60, ClientHeight - 18, "by cHackAll");
  100. FormPaint(NULL);
  101. }
  102.  
  103. //...



Edito; olvide el adjunto :p

Salud!

Archivos adjuntos

  • Archivo adjunto  307_.zip   54,82KB   4 descargas

  • 0

#42 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 18 febrero 2009 - 04:09

Hola amigo

Y porque no movemos este post a su foro correspondiente con el nombre de "El mismo mata moscas pero en C" :D

Salud OS
  • 0

#43 Caral

Caral

    Advanced Member

  • Moderador
  • PipPipPip
  • 4.266 mensajes
  • LocationCosta Rica

Escrito 18 febrero 2009 - 07:32

Hola
Eso mismo pense yo.
Saludos
  • 0

#44 cHackAll

cHackAll

    Advanced Member

  • Administrador
  • 599 mensajes

Escrito 18 febrero 2009 - 07:49

...Y porque no movemos este post a su foro correspondiente con el nombre de "El mismo mata moscas pero en C"...


Pues el subforo al que hacen referencia amigos, segun mi forma de ver las cosas está dedicado a ayudar y responder preguntas de la comunidad, y el anterior no es más que el mismo juego escrito en C. De allí tal cual sucedió con lo escrito en assembler, llegaran las dudas si es el caso.

Salud.
  • 0

#45 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.446 mensajes
  • LocationMéxico

Escrito 18 febrero 2009 - 07:54

Ah bueno, me parece bien entonces que se quede aquí.

Salud OS
  • 0

#46 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 21 febrero 2009 - 10:18

Estoy de acuerdo con cHackAll cuando piensa que la versión del juego en C debe permanecer en este hilo. Al fin y al cabo es el hilo del Juego "Mata mosca" v2 ¿Que importa, pues, el lenguaje de programación, o si se mezclan? *-)

Saludos.  ;)
  • 0




IP.Board spam blocked by CleanTalk.