Update Game_V2.py
parent
b97bc194b4
commit
5b4e2f5f2c
103
Game_V2.py
103
Game_V2.py
|
@ -5,6 +5,7 @@ import math
|
||||||
SCREEN_X = 1280
|
SCREEN_X = 1280
|
||||||
SCREEN_Y = 720
|
SCREEN_Y = 720
|
||||||
|
|
||||||
|
|
||||||
# pygame setup
|
# pygame setup
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pygame.display.set_caption("Rouglite")
|
pygame.display.set_caption("Rouglite")
|
||||||
|
@ -21,6 +22,8 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.direction = pygame.math.Vector2()
|
self.direction = pygame.math.Vector2()
|
||||||
self.speed = 2.25
|
self.speed = 2.25
|
||||||
self.time = 0
|
self.time = 0
|
||||||
|
self.time_2 = 0
|
||||||
|
self.SCORE = 0
|
||||||
|
|
||||||
|
|
||||||
#health
|
#health
|
||||||
|
@ -47,6 +50,7 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.running_sprites.append(pygame.image.load("Sprites/Running/Player_run_right_"+str(i+1)+".png").convert_alpha())
|
self.running_sprites.append(pygame.image.load("Sprites/Running/Player_run_right_"+str(i+1)+".png").convert_alpha())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_damage(self, amount):
|
def get_damage(self, amount):
|
||||||
if self.target_health > 0:
|
if self.target_health > 0:
|
||||||
self.target_health -= amount
|
self.target_health -= amount
|
||||||
|
@ -65,8 +69,6 @@ class Player(pygame.sprite.Sprite):
|
||||||
def ahealth_bar(self):
|
def ahealth_bar(self):
|
||||||
|
|
||||||
self.current_health += (self.target_health-self.current_health)/10
|
self.current_health += (self.target_health-self.current_health)/10
|
||||||
|
|
||||||
# If self.current_health < self.target_health
|
|
||||||
transition_colour = (0, 255, 0)
|
transition_colour = (0, 255, 0)
|
||||||
health_bar_width = self.current_health/self.health_ratio
|
health_bar_width = self.current_health/self.health_ratio
|
||||||
transition_bar_width = self.target_health/self.health_ratio
|
transition_bar_width = self.target_health/self.health_ratio
|
||||||
|
@ -201,6 +203,12 @@ class Projectile(pygame.sprite.Sprite):
|
||||||
enemy.damage(1)
|
enemy.damage(1)
|
||||||
self.kill()
|
self.kill()
|
||||||
break
|
break
|
||||||
|
for enemy in enemies2:
|
||||||
|
distance = pygame.math.Vector2.length(pygame.math.Vector2(enemy.rect.center) - self.rect.center)
|
||||||
|
if distance < 20:
|
||||||
|
enemy.damage(1)
|
||||||
|
self.kill()
|
||||||
|
break
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.rect.center += self.direction * self.speed
|
self.rect.center += self.direction * self.speed
|
||||||
|
@ -221,7 +229,7 @@ class Enemy(pygame.sprite.Sprite):
|
||||||
self.pos = self.rect.center
|
self.pos = self.rect.center
|
||||||
self.direction = pygame.math.Vector2()
|
self.direction = pygame.math.Vector2()
|
||||||
self.speed = 2
|
self.speed = 2
|
||||||
self.health = 2
|
self.health = 3
|
||||||
self.death = pygame.mixer.Sound("Sounds/explosion.wav")
|
self.death = pygame.mixer.Sound("Sounds/explosion.wav")
|
||||||
|
|
||||||
self.image_direction = 1
|
self.image_direction = 1
|
||||||
|
@ -234,6 +242,7 @@ class Enemy(pygame.sprite.Sprite):
|
||||||
enemies.remove(self)
|
enemies.remove(self)
|
||||||
self.kill()
|
self.kill()
|
||||||
self.death.play()
|
self.death.play()
|
||||||
|
player.SCORE += 1
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
@ -255,6 +264,41 @@ class Enemy(pygame.sprite.Sprite):
|
||||||
self.pos += self.direction.normalize() * self.speed
|
self.pos += self.direction.normalize() * self.speed
|
||||||
self.rect.center = (round(self.pos.x), round(self.pos.y))
|
self.rect.center = (round(self.pos.x), round(self.pos.y))
|
||||||
|
|
||||||
|
|
||||||
|
class Enemy_2(pygame.sprite.Sprite):
|
||||||
|
def __init__(self, pos, group, scale):
|
||||||
|
super().__init__(group)
|
||||||
|
self.original_image = pygame.image.load("Sprites/atom_bomb.png").convert_alpha()
|
||||||
|
self.image = pygame.transform.scale(self.original_image, (int(self.original_image.get_width() * scale), int(self.original_image.get_height() * scale)))
|
||||||
|
self.rect = self.image.get_rect(center = pos)
|
||||||
|
self.pos = self.rect.center
|
||||||
|
self.direction = pygame.math.Vector2()
|
||||||
|
self.speed = 1
|
||||||
|
self.health = 10
|
||||||
|
|
||||||
|
self.image_direction = 1
|
||||||
|
self.death = pygame.mixer.Sound("Sounds/explosion_atomic.wav")
|
||||||
|
|
||||||
|
def damage(self, damage):
|
||||||
|
self.health -= 1
|
||||||
|
if self.health <= 0:
|
||||||
|
enemies2.remove(self)
|
||||||
|
self.kill()
|
||||||
|
self.death.play()
|
||||||
|
player.SCORE += 3
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.direction = pygame.math.Vector2(player.rect.center) - self.rect.center
|
||||||
|
if pygame.math.Vector2.length(self.direction) < 20:
|
||||||
|
player.get_damage(500)
|
||||||
|
self.kill()
|
||||||
|
enemies2.remove(self)
|
||||||
|
player.time = 0
|
||||||
|
self.death.play()
|
||||||
|
|
||||||
|
self.pos += self.direction.normalize() * self.speed
|
||||||
|
self.rect.center = (round(self.pos.x), round(self.pos.y))
|
||||||
|
|
||||||
class CameraGroup(pygame.sprite.Group):
|
class CameraGroup(pygame.sprite.Group):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -279,16 +323,33 @@ class CameraGroup(pygame.sprite.Group):
|
||||||
self.display_surface.blit(sprite.image, offset_pos)
|
self.display_surface.blit(sprite.image, offset_pos)
|
||||||
|
|
||||||
def spawn_enemy():
|
def spawn_enemy():
|
||||||
if len(enemies) < 20:
|
if len(enemies) < 5 + (player.time_2):
|
||||||
random_x = randint(-1000, 1000)
|
random_x = randint(-1000, 1000)
|
||||||
random_y = randint(-1000, 1000)
|
random_y = randint(-1000, 1000)
|
||||||
enemies.append(Enemy((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group, 0.05))
|
enemies.append(Enemy((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group, 0.05))
|
||||||
|
|
||||||
|
|
||||||
|
def spawn_enemy2():
|
||||||
|
if len(enemies2) < 2 + int(player.time_2):
|
||||||
|
random_x = randint(-1000, 1000)
|
||||||
|
random_y = randint(-1000, 1000)
|
||||||
|
enemies2.append(Enemy_2((player.rect.centerx + random_x, player.rect.centery + random_y), camera_group, 0.5))
|
||||||
|
|
||||||
spawn_enemy_event = pygame.USEREVENT + 1
|
spawn_enemy_event = pygame.USEREVENT + 1
|
||||||
|
|
||||||
|
smallfont = pygame.font.Font("assets/font.ttf", 25)
|
||||||
|
|
||||||
|
def score(score):
|
||||||
|
text = smallfont.render("Score: " + str(score), True, "black")
|
||||||
|
screen.blit(text, [10,15])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Setup
|
#Setup
|
||||||
|
|
||||||
camera_group = CameraGroup()
|
camera_group = CameraGroup()
|
||||||
enemies = []
|
enemies = []
|
||||||
|
enemies2 = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,7 +364,6 @@ pygame.mouse.set_cursor(cursor)
|
||||||
pygame.mouse.set_visible(True | False)
|
pygame.mouse.set_visible(True | False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
for e in pygame.event.get():
|
for e in pygame.event.get():
|
||||||
if e.type == pygame.QUIT:
|
if e.type == pygame.QUIT:
|
||||||
|
@ -313,36 +373,33 @@ while running:
|
||||||
if e.type == spawn_enemy_event:
|
if e.type == spawn_enemy_event:
|
||||||
spawn_enemy()
|
spawn_enemy()
|
||||||
|
|
||||||
|
|
||||||
|
if e.type == spawn_enemy_event:
|
||||||
|
spawn_enemy2()
|
||||||
|
|
||||||
if player.time > 3:
|
if player.time > 3:
|
||||||
if player.current_health < 999:
|
if player.current_health < 999 and player.target_health > 0:
|
||||||
player.get_health(100)
|
player.get_health(100)
|
||||||
player.time -= 1
|
player.time -= 1
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
if player.target_health <= 0:
|
||||||
|
running == False
|
||||||
|
print("Your score was " + str(player.SCORE))
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
screen.fill("cyan")
|
screen.fill("cyan")
|
||||||
|
|
||||||
|
score(player.SCORE)
|
||||||
|
|
||||||
|
|
||||||
camera_group.update()
|
camera_group.update()
|
||||||
camera_group.custom_draw(player)
|
camera_group.custom_draw(player)
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip()
|
|
||||||
|
|
||||||
clock.tick(60)
|
|
||||||
player.time += 0.016
|
|
||||||
|
|
||||||
print(player.time)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
player.time += 0.016
|
player.time += 0.016
|
||||||
print(player.time)
|
player.time_2 += 0.005
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue