From 718ec2bda2b70dd3f06d4308e8eb08a8d5a17720 Mon Sep 17 00:00:00 2001 From: Vlad <89295404+Virashu@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:25:11 +0300 Subject: [PATCH] Improve enemies --- assets/DataBase.db | Bin 45056 -> 45056 bytes danmaku/database/construct.py | 10 ++--- danmaku/enemy.py | 67 ++++++++++++++++++++++++++-------- danmaku/game.py | 8 +--- danmaku/player.py | 35 +++++++++--------- 5 files changed, 76 insertions(+), 44 deletions(-) diff --git a/assets/DataBase.db b/assets/DataBase.db index edd72d48fcd4f37f1736a6353964018d7f434229..56801d26f3be4fd794a146b9d7a859e21207b7e3 100644 GIT binary patch delta 251 zcmZp8z|`=7X@az18Uq6ZHxR?XMVh7*&g$Y(N6+x$4`eViqZ^v(I&j?Rt#LMs~Nc8@}6K_&9RH!p1Yaz z1!o=KZ%&2Hf&wYbo1ZWrXXI+;iDMU6RAg*To?ORQJ2{W#<75qXaeiJV23GN=iUf9X zWo5=z^T|BC){`|^>?a>)|G^kPc@IY_W9noj&RE9e$qk%Yj7ghcbIxRBOx)bcUBS$l zviTpMvH%N{nj7 list[Bullet]: if self.can_shoot(): - if self.my_type == "boss": - return self.shoot_radial() - bullet = Bullet((self.x, self.y), self.damage, self.bullet_type) - bullet.vx = randint(-100, 100) / 100 - bullet.vy = (1 - bullet.vx**2) ** 0.5 - return [bullet] + match self.my_type: + case "boss": + if randint(0, 6) == 0: + return self.shoot_cluster() + return self.shoot_radial(waves=2, base_angle=randint(0, 359)) + case "basic enemy": + bullet = Bullet((self.x, self.y), self.damage, self.bullet_type) + bullet.vx = randint(-100, 100) / 100 + bullet.vy = (1 - bullet.vx**2) ** 0.5 + return [bullet] + case "strong enemy": + return self.shoot_radial(waves=3, n=5) return [] - def shoot_radial(self) -> list[Bullet]: + def shoot_radial(self, base_angle=0, angle_step=0, waves=1, n=6) -> list[Bullet]: """Shoot circle of bullets""" bullets = [] - a = randint(0, 359) + for wave in range(waves): + first_angle = base_angle + wave * angle_step + for add_angle in range(0, 360, 360 // n): + angle = pi * ((first_angle + add_angle) % 360) / 180 + bullet = Bullet((self.x, self.y), self.damage, self.bullet_type) + bullet.vx = cos(angle) + bullet.vy = sin(angle) + for _ in range(wave): + bullet.update(0.3) + bullets.append(bullet) + return bullets - for i in range(0, 360, 60): - angle = pi * ((a + i) % 360) / 180 - bullet = Bullet((self.x, self.y), self.damage, self.bullet_type) - bullet.vx = cos(angle) - bullet.vy = sin(angle) - bullets.append(bullet) + def shoot_cluster(self, waves=1, n=10, base_angle=0, arc=180): + bullets = [] + for wave in range(waves): + for i, a in enumerate(range(0, arc, arc // n)): + angle = pi * ((base_angle + a) % 360) / 180 + bullet = Bullet((self.x, self.y), self.damage, self.bullet_type) + bullet.vx = cos(angle) * (i + 1) + bullet.vy = sin(angle) * (i + 1) + for _ in range(wave): + bullet.update(0.3) + bullets.append(bullet) return bullets + + def generate_drops(self) -> list: + drops = [] + count = 1 + if self.my_type == "boss": + count = 5 + for _ in range(count): + pos = (self.x + randint(-10, 10), self.y + randint(-10, 10)) + match choices(("powerup", "points", None), (1, 1, 2))[0]: + case "powerup": + drops.append(PowerUp(pos)) + case "points": + drops.append(Points(pos)) + + return drops diff --git a/danmaku/game.py b/danmaku/game.py index 7b161a4..36b5238 100644 --- a/danmaku/game.py +++ b/danmaku/game.py @@ -196,15 +196,9 @@ def update_game(self): enemy.get_damage(bullet.damage) if enemy.health <= 0: self.player.score += enemy.cost - x, y = enemy.x, enemy.y + self.drops += enemy.generate_drops() self.enemies.remove(enemy) - match random.choices(("powerup", "points", None), (1, 1, 2))[0]: - case "powerup": - self.drops.append(PowerUp((x, y))) - case "points": - self.drops.append(Points((x, y))) - self.bullets.remove(bullet) break diff --git a/danmaku/player.py b/danmaku/player.py index 82cbb9e..17dbac7 100644 --- a/danmaku/player.py +++ b/danmaku/player.py @@ -31,17 +31,6 @@ def __init__( args["shoot_v"] / 1000, ) - self.my_type = object_type - self.score = 0 - self.power = 1 - - self.hitbox_radius = args["hitbox_radius"] - self.slow = False - - # Bounds - self.left = self.top = 0 - self.right = self.bottom = 10e6 - # Animation files = args["texture_file"].split(";") self.animation_frames = { @@ -50,6 +39,7 @@ def __init__( Direction.UP: [], Direction.DOWN: [], } + for i in files: path = f"/player/{i}" if "left" in i: @@ -70,6 +60,17 @@ def __init__( ] self.texture_size = args["texture_size"] + self.my_type = object_type + self.score = 0 + self.power = 1 + + self.hitbox_radius = args["hitbox_radius"] + self.slow = False + + # Bounds + self.left = self.top = 0 + self.right = self.bottom = 10e6 + def shoot(self) -> list[Bullet]: res: list[Bullet] = [] @@ -84,8 +85,8 @@ def shoot(self) -> list[Bullet]: res.append(bullet) if self.power > 4: - vx = math.cos(math.pi * 75 / 180) - vy = -math.sin(math.pi * 75 / 180) + vx = math.cos(math.pi * 85 / 180) + vy = -math.sin(math.pi * 85 / 180) b1 = Bullet( (self.x, self.y), @@ -142,9 +143,9 @@ def update(self, delta: int | float) -> None: self.y, self.top + self.height / 2, self.bottom - self.height / 2 ) - self.rect.x, self.rect.y, self.rect.w, self.rect.h = ( - int(self.x - self.width / 2), - int(self.y - self.height / 2), + self.rect.centerx, self.rect.centery, self.rect.w, self.rect.h = ( + int(self.x), + int(self.y), int(self.width), int(self.height), ) @@ -172,4 +173,4 @@ def animate(self) -> None: def draw(self, graphics: vgame.graphics.Graphics) -> None: graphics.draw_sprite(self) if self.slow: - graphics.circle((self.x, self.y), self.hitbox_radius, (255, 255, 255)) + graphics.circle((self.x, self.y), self.hitbox_radius, (200, 0, 200))