Make Bullets use textures instead of one circle for all of them, remove some bloat code

This commit is contained in:
csd4ni3l
2025-10-10 21:30:49 +02:00
parent 02561e01b6
commit 5798f3ba2a
3 changed files with 13 additions and 31 deletions

View File

@@ -4,17 +4,16 @@ from utils.constants import BULLET_SPEED, IRS_AGENT_HEALTH, HEALTH_INCREASE_PER_
from utils.constants import IRS_AGENT_SPAWN_INTERVAL, SPAWN_INTERVAL_DECREASE_PER_LEVEL, SPEED_INCREASE_PER_LEVEL from utils.constants import IRS_AGENT_SPAWN_INTERVAL, SPAWN_INTERVAL_DECREASE_PER_LEVEL, SPEED_INCREASE_PER_LEVEL
from utils.constants import TAX_EVASION_LEVELS, TAX_EVASION_NAMES, TAX_INCREASE_PER_LEVEL, menu_background_color, INVENTORY_ITEMS, INVENTORY_TRIGGER_KEYS from utils.constants import TAX_EVASION_LEVELS, TAX_EVASION_NAMES, TAX_INCREASE_PER_LEVEL, menu_background_color, INVENTORY_ITEMS, INVENTORY_TRIGGER_KEYS
import utils.preload
from utils.preload import irs_agent_texture from utils.preload import irs_agent_texture
from utils.preload import light_wizard_left_animation, light_wizard_right_animation, light_wizard_standing_animation, light_wizard_up_animation from utils.preload import light_wizard_left_animation, light_wizard_right_animation, light_wizard_standing_animation, light_wizard_up_animation
from utils.preload import dark_wizard_left_animation, dark_wizard_right_animation, dark_wizard_standing_animation, dark_wizard_up_animation from utils.preload import dark_wizard_left_animation, dark_wizard_right_animation, dark_wizard_standing_animation, dark_wizard_up_animation
from game.inventory import Inventory from game.inventory import Inventory
class Bullet(arcade.SpriteCircle): class Bullet(arcade.Sprite):
def __init__(self, radius, x, y, direction, color): def __init__(self, radius, texture, x, y, direction):
super().__init__(radius=radius, color=color) super().__init__(texture, center_x=x, center_y=y)
self.center_x = x
self.center_y = y
self.radius = radius self.radius = radius
self.direction = direction self.direction = direction
@@ -79,11 +78,10 @@ class Game(arcade.gui.UIView):
self.last_shoot = time.perf_counter() self.last_shoot = time.perf_counter()
self.evaded_tax = 0 self.evaded_tax = 0
self.high_score = self.data["high_score"]
self.mana = 0 self.mana = 0
self.tax_evasion_level = TAX_EVASION_NAMES[0] self.tax_evasion_level = TAX_EVASION_NAMES[0]
self.high_score = self.data["high_score"]
self.bullets: list[Bullet] = [] self.bullets: list[Bullet] = []
self.highscore_evaded_tax = self.data["high_score"] self.highscore_evaded_tax = self.data["high_score"]
self.player = Player(self.window.width / 2, self.window.height / 2) self.player = Player(self.window.width / 2, self.window.height / 2)
@@ -108,26 +106,10 @@ class Game(arcade.gui.UIView):
self.inventory.pay_tax_button.on_click = lambda event: self.pay_tax() self.inventory.pay_tax_button.on_click = lambda event: self.pay_tax()
def spawn_bullet(self, direction): def spawn_bullet(self, direction):
bullet = Bullet(INVENTORY_ITEMS[self.inventory.current_inventory_item][3], self.player.center_x, self.player.center_y, direction, arcade.color.BLUE) bullet = Bullet(INVENTORY_ITEMS[self.inventory.current_inventory_item][3], getattr(utils.preload, INVENTORY_ITEMS[self.inventory.current_inventory_item][4]), self.player.center_x, self.player.center_y, direction)
self.bullets.append(bullet) self.bullets.append(bullet)
self.spritelist.append(bullet) self.spritelist.append(bullet)
def auto_shoot(self):
closest_dist = 999999
closest_direction = None
for irs_agent in self.irs_agents:
distance = arcade.math.Vec2(self.player.center_x, self.player.center_y).distance((irs_agent.center_x, irs_agent.center_y))
if distance < closest_dist:
closest_dist = distance
closest_direction = (arcade.math.Vec2(irs_agent.center_x, irs_agent.center_y) - (self.player.center_x, self.player.center_y)).normalize()
if not closest_dist or not closest_direction:
return
self.spawn_bullet(closest_direction)
def get_current_level_int(self): def get_current_level_int(self):
return TAX_EVASION_NAMES.index(self.tax_evasion_level) return TAX_EVASION_NAMES.index(self.tax_evasion_level)
@@ -276,9 +258,6 @@ class Game(arcade.gui.UIView):
self.high_score = self.evaded_tax self.high_score = self.evaded_tax
self.high_score_label.text = f"High Score: {int(self.high_score)}$" self.high_score_label.text = f"High Score: {int(self.high_score)}$"
def on_show_view(self):
super().on_show_view()
def on_key_press(self, symbol, modifiers): def on_key_press(self, symbol, modifiers):
if symbol == arcade.key.ESCAPE: if symbol == arcade.key.ESCAPE:
self.data["high_score"] = int(self.high_score) self.data["high_score"] = int(self.high_score)

View File

@@ -28,10 +28,9 @@ SHOP_ITEMS = []
PLAYER_SPEED = 4 PLAYER_SPEED = 4
INVENTORY_ITEMS = [ INVENTORY_ITEMS = [
["Fireball", 0.2, 10, 10], ["Fireball", 0.2, 10, 10, "fireball_texture"],
["Lightning Bolt", 0.4, 20, 20], ["Lightning Bolt", 0.4, 20, 20, "lightning_bolt_texture"],
["Ice Blast", 0.1, 5, 7.5], ["Ice Blast", 0.1, 5, 7.5, "ice_blast_texture"],
["Arcane Beam", 0.2, 20, 15],
] ]
INVENTORY_TRIGGER_KEYS = [getattr(arcade.key, f"KEY_{n+1}") for n in range(len(INVENTORY_ITEMS))] INVENTORY_TRIGGER_KEYS = [getattr(arcade.key, f"KEY_{n+1}") for n in range(len(INVENTORY_ITEMS))]

View File

@@ -15,4 +15,8 @@ dark_wizard_right_animation = arcade.TextureAnimation([arcade.TextureKeyframe(te
dark_wizard_standing_animation = arcade.TextureAnimation([arcade.TextureKeyframe(texture, 300) for texture in dark_wizard_spritesheet[6:8]]) dark_wizard_standing_animation = arcade.TextureAnimation([arcade.TextureKeyframe(texture, 300) for texture in dark_wizard_spritesheet[6:8]])
dark_wizard_left_animation = arcade.TextureAnimation([arcade.TextureKeyframe(texture, 300) for texture in dark_wizard_spritesheet[9:11]]) dark_wizard_left_animation = arcade.TextureAnimation([arcade.TextureKeyframe(texture, 300) for texture in dark_wizard_spritesheet[9:11]])
fireball_texture = arcade.make_circle_texture(10, arcade.color.RED)
lightning_bolt_texture = arcade.make_circle_texture(20, arcade.color.BLUE)
ice_blast_texture = arcade.make_circle_texture(20, arcade.color.ICEBERG)
irs_agent_texture = arcade.load_texture("assets/graphics/irs_agent.png") irs_agent_texture = arcade.load_texture("assets/graphics/irs_agent.png")