summaryrefslogtreecommitdiff
path: root/Level.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Level.cpp')
-rw-r--r--Level.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/Level.cpp b/Level.cpp
index 6655777..652284d 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -38,6 +38,11 @@ void Level::changeLevel(int levelNo) {
player.setY(startY);
cameraX = 0;
+
+ // Give him some weapons
+ player.obtainWeapon(0);
+ player.obtainWeapon(1);
+
}
void Level::move() {
@@ -111,6 +116,33 @@ void Level::move() {
}
player.orient();
+
+ // Move the visible weapon with the player
+ player.weapon->setX(player.getX() + WEAPON_OFFSET_X);
+ player.weapon->setY(player.getY() + WEAPON_OFFSET_Y);
+
+ // Move the projectiles
+ for (int i = 0; i < 10; i++) {
+ // Only calculate if they're active
+ if (player.weapon->projectiles[i].isActive()) {
+ // Move based on weapon speed
+ player.weapon->projectiles[i].setX(player.weapon->projectiles[i].getX() + player.weapon->getSpeed());
+ if (player.weapon->projectiles[i].getX() + cameraX > SCREEN_WIDTH || player.weapon->projectiles[i].getY() > SCREEN_HEIGHT || player.weapon->projectiles[i].getX() < 0 || player.weapon->projectiles[i].getY() < 0) {
+ // If they go off screen, set to inactive
+ player.weapon->projectiles[i].setActive(false);
+ }
+ // Set up a collision box for the projectiles
+ SDL_Rect bullet;
+ bullet.x = player.weapon->projectiles[i].getX();
+ bullet.y = player.weapon->projectiles[i].getY();
+ bullet.w = 20;
+ bullet.h = 20;
+ // Check collision with objects
+ if (checkCollision(bullet)) {
+ player.weapon->projectiles[i].setActive(false);
+ }
+ }
+ }
}
void Level::draw(Screen *screen) {
@@ -157,6 +189,16 @@ void Level::draw(Screen *screen) {
hazard[0].image, hazard[i].getClip());
}
}
+
+ // Draw the player's weapon
+ screen->blit(player.weapon->getX() + cameraX, player.weapon->getY(), player.weapon->image, player.weapon->getClip());
+
+ // Draw each projectile, if it's active
+ for (int i = 0; i < 10; i++) {
+ if (player.weapon->projectiles[i].isActive()) {
+ screen->blit(player.weapon->projectiles[i].getX() + cameraX, player.weapon->projectiles[i].getY(), player.weapon->projectiles[i].image, player.weapon->projectiles[i].getClip());
+ }
+ }
}
void Level::loadMap(int LevelNo) {