Browse Source

A new surface added; Understood that I don`t need to draw rects

master
Unbewohnte 4 years ago
parent
commit
2180b77b6d
  1. 13
      Main.py
  2. 28
      beings.py
  3. 2
      bullets.py
  4. BIN
      pics/randsurf.png
  5. 3
      settings.py
  6. 23
      surfaces.py

13
Main.py

@ -4,7 +4,7 @@ import sys
from settings import windowX,windowY, DEBUG, window_caption,logo,gamefont from settings import windowX,windowY, DEBUG, window_caption,logo,gamefont
from bullets import Bullet from bullets import Bullet
from beings import * from beings import *
from surfaces import SlowTimeSurf from surfaces import SlowTimeSurf, BuffRandomSurf
from particles import * from particles import *
pygame.init() pygame.init()
@ -19,6 +19,7 @@ def play():
clock = pygame.time.Clock() clock = pygame.time.Clock()
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
slowsurf = SlowTimeSurf(384,64) slowsurf = SlowTimeSurf(384,64)
randsurf = BuffRandomSurf(540,64)
enemy = Enemy(100,100) enemy = Enemy(100,100)
enemy2 = Enemy(windowX,200) enemy2 = Enemy(windowX,200)
enemies_on_screen.append(enemy) enemies_on_screen.append(enemy)
@ -53,10 +54,18 @@ def play():
print("Colliding !") print("Colliding !")
slowsurf.switch = False slowsurf.switch = False
else: 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(enemy)
slowsurf.activate(enemy2) 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() player.teleportation()

28
beings.py

@ -1,5 +1,5 @@
import pygame import pygame
from random import randint from random import randint,randrange
from time import time from time import time
from bullets import * from bullets import *
from particles import * from particles import *
@ -10,6 +10,7 @@ import sys
enemies_on_screen = [] enemies_on_screen = []
class Player: class Player:
power_of_random = 2
def __init__(self): def __init__(self):
self.bul_cooldown = 14 self.bul_cooldown = 14
self.tp_cooldown = 100 self.tp_cooldown = 100
@ -34,9 +35,10 @@ class Player:
self.y += self.vel self.y += self.vel
def draw(self,window): def draw(self,window):
pygame.draw.rect(window,(0,0,0),(self.x,self.y,self.width,self.height)) #(self.x,self.y,self.width,self.height)
window.blit(player_image,(self.x, self.y))
self.player_rect = pygame.Rect(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): def shoot(self,window):
@ -87,8 +89,8 @@ 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):
self.x += 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 += randint(-100*1.4,100*1.4) self.y += randrange(-100*1.4//self.power_of_random,100*1.4//self.power_of_random)
enemy_bul_on_screen.remove(bullet) enemy_bul_on_screen.remove(bullet)
for i in range(5): for i in range(5):
particle = Particle(self.player_rect[0] + self.width/2, self.player_rect[1] + self.height) particle = Particle(self.player_rect[0] + self.width/2, self.player_rect[1] + self.height)
@ -100,22 +102,19 @@ class Player:
particle.update("down") particle.update("down")
class Enemy: class Enemy:
def __init__(self,x,y): def __init__(self,x,y):
self.enemy_x = x #100 self.enemy_x = x
self.enemy_y = y #100 self.enemy_y = y
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 = 20 #12 self.bul_cooldown = 20 #12
self.alive = True self.alive = True
self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height) self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height)
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))
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) 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): def move(self,side):
if str(side) == "right": if str(side) == "right":
self.enemy_x += self.vel self.enemy_x += self.vel
@ -153,8 +152,8 @@ class Enemy:
for bullet in player_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) player_bullets_on_screen.remove(bullet)
self.enemy_x += randint(-100*1.4,100*1.4) self.enemy_x += randrange(-100*Player.power_of_random,100*Player.power_of_random)
self.enemy_y += randint(-100*1.4,100*1.4) self.enemy_y += randrange(-100*Player.power_of_random,100*Player.power_of_random)
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_e.append(particle) particles_on_screen_e.append(particle)
@ -163,6 +162,3 @@ class Enemy:
for particle in particles_on_screen_e: for particle in particles_on_screen_e:
particle.draw(window) particle.draw(window)
particle.update("up") particle.update("up")
def refresh(self):
#self.bul_cooldown = 10
self.vel = 3

2
bullets.py

@ -6,7 +6,7 @@ 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
self.bullet_x = bullet_x + random.randint(-9,9) 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

BIN
pics/randsurf.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

3
settings.py

@ -1,10 +1,11 @@
import pygame import pygame
############ ############
bullet_image = pygame.image.load('pics/second_bullet.png') bullet_image = pygame.image.load('pics/second_bullet.png')
enemy_bul_img = pygame.image.load('pics/bullet.png') enemy_bul_img = pygame.image.load('pics/bullet.png')
enemy_image = pygame.image.load('pics/32x64.png') enemy_image = pygame.image.load('pics/32x64.png')
player_image = pygame.image.load('pics/32x64.png') player_image = pygame.image.load('pics/32x64.png')
timesurf_image = pygame.image.load('pics/timesurf.png') timesurf_image = pygame.image.load('pics/timesurf.png')
randsurf_image = pygame.image.load('pics/randsurf.png')
logo = pygame.image.load('pics/logo.png') logo = pygame.image.load('pics/logo.png')
############ ############
window_caption = 'Healthless' window_caption = 'Healthless'

23
surfaces.py

@ -1,6 +1,5 @@
import pygame import pygame
#from beings import * from settings import timesurf_image, randsurf_image
from settings import timesurf_image
class BuffRandomSurf: class BuffRandomSurf:
def __init__(self,surf_x,surf_y): def __init__(self,surf_x,surf_y):
@ -9,15 +8,27 @@ class BuffRandomSurf:
self.width = 32 self.width = 32
self.height = 64 self.height = 64
self.color = (30,70,40) self.color = (30,70,40)
self.switch = True
self.activation_timer = 1500
self.rect = pygame.Rect(self.x,self.y,self.width,self.height,) 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): def collide(self,object):
if self.rect.colliderect(object): if self.rect.colliderect(object):
return True return True
else: else:
return False 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: class SlowTimeSurf:
def __init__(self,surf_x,surf_y): def __init__(self,surf_x,surf_y):
self.x = surf_x self.x = surf_x
@ -28,14 +39,16 @@ class SlowTimeSurf:
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.switch = True self.switch = True
self.activation_timer = 1000 self.activation_timer = 1000
def place(self,window): def place(self,window):
pygame.draw.rect(window,self.color,self.rect)
window.blit(timesurf_image,(self.rect[0], self.rect[1])) window.blit(timesurf_image,(self.rect[0], self.rect[1]))
def collide(self,object): def collide(self,object):
if self.rect.colliderect(object): if self.rect.colliderect(object):
return True return True
else: else:
return False return False
def activate(self,enemy): def activate(self,enemy):
if self.activation_timer > 0: if self.activation_timer > 0:
self.activation_timer -= 1 self.activation_timer -= 1

Loading…
Cancel
Save