Browse Source

Added cooldown feature for the player and the enemy

master
Unbewohnte 4 years ago
parent
commit
9eab9d00f0
  1. 24
      Main.py
  2. 39
      beings.py
  3. 12
      particles.py

24
Main.py

@ -26,7 +26,7 @@ def play():
death_timer = 70 death_timer = 70
text = font.render(str(death_timer), True,(0,0,0)) #Declaring just for rect text = font.render(str(death_timer), True,(0,0,0)) #Declaring just for rect
text_rect = text.get_rect(center = (windowX//2,windowY//2 - 100)) text_rect = text.get_rect(center = (windowX//2,windowY//2 - 100))
##########################
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
@ -35,8 +35,9 @@ def play():
break break
window.fill((41, 64, 59)) window.fill((41, 64, 59))
##########################
#PPPPPPPPPPPPPPPPPPPPPPPPP
player.teleportation() player.teleportation()
player.shoot(window) player.shoot(window)
player.draw(window) player.draw(window)
@ -52,25 +53,30 @@ def play():
break break
else: else:
death_timer = 70 death_timer = 70
#PPPPPPPPPPPPPPPPPPPPPPPPP
#EEEEEEEEEEEEEEEEEEEEEEEEE
enemy.enemy_shoot(window) enemy.enemy_shoot(window)
enemy.draw(window) enemy.draw(window)
enemy.move('right') enemy.move('right')
if enemy.enemy_x >= windowX-10: #That returning thingy if enemy.enemy_x >= windowX-10: #That returning thingy
enemy.enemy_x = 5 enemy.enemy_x = 5
enemy.collision() enemy.collision(window)
if enemy.out_of_area(): if enemy.out_of_area():
print('Random is on our side') print('Random is on our side')
break break
#EEEEEEEEEEEEEEEEEEEEEEEEE
partic = Particle(400,400) #PRTCLS_PRTCLS_PRTCLS_PRTCLS_
particles_on_screen.append(partic) # partic = Particle(400,400)
for particle in particles_on_screen: # particles_on_screen.append(partic)
particle.draw(window) # for particle in particles_on_screen:
particle.update() # particle.draw(window)
# particle.update()
# print('PARTICLES: ',str(len(particles_on_screen)))
#PRTCLS_PRTCLS_PRTCLS_PRTCLS_
clock.tick(FPS) clock.tick(FPS)
pygame.display.update() pygame.display.update()

39
beings.py

@ -2,7 +2,7 @@ import pygame
from random import randint from random import randint
from time import time from time import time
from bullets import * from bullets import *
#from particles import * # !!! from particles import * # !!!
import time import time
import sys import sys
@ -18,7 +18,7 @@ player_image = pygame.image.load('pics/32x64.png')
class Player: class Player:
def __init__(self): def __init__(self):
self.bul_cooldown = 50 self.bul_cooldown = 14
self.tp_cooldown = 100 self.tp_cooldown = 100
self.x = 300 self.x = 300
self.y = 300 self.y = 300
@ -47,14 +47,14 @@ class Player:
def shoot(self,window): def shoot(self,window):
# if self.bul_cooldown >= 1: #With cooldown the game looks not so spicy. if self.bul_cooldown >= 1:
# self.bul_cooldown -= 2 #Maybe it will be the matter of upgrades ? self.bul_cooldown -= 2
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_z]: # and self.bul_cooldown == 0 if keys[pygame.K_z] and self.bul_cooldown == 0:
new_bullet = Bullet(self.x + self.width/2, self.y + 10) new_bullet = Bullet(self.x + self.width/2, self.y + 10)
bullets_on_screen.append(new_bullet) bullets_on_screen.append(new_bullet)
#self.bul_cooldown = 20 self.bul_cooldown = 14
if int(len(bullets_on_screen)) > 0: if int(len(bullets_on_screen)) > 0:
for bullet in bullets_on_screen: for bullet in bullets_on_screen:
@ -94,11 +94,6 @@ class Player:
def collision(self,window): def collision(self,window):
for bullet in enemy_bul_on_screen: for bullet in enemy_bul_on_screen:
if self.player_rect.colliderect(bullet.bullet_rect): if self.player_rect.colliderect(bullet.bullet_rect):
# new_particle = Particle(bullet.x,bullet.y)
# particles_on_screen.append(new_particle)
# for particle in particles_on_screen:
# particle.draw(window)
# particle.update()
self.x += randint(-100,100) self.x += randint(-100,100)
self.y += randint(-100,100) self.y += randint(-100,100)
@ -111,6 +106,7 @@ class Enemy:
self.en_width = 32 self.en_width = 32
self.en_height = 64 self.en_height = 64
self.vel = 3 self.vel = 3
self.bul_cooldown = 10
def draw(self,window): def draw(self,window):
pygame.draw.rect(window,(0,0,0),(self.enemy_x, self.enemy_y, self.en_width, self.en_height)) pygame.draw.rect(window,(0,0,0),(self.enemy_x, self.enemy_y, self.en_width, self.en_height))
window.blit(enemy_image,(self.enemy_x, self.enemy_y)) window.blit(enemy_image,(self.enemy_x, self.enemy_y))
@ -125,15 +121,22 @@ class Enemy:
elif str(side) == "down": elif str(side) == "down":
self.enemy_y += self.vel self.enemy_y += self.vel
def enemy_shoot(self,window): def enemy_shoot(self,window):
if self.bul_cooldown >= 1:
self.bul_cooldown -= 2
if self.bul_cooldown <= 0:
new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10) new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10)
enemy_bul_on_screen.append(new_bullet) enemy_bul_on_screen.append(new_bullet)
self.bul_cooldown = random.randint(6,14) #10
if int(len(enemy_bul_on_screen)) > 0: if int(len(enemy_bul_on_screen)) > 0:
for bullet in enemy_bul_on_screen: for bullet in enemy_bul_on_screen:
bullet.draw(window,(0,0,0),enemy_bul_img) bullet.draw(window,(0,0,0),enemy_bul_img)
bullet.movedwn() bullet.movedwn()
if bullet.bullet_rect[1] >= windowY +20: if bullet.bullet_rect[1] >= windowY +20:
enemy_bul_on_screen.remove(bullet) # !!??? enemy_bul_on_screen.remove(bullet)
print('Bullets (Enemy,Player): ' + str(len(bullets_on_screen + enemy_bul_on_screen)))
#print('Bullets (Enemy,Player): ' + str(len(bullets_on_screen + enemy_bul_on_screen)))
def out_of_area(self): def out_of_area(self):
if self.enemy_x > windowX+1 or self.enemy_x < -1 or self.enemy_y > windowY+1 or self.enemy_y < -1: if self.enemy_x > windowX+1 or self.enemy_x < -1 or self.enemy_y > windowY+1 or self.enemy_y < -1:
@ -141,9 +144,15 @@ class Enemy:
else: else:
return False return False
def collision(self): def collision(self,window):
for bullet in bullets_on_screen: for bullet in bullets_on_screen:
if self.enemy_rect.colliderect(bullet.bullet_rect): if self.enemy_rect.colliderect(bullet.bullet_rect):
#Particle effect here
self.enemy_x += randint(-60,60) self.enemy_x += randint(-60,60)
self.enemy_y += randint(-60,60) self.enemy_y += randint(-60,60)
particle = Particle(self.enemy_rect[0] + self.en_width/2, self.enemy_rect[1] + self.en_height)
particles_on_screen.append(particle)
if len(particles_on_screen) != 0:
for particle in particles_on_screen:
particle.draw(window)
particle.update()

12
particles.py

@ -10,15 +10,17 @@ class Particle:
self.width = 4 self.width = 4
self.height = self.width self.height = self.width
self.vel = int(randint(0,3)/5) self.vel = int(randint(0,3)/5)
self.timer = 200 self.rect = pygame.Rect(self.x,self.y,self.width,self.height)
self.timer = randint(10,40)
def draw(self,window): def draw(self,window):
for i in range(10): for i in range(5): #+ randint(-30,30)
pygame.draw.rect(window,(255,255,255),(self.x + randint(-30,30), self.y + randint(-30,30), self.width, self.height)) pygame.draw.rect(window,(255,255,255),(self.rect[0] + randint(-30,30), self.rect[1] + randint(-30,30), self.rect[2], self.rect[3]))
def update(self): def update(self):
for particle in particles_on_screen: for particle in particles_on_screen:
self.timer -= 1 self.timer -= 0.5
#self.x += self.vel - randint(1,2) #self.x += self.vel - randint(1,2)
self.y += self.vel self.rect[1] += int(randint(-2,2)) #self.vel +
self.rect[0] += int(randint(-1,1))
if particle.timer <= 0: if particle.timer <= 0:
particles_on_screen.remove(particle) particles_on_screen.remove(particle)
#print('Particles :',str(len(particles_on_screen))) #print('Particles :',str(len(particles_on_screen)))

Loading…
Cancel
Save