Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool platformCollision(float x, float y, int w, int h) {
- return y + h > platform.y &&
- x + 48 >= platform.x &&
- x + w - 48 <= platform.x + platform.w;
- }
- void update() {
- // Zombies
- for (int i = 0; i < ZOMBIE_COUNT; i++) {
- if (zombies[i].alive) {
- // Apply gravity
- zombies[i].vY += world.gravity;
- zombies[i].y += zombies[i].vY;
- // Motion
- zombies[i].x += zombies[i].vX;
- zombies[i].vX = zombieSpeed * zombies[i].dir;
- // Platform
- if (platformCollision(zombies[i].x, zombies[i].y, zombieWidth, zombieHeight)) {
- zombies[i].y = platform.y - zombieHeight;
- zombies[i].vY = 0;
- } else {
- zombies[i].vX = 0;
- }
- // Death
- if (zombies[i].y > SCREEN_HEIGHT) {
- zombies[i].alive = false;
- }
- }
- }
- // Spawn zombie every N seconds
- currentTime = SDL_GetTicks();
- if (currentTime > lastSpawnTime + SPAWN_FREQ * 1000) {
- spawnZombie();
- lastSpawnTime = currentTime;
- }
- }
Add Comment
Please, Sign In to add comment