Guest User

Untitled

a guest
Nov 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. bool platformCollision(float x, float y, int w, int h) {
  2. return y + h > platform.y &&
  3. x + 48 >= platform.x &&
  4. x + w - 48 <= platform.x + platform.w;
  5. }
  6.  
  7. void update() {
  8.  
  9. // Zombies
  10. for (int i = 0; i < ZOMBIE_COUNT; i++) {
  11. if (zombies[i].alive) {
  12.  
  13. // Apply gravity
  14. zombies[i].vY += world.gravity;
  15. zombies[i].y += zombies[i].vY;
  16.  
  17. // Motion
  18. zombies[i].x += zombies[i].vX;
  19. zombies[i].vX = zombieSpeed * zombies[i].dir;
  20.  
  21. // Platform
  22. if (platformCollision(zombies[i].x, zombies[i].y, zombieWidth, zombieHeight)) {
  23. zombies[i].y = platform.y - zombieHeight;
  24. zombies[i].vY = 0;
  25. } else {
  26. zombies[i].vX = 0;
  27. }
  28.  
  29. // Death
  30. if (zombies[i].y > SCREEN_HEIGHT) {
  31. zombies[i].alive = false;
  32. }
  33.  
  34. }
  35. }
  36.  
  37. // Spawn zombie every N seconds
  38. currentTime = SDL_GetTicks();
  39. if (currentTime > lastSpawnTime + SPAWN_FREQ * 1000) {
  40. spawnZombie();
  41. lastSpawnTime = currentTime;
  42. }
  43. }
Add Comment
Please, Sign In to add comment