diff --git a/Main.py b/Main.py index ea3d55e..bf733ec 100644 --- a/Main.py +++ b/Main.py @@ -4,7 +4,7 @@ import sys from settings import windowX,windowY, DEBUG, window_caption,logo,gamefont from bullets import Bullet from beings import * -from surfaces import SlowTimeSurf +from surfaces import SlowTimeSurf, BuffRandomSurf from particles import * pygame.init() @@ -19,6 +19,7 @@ def play(): clock = pygame.time.Clock() pygame.mouse.set_visible(False) slowsurf = SlowTimeSurf(384,64) + randsurf = BuffRandomSurf(540,64) enemy = Enemy(100,100) enemy2 = Enemy(windowX,200) enemies_on_screen.append(enemy) @@ -53,10 +54,18 @@ def play(): print("Colliding !") slowsurf.switch = False else: - #for enemy in enemies_on_screen: + #for enemy in enemies_on_screen: #Doesn`t work and I don`t know why slowsurf.activate(enemy) slowsurf.activate(enemy2) + if randsurf.switch == True: + randsurf.place(window) + if randsurf.collide(player.player_rect): + print('Random !!!') + randsurf.switch = False + else: + randsurf.activate(player) + player.teleportation() diff --git a/beings.py b/beings.py index 47b0b35..be2984e 100644 --- a/beings.py +++ b/beings.py @@ -1,5 +1,5 @@ import pygame -from random import randint +from random import randint,randrange from time import time from bullets import * from particles import * @@ -10,6 +10,7 @@ import sys enemies_on_screen = [] class Player: + power_of_random = 2 def __init__(self): self.bul_cooldown = 14 self.tp_cooldown = 100 @@ -34,9 +35,10 @@ class Player: self.y += self.vel def draw(self,window): - pygame.draw.rect(window,(0,0,0),(self.x,self.y,self.width,self.height)) - window.blit(player_image,(self.x, self.y)) + #(self.x,self.y,self.width,self.height) self.player_rect = pygame.Rect(self.x, self.y, self.width, self.height) + #pygame.draw.rect(window,(0,0,0),(self.player_rect[0],self.player_rect[1],self.player_rect[2],self.player_rect[3])) + window.blit(player_image,(self.player_rect[0], self.player_rect[1])) def shoot(self,window): @@ -87,8 +89,8 @@ class Player: def collision(self,window): for bullet in enemy_bul_on_screen: if self.player_rect.colliderect(bullet.bullet_rect): - self.x += randint(-100*1.4,100*1.4) - self.y += randint(-100*1.4,100*1.4) + self.x += randrange(-100*1.4//self.power_of_random,100*1.4//self.power_of_random) + self.y += randrange(-100*1.4//self.power_of_random,100*1.4//self.power_of_random) enemy_bul_on_screen.remove(bullet) for i in range(5): particle = Particle(self.player_rect[0] + self.width/2, self.player_rect[1] + self.height) @@ -100,22 +102,19 @@ class Player: particle.update("down") - class Enemy: def __init__(self,x,y): - self.enemy_x = x #100 - self.enemy_y = y #100 + self.enemy_x = x + self.enemy_y = y self.en_width = 32 self.en_height = 64 self.vel = 3 self.bul_cooldown = 20 #12 self.alive = True - self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height) def draw(self,window): - 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)) self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height) + window.blit(enemy_image,(self.enemy_x, self.enemy_y)) def move(self,side): if str(side) == "right": self.enemy_x += self.vel @@ -153,8 +152,8 @@ class Enemy: for bullet in player_bullets_on_screen: if self.enemy_rect.colliderect(bullet.bullet_rect): player_bullets_on_screen.remove(bullet) - self.enemy_x += randint(-100*1.4,100*1.4) - self.enemy_y += randint(-100*1.4,100*1.4) + self.enemy_x += randrange(-100*Player.power_of_random,100*Player.power_of_random) + self.enemy_y += randrange(-100*Player.power_of_random,100*Player.power_of_random) for i in range(5): particle = Particle(self.enemy_rect[0] + self.en_width/2, self.enemy_rect[1] + self.en_height) particles_on_screen_e.append(particle) @@ -163,6 +162,3 @@ class Enemy: for particle in particles_on_screen_e: particle.draw(window) particle.update("up") - def refresh(self): - #self.bul_cooldown = 10 - self.vel = 3 diff --git a/bullets.py b/bullets.py index c69f57d..5740aac 100644 --- a/bullets.py +++ b/bullets.py @@ -6,7 +6,7 @@ player_bullets_on_screen = [] enemy_bul_on_screen = [] class Bullet: - def __init__(self, bullet_x, bullet_y): # y = ax^2 + bx + c __maybe ?) + def __init__(self, bullet_x, bullet_y): # y = ax^2 + bx + c self.bullet_x = bullet_x + random.randint(-9,9) self.bullet_y = bullet_y self.bullet_width = 4 diff --git a/pics/randsurf.png b/pics/randsurf.png new file mode 100644 index 0000000..f00a740 Binary files /dev/null and b/pics/randsurf.png differ diff --git a/settings.py b/settings.py index 125258e..f375b43 100644 --- a/settings.py +++ b/settings.py @@ -1,10 +1,11 @@ import pygame -############ +############ bullet_image = pygame.image.load('pics/second_bullet.png') enemy_bul_img = pygame.image.load('pics/bullet.png') enemy_image = pygame.image.load('pics/32x64.png') player_image = pygame.image.load('pics/32x64.png') timesurf_image = pygame.image.load('pics/timesurf.png') +randsurf_image = pygame.image.load('pics/randsurf.png') logo = pygame.image.load('pics/logo.png') ############ window_caption = 'Healthless' diff --git a/surfaces.py b/surfaces.py index 02196bc..55c6536 100644 --- a/surfaces.py +++ b/surfaces.py @@ -1,6 +1,5 @@ import pygame -#from beings import * -from settings import timesurf_image +from settings import timesurf_image, randsurf_image class BuffRandomSurf: def __init__(self,surf_x,surf_y): @@ -9,15 +8,27 @@ class BuffRandomSurf: self.width = 32 self.height = 64 self.color = (30,70,40) + self.switch = True + self.activation_timer = 1500 self.rect = pygame.Rect(self.x,self.y,self.width,self.height,) - def place(self,window,surf_x,surf_y): - pygame.draw.rect(window,self.color,self.rect) + + def place(self,window): + window.blit(randsurf_image,(self.rect[0],self.rect[1])) + def collide(self,object): if self.rect.colliderect(object): return True else: return False + def activate(self,player): + if self.activation_timer > 0: + self.activation_timer -= 1 + player.power_of_random = 3 + else: + player.power_of_random = 1 + #print(power_of_random : ',player.power_of_random) + class SlowTimeSurf: def __init__(self,surf_x,surf_y): self.x = surf_x @@ -28,14 +39,16 @@ class SlowTimeSurf: self.rect = pygame.Rect(self.x, self.y, self.width, self.height) self.switch = True self.activation_timer = 1000 + def place(self,window): - pygame.draw.rect(window,self.color,self.rect) window.blit(timesurf_image,(self.rect[0], self.rect[1])) + def collide(self,object): if self.rect.colliderect(object): return True else: return False + def activate(self,enemy): if self.activation_timer > 0: self.activation_timer -= 1