From 2180b77b6dacb1491f88893f6b8f6ba64123e7b1 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Mon, 24 Aug 2020 11:54:29 +0300 Subject: [PATCH] A new surface added; Understood that I don`t need to draw rects --- Main.py | 13 +++++++++++-- beings.py | 28 ++++++++++++---------------- bullets.py | 2 +- pics/randsurf.png | Bin 0 -> 16137 bytes settings.py | 3 ++- surfaces.py | 23 ++++++++++++++++++----- 6 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 pics/randsurf.png 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 0000000000000000000000000000000000000000..f00a740b829033b44f357fabebd1c8e900c041fe GIT binary patch literal 16137 zcmeI3dsGuw9>+&1K3GupsPv_h2BdguGI@uDBnSiy+8{!Zhn&@6W`j|)ug+3p{E&debs zzx%zv-|ybf{oOnB&n(W$oDvcCS{MXD5g9sdHvP?^Ka+ttvwm7&l21rgACi02Z7=I4+CX>QK7WTu)pj{oCCP zb2*+aRGFHa>`utZ*Jp83NjuJw@})dfAQE!q3cgS(Q3!>TI3j^i3=0LYNWl{dl@hs9 zDC6{8Tum7LOJ&E5%4}_VPdeICb4?UwQ^IgXMFqb?%qQ(7uu!2;zyc9067lFBJV&LK zLR>tnBgPw~H;xu}pmxGW5u}ylj*AqNPD;(?x)b@Xo_SepzC>0>4?CJ7>_Tj?kS~A- zaMJ6U-7J=VJsnh9IX#k|nf05{VW_m>a5nBBopuyYE61%=On-y0nMjIsn8*Rf?~@0d z1%~5q1<7V7K=XB71!hYvK5k~*w1Wm!M444jg5d*ln6|bA86uc{>qU%qY zYR3_Zv>Qm$tnpS^R`0Aisi~a!Ji>~R6^@B280_s|YJVVHi%_^mBoGOBf&`vOVxUV= zO#jK>5{Q)oK|m01PauY#E_)22kQa#()EA6HVuZ2sg`)U-2FK9rl^IqCg;-HML#v_Z z&L;>=iAv-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sQz z8z6Ff%-X_-Q0FseT-3y|>e-K4w$5B%^W_`6Hl@j(&WHD=j(`r;g+p6c8@iHSNia6I z9Z$^5DcZ7Q?ye~4OHGvRxaQN--@i3~*|)St4oXN z{=4;H^!*8j12YCa51C`{IC|sqNU8Q-6FgP>-6c47@4T6(j^#UcOuim^|D1Zkw5a8r zpS5$*^M~7@h&$=3| zF=ZF33)h@|v~X~BUQ$it2uQ!}Nz&eV7Zi`5&KNwOcbeL^qV7iB`Lfc`-$uLy>Dr37 zLAN4eq3YqcOG8ap(-RA+@5I&IhAF)8(vz#&^>afyJFQQiEPQGFxUoEC?#kTxVOfJt zl!^*JZw#$e{lnQ&@~?-lom;dd{m%=&zBT>i`FleP{xo*?$emED4WMJj@OK-J(xF;zoBR zUU_%|TE{V$E{B~A8Or6EVRo_X)-YRBBC(XQ$>OJ+&mMYqI# fJl_dDRzMNq)#D-$#mBl|R?kSw)NW6i^WJ{|X^|ct literal 0 HcmV?d00001 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