Catapults working. At this point most of the basic game is set up, now I have to get down to level and enemy creation, and sounds for when things happen.
This commit is contained in:
		
							
								
								
									
										25
									
								
								src/level.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/level.py
									
									
									
									
									
								
							| @@ -1,6 +1,8 @@ | ||||
| import pygame | ||||
| import random | ||||
| from libstormgames import * | ||||
| from src.catapult import Catapult | ||||
| from src.coffin import CoffinObject | ||||
| from src.enemy import Enemy | ||||
| from src.object import Object | ||||
| from src.player import Player | ||||
| @@ -18,7 +20,7 @@ class Level: | ||||
|         self.player = Player(levelData["player_start"]["x"], levelData["player_start"]["y"]) | ||||
|         self.edge_warning_channel = None | ||||
|         self.weapon_hit_channel = None | ||||
|          | ||||
|      | ||||
|         # Load objects and enemies from level data | ||||
|         for obj in levelData["objects"]: | ||||
|             # Handle x position or range | ||||
| @@ -26,9 +28,20 @@ class Level: | ||||
|                 xPos = obj["x_range"] | ||||
|             else: | ||||
|                 xPos = [obj["x"], obj["x"]]  # Single position as range | ||||
|                  | ||||
|          | ||||
|             # Check if this is a catapult | ||||
|             if obj.get("type") == "catapult": | ||||
|                 catapult = Catapult( | ||||
|                     xPos[0], | ||||
|                     obj["y"], | ||||
|                     self.sounds, | ||||
|                     direction=obj.get("direction", 1), | ||||
|                     fireInterval=obj.get("fireInterval", 5000), | ||||
|                     firingRange=obj.get("range", 20) | ||||
|                 ) | ||||
|                 self.objects.append(catapult) | ||||
|             # Check if this is an enemy | ||||
|             if "enemy_type" in obj: | ||||
|             elif "enemy_type" in obj: | ||||
|                 enemy = Enemy( | ||||
|                     xPos, | ||||
|                     obj["y"], | ||||
| @@ -71,7 +84,6 @@ class Level: | ||||
|                     obj.has_spawned = True | ||||
|                      | ||||
|                     roll = random.randint(1, 100) | ||||
|                     speak(f"Near grave, chance to spawn zombie") | ||||
|                     if roll <= obj.zombie_spawn_chance: | ||||
|                         zombie = Enemy( | ||||
|                             [obj.xPos, obj.xPos], | ||||
| @@ -108,6 +120,11 @@ class Level: | ||||
|             if enemy.channel is not None: | ||||
|                 enemy.channel = obj_update(enemy.channel, self.player.xPos, enemy.xPos) | ||||
|                  | ||||
|         # Update catapults | ||||
|         for obj in self.objects: | ||||
|             if isinstance(obj, Catapult): | ||||
|                 obj.update(currentTime, self.player) | ||||
|  | ||||
|         # Update bouncing items | ||||
|         for item in self.bouncing_items[:]:  # Copy list to allow removal | ||||
|             if not item.update(currentTime): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user