Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
// Vektor für Positionen struct poszeiger { float xPos; float yPos; }; // Klasse des Balles class gameball { private: DWORD time; DWORD now; int speed; public: poszeiger ball; void init (); int move (); }; // Startwerte setzen void gameball::init () { time = timeGetTime (); speed = 100; ball.xPos = 170; ball.yPos = 200; } // Ball bewegen (noch nicht komplett) int gameball::move() { DWORD tick; now = timeGetTime (); tick = (now-time)*speed; ball.xPos = static_cast<float>(ball.xPos + tick); ball.yPos = static_cast<float>(ball.yPos + tick); return 1; } // Instanz der Klasse gameball gameball rball; // Klasse des Spiels class ppb { private: int points; void init (); int speed; DWORD time; public: void reset_timer () {time = timeGetTime ();} void faster () {speed += 50;} void slower () {if (speed > 50) speed -= 50;} int game_run; void start (); void display (); }; void ppb::init () { game_run = 0; points = 0; } void ppb::start () { reset_timer (); speed = 100; init (); game_run = 1; } void ppb::display () { ppb_display.backgrnd (); ppb_display.gplayer1 (); ppb_display.gball (); ppb_display.present (); } // Instanz der Spielerklasse ppb game; // Ausschnitt WinMain [...] while( TRUE) { if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE)) { if( GetMessage( &msg, NULL, 0, 0 ) == 0) return 0; // Message ist WM_QUIT if( TranslateAccelerator( ppb_window, acc, &msg) == 0) { TranslateMessage( &msg); DispatchMessage( &msg); } } else { HRESULT hr; hr = ppb_display.cooperative (); if (hr < 0) { switch (hr) { case DDERR_EXCLUSIVEMODEALREADYSET: Sleep(10); break; case DDERR_WRONGMODE: ppb_display.free_all (); ppb_display.init (ppb_window); PostMessage (ppb_window, WM_PAINT, 0, 0); break; if (game.game_run) { if (rball.move ()); game.display (); } else { WaitMessage (); game.reset_timer (); } } } } } } |
Quellcode |
|
1 2 3 4 5 |
_______________ / / / / |
Quellcode |
|
1 2 3 4 5 |
_______________ \ \ \ \ |
Zitat von »"Elloran"«
Denke ich zu kompliziert?
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
int gameball::move() { curtime = timeGetTime (); curtime /= 1000; elapsedtime = curtime-lasttime; lasttime = curtime; xPos = GetxPos (); yPos = GetyPos (); if (xPos <= 0) hitx = LEFT; if (xPos >= 735) hitx = RIGHT; if (yPos <= 0) hity = UP; if (yPos >= 399) hity = DOWN; switch (hitx) { case LEFT: incdecx = 1; break; case RIGHT: incdecx = -1; break; }; switch (hity) { case UP: incdecy = 1; break; case DOWN: incdecy = -1; }; Setpos (xPos + ((incdecx*speed)*elapsedtime), yPos + ((incdecy*speed)*elapsedtime)); return 1; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
HRESULT hr; hr = ppb_display.cooperative (); if (hr < 0) { switch (hr) { case DDERR_EXCLUSIVEMODEALREADYSET: Sleep(10); break; case DDERR_WRONGMODE: ppb_display.free_all (); ppb_display.init (ppb_window); PostMessage (ppb_window, WM_PAINT, 0, 0); break; } } else { if (game.game_run) { if (rball.move ()) game.display (); } else { WaitMessage (); rball.reset_timer (); } } |
Werbeanzeige