diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/cdec.iml b/.idea/cdec.iml new file mode 100644 index 0000000..09c9cc6 --- /dev/null +++ b/.idea/cdec.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6304f14 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f5488ad --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/images/enemy.png b/images/enemy.png new file mode 100644 index 0000000..065cb41 Binary files /dev/null and b/images/enemy.png differ diff --git a/images/player.png b/images/player.png new file mode 100644 index 0000000..9f09f2e Binary files /dev/null and b/images/player.png differ diff --git a/results/s2_2025.tif b/results/s2_2025.tif new file mode 100644 index 0000000..59c6980 Binary files /dev/null and b/results/s2_2025.tif differ diff --git a/water-game.py b/water-game.py index 6c32dee..8c60e7a 100644 --- a/water-game.py +++ b/water-game.py @@ -6,7 +6,7 @@ import rasterio pygame.init() -WIDTH, HEIGHT = 1920, 1080 +WIDTH, HEIGHT = 800, 600 WIN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Water Bottle Shooter") @@ -20,7 +20,7 @@ PLAYER_SPEED = 5 WATER_SIZE = 10 WATER_SPEED = 10 -PLAYER_IMAGE_PATH = "player.png" # Path to your player image +PLAYER_IMAGE_PATH = "images/player.png" # Path to your player image try: PLAYER_IMAGE = pygame.image.load(PLAYER_IMAGE_PATH).convert_alpha() PLAYER_IMAGE = pygame.transform.scale(PLAYER_IMAGE, (PLAYER_SIZE, PLAYER_SIZE)) @@ -28,6 +28,15 @@ except Exception as e: print(f"Could not load player image: {e}") PLAYER_IMAGE = None + + +ENEMY_IMAGE_PATH = "images/enemy.png" # Path to your player image +try: + ENEMY_IMAGE = pygame.image.load(ENEMY_IMAGE_PATH).convert_alpha() + ENEMY_IMAGE = pygame.transform.scale(ENEMY_IMAGE, (PLAYER_SIZE, PLAYER_SIZE)) +except Exception as e: + print(f"Could not load player image: {e}") + ENEMY_IMAGE = None clock = pygame.time.Clock() # Load raster map as background @@ -56,7 +65,7 @@ def load_full_map_surface(path): print(f"Could not load map background: {e}") return None, WIDTH, HEIGHT -MAP_PATH = "results/lst.tif" +MAP_PATH = "results/s2_2025.tif" map_surface, MAP_W, MAP_H = load_full_map_surface(MAP_PATH) @@ -91,6 +100,37 @@ class Player: else: pygame.draw.rect(win, PLAYER_COLOR, (self.x - offset_x, self.y - offset_y, PLAYER_SIZE, PLAYER_SIZE)) +class Enemy: + def __init__(self, x, y): + self.x = x + self.y = y + self.rect = pygame.Rect(self.x, self.y, PLAYER_SIZE /2, PLAYER_SIZE /2) + self.direction = "up" # Default direction + + def move(self, keys): + if keys[pygame.K_UP]: + self.y -= PLAYER_SPEED + self.direction = "up" + if keys[pygame.K_DOWN]: + self.y += PLAYER_SPEED + self.direction = "down" + if keys[pygame.K_LEFT]: + self.x -= PLAYER_SPEED + self.direction = "left" + if keys[pygame.K_RIGHT]: + self.x += PLAYER_SPEED + self.direction = "right" + # Clamp to map boundaries + self.x = max(0, min(MAP_W - PLAYER_SIZE, self.x)) + self.y = max(0, min(MAP_H - PLAYER_SIZE, self.y)) + self.rect.topleft = (self.x, self.y) + + def draw(self, win, offset_x, offset_y): + if ENEMY_IMAGE: + win.blit(ENEMY_IMAGE, (self.x - offset_x, self.y - offset_y)) + else: + pygame.draw.rect(win, PLAYER_COLOR, (self.x - offset_x, self.y - offset_y, PLAYER_SIZE, PLAYER_SIZE)) + class WaterBottle: def __init__(self, x, y, direction): @@ -117,6 +157,7 @@ class WaterBottle: def main(): # Start player in center of map player = Player(MAP_W // 2, MAP_H // 2) + enemy = Enemy(MAP_W // 3, MAP_H // 3) water_bottles = [] running = True @@ -132,7 +173,7 @@ def main(): keys = pygame.key.get_pressed() player.move(keys) - + enemy.move(keys) for bottle in water_bottles: bottle.move()