Browse Source

Added timer

master
Unbewohnte 4 years ago
parent
commit
110ed108ca
  1. 25
      Main.py
  2. 16
      beings.py
  3. 18
      surfaces.py

25
Main.py

@ -6,7 +6,6 @@ import time
from bullets import Bullet from bullets import Bullet
from beings import * from beings import *
from surfaces import Surface from surfaces import Surface
######## Set up things that will not change ######## Set up things that will not change
pygame.init() pygame.init()
pygame.display.set_caption('Healthless') pygame.display.set_caption('Healthless')
@ -16,6 +15,8 @@ window = pygame.display.set_mode((windowX,windowY))
icon = pygame.image.load('pics/logo.png') icon = pygame.image.load('pics/logo.png')
pygame.display.set_icon(icon) pygame.display.set_icon(icon)
# font = pygame.font.Font('freesansbold.ttf', 32)
# text = font.render('5', True,(100,100,100))
bullet_image = pygame.image.load('pics/second_bullet.png') bullet_image = pygame.image.load('pics/second_bullet.png')
enemy_bul_img = pygame.image.load('pics/bullet.png') enemy_bul_img = pygame.image.load('pics/bullet.png')
@ -31,7 +32,9 @@ def play():
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
enemy = Enemy() enemy = Enemy()
player = Player() player = Player()
test_surface = Surface() death_timer = 70
# lower_surface = Surface('killsurf')
# main_surface = Surface('default')
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -42,29 +45,37 @@ def play():
window.fill((41, 64, 59)) # (41,64,59) window.fill((41, 64, 59)) # (41,64,59)
test_surface.place(window,100,100) # lower_surface.place(window,0,0)
# main_surface.place(window,145,145)
player.teleportation() player.teleportation()
player.shoot(window,start_color,bullet_image) player.shoot(window,start_color,bullet_image)
player.draw(window,start_color,player_image) player.draw(window,start_color,player_image)
player.update(window,start_color,bullet_image) player.update(window,start_color,bullet_image)
player.collision() player.collision()
if player.out_of_area():
death_timer -= 1
print('death_timer',death_timer)
if death_timer <= 0:
print('DED')
break
else:
death_timer = 70
enemy.enemy_shoot(window,start_color,enemy_bul_img) enemy.enemy_shoot(window,start_color,enemy_bul_img)
enemy.draw(window,start_color,enemy_image) enemy.draw(window,start_color,enemy_image)
enemy.move('right') enemy.move('right')
if enemy.enemy_x == windowX: if enemy.enemy_x == windowX:
enemy.enemy_x = 1 enemy.enemy_x = 1
enemy.collision() enemy.collision()
if player.out_of_area():
print(player.x, player.y)
break
if enemy.out_of_area(): if enemy.out_of_area():
print('Random is on our side') print('Random is on our side')
break break
clock.tick(FPS) clock.tick(FPS)
pygame.display.update() pygame.display.update()
pass pass

16
beings.py

@ -25,16 +25,16 @@ class Player:
def update(self,window,start_color,bul_image): def update(self,window,start_color,bul_image):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.x > 5 : if keys[pygame.K_LEFT] and self.x - self.vel > 5 :
self.x -= self.vel self.x -= self.vel
if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 : if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 :
self.x += self.vel self.x += self.vel
if keys[pygame.K_UP] and self.y + self.height > self.height + 5 : if keys[pygame.K_UP] and self.y + self.height - self.vel > self.height + 5 :
self.y -= self.vel self.y -= self.vel
if keys[pygame.K_DOWN] and self.y + self.height < windowY-15 : if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY-15 :
self.y += self.vel self.y += self.vel
def draw(self,window,color,player_image): def draw(self,window,color,player_image):
@ -89,15 +89,15 @@ class Player:
# self.tp_cooldown = 100 # self.tp_cooldown = 100
def out_of_area(self): def out_of_area(self):
if self.x > windowX or self.x < 0 or self.y > windowY or self.y < 0: if self.x + self.width > windowX or self.x < 0 or self.y+self.height > windowY or self.y < 0:
return True return True
else: else:
return False return False
def collision(self): def collision(self):
for bullet in enemy_bul_on_screen: for bullet in enemy_bul_on_screen:
if bullet.bullet_x + bullet.bullet_width/2 >= self.x and bullet.bullet_x + bullet.bullet_width/2 <= self.x + self.width and bullet.bullet_y <= self.y: if bullet.bullet_x + bullet.bullet_width/2 >= self.x and bullet.bullet_x + bullet.bullet_width/2 <= self.x + self.width and bullet.bullet_y <= self.y:
self.x += randint(-50,50) self.x += randint(-100,100)
self.y += randint(-50,50) self.y += randint(-100,100)
@ -140,5 +140,5 @@ class Enemy:
for bullet in bullets_on_screen: for bullet in bullets_on_screen:
# if bullet.bullet_x + bullet.bullet_width/2 >= enemy.enemy_x and bullet.bullet_x + bullet.bullet_width/2 <= enemy.enemy_x + enemy.en_width and bullet.bullet_y <= enemy.enemy_y: # if bullet.bullet_x + bullet.bullet_width/2 >= enemy.enemy_x and bullet.bullet_x + bullet.bullet_width/2 <= enemy.enemy_x + enemy.en_width and bullet.bullet_y <= enemy.enemy_y:
if bullet.bullet_x + bullet.bullet_width/2 >= self.enemy_x and bullet.bullet_x + bullet.bullet_width/2 <= self.enemy_x + self.en_width and bullet.bullet_y <= self.enemy_y: if bullet.bullet_x + bullet.bullet_width/2 >= self.enemy_x and bullet.bullet_x + bullet.bullet_width/2 <= self.enemy_x + self.en_width and bullet.bullet_y <= self.enemy_y:
self.enemy_x += randint(-50,50) self.enemy_x += randint(-60,60)
self.enemy_y += randint(-50,50) self.enemy_y += randint(-60,60)

18
surfaces.py

@ -1,12 +1,16 @@
import pygame import pygame
from beings import *
class Surface: class Surface:
def __init__(self): def __init__(self,name):
self.width = 64 if str(name) == 'killsurf':
self.height = 64 self.width = windowX
self.height = windowY
def killsurf(self): #Don`t quite understand what I`ll do with these self.color = (30,70,40)
pass if str(name) == 'default':
self.width = windowX/1.5
self.height = windowY/1.5
self.color = (50,20,60)
def place(self,window,surf_x,surf_y): def place(self,window,surf_x,surf_y):
pygame.draw.rect(window,(100,200,240),(surf_x,surf_y,self.width,self.height)) pygame.draw.rect(window,self.color,(surf_x,surf_y,self.width,self.height))

Loading…
Cancel
Save