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
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 |
SDL_Rect shoot_Position; shoot_Position.x = imagePosition.x; shoot_Position.y = imagePosition.y; SDL_Rect EnemyPosition; EnemyPosition.x = rand() % 700 + 100; EnemyPosition.y = 20; ... if (shoot_event == 1) { SDL_BlitSurface(shoot, 0, screen, &shoot_Position); shoot_Position.y -= 10; if(shoot_Position.y < 5) { shoot_event = 0; shoot_Position.y = imagePosition.y; shoot_Position.x = imagePosition.x; } } ... |
C-/C++-Quelltext |
|
1 2 3 |
#define SHOOT_LENGHT 6 // shoot.bmp (6x12) #define SHOOT_WIGHT 12 ... ect... |
C-/C++-Quelltext |
|
1 2 3 4 5 |
If ( shoot_Position.x + SHOOT_LENGHT == EnemyPosition.x + ENEMY_LENGHT && shoot_Position.y + SHOOT_WIGHT == EnemyPosition.y + ENEMY_WIGHT) { // ... } |
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Patty1991« (09.03.2014, 11:14)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
if ((((shoot_Position.x + shoot_width >= EnemyPosition.x) && (shoot_Position.x + shoot_width <= EnemyPosition.x + enemy_width)) || ((EnemyPosition.x + enemy_width >= shoot_Position.x) && (EnemyPosition.x + enemy_width <= shoot_Position.x + shoot_width))) && (((shoot_Position.y + shoot_height >= EnemyPosition.y) && (shoot_Position.y + shoot_height <= EnemyPosition.y + enemy_height)) || ((EnemyPosition.y + enemy_height >= shoot_Position.y) && (EnemyPosition.y + enemy_height <= shoot_Position.y + shoot_height)))) { shoot_event = 0; shoot_Position.y = imagePosition.y; shoot_Position.x = imagePosition.x; EnemyPosition.y = 20; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Patty1991« (09.03.2014, 11:21)
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
Kannst du mir die kollisition mal schnell als codeschnippsel (am besten funkionierend) posten ?
der feind were 32x32 und der schuss 6x12 groß
- Nur die if schleife mit den defines
Abgesehn von den rechtschreibfehlern muss doch folgendes passieren:
Damit eine kollision statt finden kann, muss doch schuss.x und y mit der position des feindes übereinstimmen,
da sie sich aber beide bewegen können sie sich nicht treffen - hier kommen jetz die defines ins spiel
Die kollision soll nich pixelgenau sein, sondern nur "treffend"
Quellcode |
|
1 2 3 4 |
((shoot_Position.x + shoot_width >= EnemyPosition.x && shoot_Position.x + shoot_width <= EnemyPosition.x + enemy_width) || (EnemyPosition.x + enemy_width >= shoot_Position.x && EnemyPosition.x + enemy_width <= shoot_Position.x + shoot_width)) && ((shoot_Position.y + shoot_height >= EnemyPosition.y && shoot_Position.y + shoot_height <= EnemyPosition.y + enemy_height) || (EnemyPosition.y + enemy_height >= shoot_Position.y && EnemyPosition.y + enemy_height <= shoot_Position.y + shoot_height)) |
Quellcode |
|
1 2 |
!(shoot_Position.x + shoot_width/2 < enemyPosition.x - enemy_width/2 && shoot_Position.x - shoot_width/2 > enemyPosition.x + enemy_width/2 || shoot_Position.y + shoot_height/2 < enemyPosition.y - enemy_height/2 && shoot_Position.y - shoot_height/2 > enemyPosition.y + enemy_height/2) |
Quellcode |
|
1 |
(shoot_size - enemy_size).sqrMagnitude < (shoot_Position - enemyPosition).sqrMagnitude |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige