Browse Source

Improved particles

master
Unbewohnte 4 years ago
parent
commit
b8eb1ca864
  1. 4
      Main.py
  2. 3
      beings.py
  3. 7
      particles.py

4
Main.py

@ -24,8 +24,6 @@ def play():
enemy = Enemy() enemy = Enemy()
player = Player() player = Player()
death_timer = 70 death_timer = 70
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))
########################## ##########################
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -47,7 +45,7 @@ def play():
death_timer -= 1 death_timer -= 1
timertext_color = (255-death_timer-60,3.6*death_timer,10) timertext_color = (255-death_timer-60,3.6*death_timer,10)
text = font.render(str(death_timer), True, timertext_color) #Actual text text = font.render(str(death_timer), True, timertext_color) #Actual text
window.blit(text,text_rect) window.blit(text,(windowX//2,windowY//2 - 100))
if death_timer <= 1: if death_timer <= 1:
print('DED') print('DED')
break break

3
beings.py

@ -149,9 +149,10 @@ class Enemy:
if self.enemy_rect.colliderect(bullet.bullet_rect): if self.enemy_rect.colliderect(bullet.bullet_rect):
self.enemy_x += randint(-60,60) self.enemy_x += randint(-60,60)
self.enemy_y += randint(-60,60) self.enemy_y += randint(-60,60)
for i in range(5):
particle = Particle(self.enemy_rect[0] + self.en_width/2, self.enemy_rect[1] + self.en_height) particle = Particle(self.enemy_rect[0] + self.en_width/2, self.enemy_rect[1] + self.en_height)
particles_on_screen.append(particle) particles_on_screen.append(particle)
if len(particles_on_screen) != 0: if len(particles_on_screen) != 0:
for particle in particles_on_screen: for particle in particles_on_screen:
particle.draw(window) particle.draw(window)

7
particles.py

@ -14,13 +14,12 @@ class Particle:
self.timer = randint(10,40) self.timer = randint(10,40)
def draw(self,window): def draw(self,window):
for i in range(5): #+ randint(-30,30) for i in range(5): #+ randint(-30,30)
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])) pygame.draw.rect(window,(randint(200,255),randint(170,255),20),(self.rect[0] + randint(-35,35), 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 -= 0.5 self.timer -= 0.5
#self.x += self.vel - randint(1,2) #self.x += self.vel - randint(1,2)
self.rect[1] += int(randint(-2,2)) #self.vel + self.rect[1] += self.vel + int(randint(-6,1)) #self.vel +
self.rect[0] += int(randint(-1,1)) self.rect[0] += self.vel + 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)))

Loading…
Cancel
Save