From 67bcf927ef261c538fa66044ca809d0b98265911 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sat, 8 Aug 2020 09:50:24 +0300 Subject: [PATCH] Added cooldown mechanic --- Main.py | 7 +++---- enemy.py | 4 ++-- player.py | 20 ++++++++++++++++---- surfaces.py | 4 ++-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Main.py b/Main.py index 767b690..a4f093c 100644 --- a/Main.py +++ b/Main.py @@ -7,7 +7,7 @@ from bullets import * from player import * from enemy import * from surfaces import Surface - +######## Set up things that will not change pygame.init() pygame.display.set_caption('Healthless') windowX = 640 @@ -16,12 +16,11 @@ window = pygame.display.set_mode((windowX,windowY)) icon = pygame.image.load('pics/logo.png') pygame.display.set_icon(icon) -######## Load Images + bullet_image = pygame.image.load('pics/second_bullet.png') enemy_image = pygame.image.load('pics/32x64.png') player_image = pygame.image.load('pics/32x64.png') ######## -#rand_color = (int(random.randint(0,254)),int(random.randint(0,254)) ,int(random.randint(0,254))) ################################################################ def play(): @@ -52,7 +51,7 @@ def play(): enemy.draw(window,start_color,enemy_image) enemy.update() - if player.y == 0: #Just to try a "death" + if player.y <= 0: #Just to try a "death" break clock.tick(FPS) diff --git a/enemy.py b/enemy.py index 13e2854..ab11939 100644 --- a/enemy.py +++ b/enemy.py @@ -8,7 +8,7 @@ class Enemy: def __init__(self): self.enemy_x = 100 self.enemy_y = 100 - self.en_width = 32 + self.en_width = 32 self.en_height = 64 def draw(self,window,en_color,en_image): @@ -18,5 +18,5 @@ class Enemy: self.enemy_x += 3 if self.enemy_x >= 600: self.enemy_x = 1 - def enemy_shoot(self): + def enemy_shoot(self): #Have NO IDEA how it`ll work pass diff --git a/player.py b/player.py index 62676c0..3bc8f54 100644 --- a/player.py +++ b/player.py @@ -9,9 +9,12 @@ import sys windowX = 640 windowY = 640 bullets_on_screen = [] +clock = pygame.time.Clock() class Player: def __init__(self): + self.bul_cooldown = 50 + self.tp_cooldown = 100 self.x = 300 self.y = 300 self.vel = 10 @@ -38,10 +41,14 @@ class Player: def shoot(self,window,start_color,bul_image): + # if self.bul_cooldown >= 1: #With cooldown the game looks not so spicy. + # self.bul_cooldown -= 2 #Maybe it will be the matter of upgrades ? + keys = pygame.key.get_pressed() - if keys[pygame.K_z]: + if keys[pygame.K_z]: # and self.bul_cooldown == 0 new_bullet = Bullet(self.x + self.width/2, self.y + 10) bullets_on_screen.append(new_bullet) + #self.bul_cooldown = 20 if int(len(bullets_on_screen)) > 0: for bullet in bullets_on_screen: @@ -52,7 +59,12 @@ class Player: print('Bullets: ' + str(len(bullets_on_screen))) def teleportation(self): + self.vel = 10 + if self.tp_cooldown >= 1: + self.tp_cooldown -= 2 + print('teleportation cooldown : '+ str(self.tp_cooldown)) + keys = pygame.key.get_pressed() - if keys[pygame.K_d]: - self.x = randint(10,550) - self.y = randint(10,550) + if keys[pygame.K_d] and self.tp_cooldown == 0: + self.y -= 64 + self.tp_cooldown = 100 diff --git a/surfaces.py b/surfaces.py index ac9c085..684c2eb 100644 --- a/surfaces.py +++ b/surfaces.py @@ -2,10 +2,10 @@ import pygame class Surface: def __init__(self): - self.width = 64 + self.width = 64 self.height = 64 - def killsurf(self): + def killsurf(self): #Don`t quite understand what I`ll do with these pass def place(self,window,surf_x,surf_y):