Browse Source

Particles are done

master
Unbewohnte 4 years ago
parent
commit
1c7b149115
  1. 11
      Main.py
  2. 38
      beings.py
  3. 15
      bullets.py
  4. 38
      particles.py

11
Main.py

@ -44,7 +44,7 @@ def play():
if player.out_of_area(): if player.out_of_area():
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)
window.blit(text,(windowX//2,windowY//2 - 100)) window.blit(text,(windowX//2,windowY//2 - 100))
if death_timer <= 1: if death_timer <= 1:
print('DED') print('DED')
@ -67,15 +67,6 @@ def play():
break break
#EEEEEEEEEEEEEEEEEEEEEEEEE #EEEEEEEEEEEEEEEEEEEEEEEEE
#PRTCLS_PRTCLS_PRTCLS_PRTCLS_
# partic = Particle(400,400)
# particles_on_screen.append(partic)
# for particle in particles_on_screen:
# 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()
pass pass

38
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
@ -25,7 +25,7 @@ class Player:
self.vel = 10 self.vel = 10
self.height = 64 self.height = 64
self.width = 32 self.width = 32
self.player_rect = pygame.Rect(self.x, self.y, self.width, self.height)
def update(self): def update(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.x - self.vel > 5 : if keys[pygame.K_LEFT] and self.x - self.vel > 5 :
@ -53,15 +53,15 @@ class Player:
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) player_bullets_on_screen.append(new_bullet)
self.bul_cooldown = 14 self.bul_cooldown = 14
if int(len(bullets_on_screen)) > 0: if int(len(player_bullets_on_screen)) > 0:
for bullet in bullets_on_screen: for bullet in player_bullets_on_screen:
bullet.draw(window,(0,0,0),bullet_image) bullet.draw(window,(0,0,0),bullet_image)
bullet.move() bullet.move("up")
if bullet.bullet_rect[1] <= -20: if bullet.bullet_rect[1] <= -20:
bullets_on_screen.remove(bullet) player_bullets_on_screen.remove(bullet)
def teleportation(self): def teleportation(self):
self.vel = 10 self.vel = 10
@ -96,6 +96,15 @@ class Player:
if self.player_rect.colliderect(bullet.bullet_rect): if self.player_rect.colliderect(bullet.bullet_rect):
self.x += randint(-100,100) self.x += randint(-100,100)
self.y += randint(-100,100) self.y += randint(-100,100)
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)
particles_on_screen_p.append(particle)
if len(particles_on_screen_p) != 0:
for particle in particles_on_screen_p:
particle.draw(window)
particle.update("down")
@ -132,7 +141,7 @@ class Enemy:
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.move("down")
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)
@ -145,15 +154,16 @@ class Enemy:
return False return False
def collision(self,window): def collision(self,window):
for bullet in bullets_on_screen: for bullet in player_bullets_on_screen:
if self.enemy_rect.colliderect(bullet.bullet_rect): if self.enemy_rect.colliderect(bullet.bullet_rect):
player_bullets_on_screen.remove(bullet)
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): 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_e.append(particle)
if len(particles_on_screen) != 0: if len(particles_on_screen_e) != 0:
for particle in particles_on_screen: for particle in particles_on_screen_e:
particle.draw(window) particle.draw(window)
particle.update() particle.update("up")

15
bullets.py

@ -2,22 +2,23 @@ import pygame
import random import random
from math import pow from math import pow
bullets_on_screen = [] player_bullets_on_screen = []
enemy_bul_on_screen = [] enemy_bul_on_screen = []
class Bullet: 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 __maybe ?)
self.bullet_x = bullet_x + random.randint(-9,9) # -8 -- 8 self.bullet_x = bullet_x + random.randint(-9,9)
self.bullet_y = bullet_y self.bullet_y = bullet_y
self.bullet_width = 4 self.bullet_width = 4
self.bullet_height = 12 self.bullet_height = 12
self.bullet_vel = random.randint(16,28) #12 -- 22 self.bullet_vel = random.randint(24,36) #16 -- 28
self.bullet_rect = pygame.Rect(self.bullet_x,self.bullet_y,self.bullet_width,self.bullet_height) self.bullet_rect = pygame.Rect(self.bullet_x,self.bullet_y,self.bullet_width,self.bullet_height)
def draw(self,window,start_color,bullet_image): def draw(self,window,start_color,bullet_image):
pygame.draw.rect(window,start_color,self.bullet_rect) pygame.draw.rect(window,start_color,self.bullet_rect)
window.blit(bullet_image,(self.bullet_rect[0],self.bullet_rect[1])) window.blit(bullet_image,(self.bullet_rect[0],self.bullet_rect[1]))
def move(self): def move(self,side):
self.bullet_rect[1] -= self.bullet_vel if str(side) == "up":
def movedwn(self): self.bullet_rect[1] -= self.bullet_vel
self.bullet_rect[1] += self.bullet_vel if str(side) == "down":
self.bullet_rect[1] += self.bullet_vel

38
particles.py

@ -1,25 +1,33 @@
import pygame import pygame
from random import randint from random import randint,randrange
particles_on_screen = []
particles_on_screen_e = []
particles_on_screen_p = []
class Particle: class Particle:
def __init__(self,x,y): def __init__(self,x,y):
self.x = x self.x = x
self.y = y self.y = y
self.width = 4 self.width = 4 #4
self.height = self.width self.height = self.width
self.vel = int(randint(0,3)/5) self.vel = int(randint(0,3)/5)
self.rect = pygame.Rect(self.x,self.y,self.width,self.height) self.rect = pygame.Rect(self.x,self.y,self.width,self.height)
self.timer = randint(10,40) self.timer = randint(10,66)
def draw(self,window): def draw(self,window):
for i in range(5): #+ randint(-30,30) for i in range(5): #5
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])) pygame.draw.rect(window,(randint(200,255),randint(50,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,side):
for particle in particles_on_screen: if str(side) == "up":
self.timer -= 0.5 for particle in particles_on_screen_e:
#self.x += self.vel - randint(1,2) particle.timer -= 0.5
self.rect[1] += self.vel + int(randint(-6,1)) #self.vel + #self.rect[1] -= (self.vel - randrange(-7,1))
self.rect[0] += self.vel + int(randint(-1,1)) particle.rect[1] += (self.vel + randrange(-7,1))
if particle.timer <= 0: particle.rect[0] += (self.vel + randrange(-3,3))
particles_on_screen.remove(particle) if particle.timer <= 0:
particles_on_screen_e.remove(particle)
if str(side) == "down":
for particle in particles_on_screen_p:
particle.timer -= 0.5
particle.rect[1] += (self.vel + randrange(-1,7))
particle.rect[0] += (self.vel + randrange(-3,3))
if particle.timer <= 0:
particles_on_screen_p.remove(particle)

Loading…
Cancel
Save