Projektile für Gegner hinzugefügt, die auf den Spieler feuern
This commit is contained in:
parent
86312b2106
commit
aa8f10a08a
2 changed files with 64 additions and 2 deletions
28
game.py
28
game.py
|
|
@ -67,6 +67,8 @@ class Game:
|
||||||
"particles/particle": Animation(
|
"particles/particle": Animation(
|
||||||
load_images(path="particles/particle"), image_duration=6, loop=False
|
load_images(path="particles/particle"), image_duration=6, loop=False
|
||||||
),
|
),
|
||||||
|
"gun": load_image("gun.png"),
|
||||||
|
"projectile": load_image("projectile.png"),
|
||||||
}
|
}
|
||||||
self.player: Player = Player(game=self, pos=(50, 50), size=(8, 15))
|
self.player: Player = Player(game=self, pos=(50, 50), size=(8, 15))
|
||||||
|
|
||||||
|
|
@ -92,6 +94,7 @@ class Game:
|
||||||
self.enemys.append(Enemy(self, spawner["pos"], (8, 15)))
|
self.enemys.append(Enemy(self, spawner["pos"], (8, 15)))
|
||||||
|
|
||||||
self.particles: list[Particle] = []
|
self.particles: list[Particle] = []
|
||||||
|
self.projectiles: list = []
|
||||||
|
|
||||||
self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16)
|
self.clouds: Clouds = Clouds(cloud_images=self.assets["clouds"], count=16)
|
||||||
self.isJumping: bool = False
|
self.isJumping: bool = False
|
||||||
|
|
@ -140,6 +143,29 @@ class Game:
|
||||||
self.tilemap, movement=((self.movement[1] - self.movement[0]), 0)
|
self.tilemap, movement=((self.movement[1] - self.movement[0]), 0)
|
||||||
)
|
)
|
||||||
self.player.render(surface=self.display, offset=render_scroll)
|
self.player.render(surface=self.display, offset=render_scroll)
|
||||||
|
|
||||||
|
|
||||||
|
# [[x, y], direction, timer]
|
||||||
|
for projectile in self.projectiles.copy():
|
||||||
|
projectile[0][0] += projectile[1]
|
||||||
|
projectile[2] += 1
|
||||||
|
img = self.assets["projectile"]
|
||||||
|
self.display.blit(
|
||||||
|
img,
|
||||||
|
(
|
||||||
|
projectile[0][0] - img.get_width() / 2 - render_scroll[0],
|
||||||
|
projectile[0][1] - img.get_height() / 2 - render_scroll[1],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if self.tilemap.solid_check(projectile[0]):
|
||||||
|
self.projectiles.remove(projectile)
|
||||||
|
elif projectile[2] > 360:
|
||||||
|
self.projectiles.remove(projectile)
|
||||||
|
elif abs(self.player.dashing) < 50:
|
||||||
|
if self.player.rect().collidepoint(projectile[0]):
|
||||||
|
self.projectiles.remove(projectile)
|
||||||
|
|
||||||
|
|
||||||
# self.player.boost(self.boost)
|
# self.player.boost(self.boost)
|
||||||
# print(int(self.player.pos[0]))
|
# print(int(self.player.pos[0]))
|
||||||
# print(int(self.player.pos[1]))
|
# print(int(self.player.pos[1]))
|
||||||
|
|
@ -171,7 +197,7 @@ class Game:
|
||||||
# self.boost = True
|
# self.boost = True
|
||||||
self.player.boost()
|
self.player.boost()
|
||||||
|
|
||||||
if event.key == pygame.K_x:
|
if event.key == pygame.K_x or event.key == pygame.K_LSHIFT or event.key == pygame.K_RSHIFT:
|
||||||
self.player.dash()
|
self.player.dash()
|
||||||
|
|
||||||
if event.type == pygame.KEYUP:
|
if event.type == pygame.KEYUP:
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,25 @@ class Enemy(PhysicsEntity):
|
||||||
movement = (movement[0] - 0.5 if self.flip else 0.5, movement[1])
|
movement = (movement[0] - 0.5 if self.flip else 0.5, movement[1])
|
||||||
else:
|
else:
|
||||||
self.flip = not self.flip
|
self.flip = not self.flip
|
||||||
|
|
||||||
self.walking = max(0, self.walking - 1)
|
self.walking = max(0, self.walking - 1)
|
||||||
elif random.random() < 0.01:
|
|
||||||
|
if not self.walking:
|
||||||
|
distance = (
|
||||||
|
self.game.player.pos[0] - self.pos[0],
|
||||||
|
self.game.player.pos[1] - self.pos[1],
|
||||||
|
)
|
||||||
|
if abs(distance[1]) < 16:
|
||||||
|
if self.flip and distance[0] < 0:
|
||||||
|
self.game.projectiles.append(
|
||||||
|
[[self.rect().centerx - 7, self.rect().centery], -1.5, 0]
|
||||||
|
)
|
||||||
|
if not self.flip and distance[0] > 0:
|
||||||
|
self.game.projectiles.append(
|
||||||
|
[[self.rect().centerx + 7, self.rect().centery], 1.5, 0]
|
||||||
|
)
|
||||||
|
|
||||||
|
elif random.random() < 0.02:
|
||||||
self.walking = random.randint(30, 120)
|
self.walking = random.randint(30, 120)
|
||||||
|
|
||||||
super().update(tilemap, movement)
|
super().update(tilemap, movement)
|
||||||
|
|
@ -134,6 +151,25 @@ class Enemy(PhysicsEntity):
|
||||||
else:
|
else:
|
||||||
self.set_action("idle")
|
self.set_action("idle")
|
||||||
|
|
||||||
|
def render(self, surface: pygame.Surface, offset: tuple = (0, 0)):
|
||||||
|
super().render(surface, offset)
|
||||||
|
|
||||||
|
if self.flip:
|
||||||
|
surface.blit(
|
||||||
|
pygame.transform.flip(self.game.assets["gun"], True, False),
|
||||||
|
(
|
||||||
|
self.rect().centerx
|
||||||
|
- 4
|
||||||
|
- self.game.assets["gun"].get_width()
|
||||||
|
- offset[0],
|
||||||
|
self.rect().centery - offset[1],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
surface.blit(
|
||||||
|
self.game.assets["gun"],
|
||||||
|
(self.rect().centerx + 4 - offset[0], self.rect().centery - offset[1]),
|
||||||
|
)
|
||||||
|
|
||||||
class Player(PhysicsEntity):
|
class Player(PhysicsEntity):
|
||||||
def __init__(self, game, pos: tuple[float, float], size: tuple[int, int]):
|
def __init__(self, game, pos: tuple[float, float], size: tuple[int, int]):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue