Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added code/__pycache__/alien.cpython-312.pyc
Binary file not shown.
Binary file added code/__pycache__/laser.cpython-312.pyc
Binary file not shown.
Binary file added code/__pycache__/obstacle.cpython-312.pyc
Binary file not shown.
Binary file added code/__pycache__/player.cpython-312.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions code/laser.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import pygame

class Laser(pygame.sprite.Sprite):
def __init__(self,pos,speed,screen_height):
def __init__(self,pos,speed_y,screen_height,speed_x=0):
super().__init__()
self.image = pygame.Surface((4,20))
self.image.fill('white')
self.rect = self.image.get_rect(center = pos)
self.speed = speed
self.speed_y = speed_y
self.speed_x = speed_x
self.height_y_constraint = screen_height

def destroy(self):
if self.rect.y <= -50 or self.rect.y >= self.height_y_constraint + 50:
self.kill()
if self.rect.x <= -50 or self.rect.x >= self.height_y_constraint + 50:
self.kill()

def update(self):
self.rect.y += self.speed
self.rect.x += self.speed_x
self.rect.y += self.speed_y
self.destroy()
21 changes: 21 additions & 0 deletions code/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ def __init__(self,pos,constraint,speed):
self.rect = self.image.get_rect(midbottom = pos)
self.speed = speed
self.max_x_constraint = constraint

self.ready = True
self.laser_time = 0
self.laser_cooldown = 600

self.shotgun_ready = True
self.shotgun_time = 0
self.shotgun_cooldown = 1500

self.lasers = pygame.sprite.Group()

self.laser_sound = pygame.mixer.Sound('../audio/laser.wav')
Expand All @@ -31,12 +36,23 @@ def get_input(self):
self.laser_time = pygame.time.get_ticks()
self.laser_sound.play()

if keys[pygame.K_x] and self.shotgun_ready:
self.shoot_shotgun()
self.shotgun_ready = False
self.shotgun_time = pygame.time.get_ticks()
self.laser_sound.play()

def recharge(self):
if not self.ready:
current_time = pygame.time.get_ticks()
if current_time - self.laser_time >= self.laser_cooldown:
self.ready = True

if not self.shotgun_ready:
current_time = pygame.time.get_ticks()
if current_time - self.shotgun_time >= self.shotgun_cooldown:
self.shotgun_ready = True

def constraint(self):
if self.rect.left <= 0:
self.rect.left = 0
Expand All @@ -46,6 +62,11 @@ def constraint(self):
def shoot_laser(self):
self.lasers.add(Laser(self.rect.center,-8,self.rect.bottom))

def shoot_shotgun(self):
self.lasers.add(Laser(self.rect.center,-8,self.rect.bottom))
self.lasers.add(Laser(self.rect.center,-8,self.rect.bottom,speed_x=-4))
self.lasers.add(Laser(self.rect.center,-8,self.rect.bottom,speed_x=4))

def update(self):
self.get_input()
self.constraint()
Expand Down