Browse Source

Started to understand the matter of clean code. Added image import file

master
Unbewohnte 4 years ago
parent
commit
1a96acb3eb
  1. 14
      Main.py
  2. 24
      beings.py
  3. 9
      images.py
  4. BIN
      pics/timesurf.png
  5. 32
      surfaces.py

14
Main.py

@ -3,7 +3,7 @@ import pygame_menu
import sys import sys
from bullets import Bullet from bullets import Bullet
from beings import * from beings import *
from surfaces import Surface from surfaces import SlowTimeSurf
from particles import * from particles import *
######## Set up things that will not change ######## Set up things that will not change
pygame.init() pygame.init()
@ -21,6 +21,7 @@ def play():
FPS = 70 FPS = 70
clock = pygame.time.Clock() clock = pygame.time.Clock()
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
slowsurf = SlowTimeSurf(400,20)
enemy = Enemy(100,100) enemy = Enemy(100,100)
enemy2 = Enemy(windowX,200) enemy2 = Enemy(windowX,200)
player = Player() player = Player()
@ -47,11 +48,21 @@ def play():
########################## ##########################
#PPPPPPPPPPPPPPPPPPPPPPPPP #PPPPPPPPPPPPPPPPPPPPPPPPP
slowsurf.place(window)
if slowsurf.collide(player.player_rect):
enemy.vel -= 0.1
enemy2.vel -= 0.1
print("Colliding !")
else:
enemy.vel = 3
enemy2.vel = 3
player.teleportation() player.teleportation()
player.shoot(window) player.shoot(window)
player.draw(window) player.draw(window)
player.update() player.update()
player.collision(window) player.collision(window)
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)
@ -62,6 +73,7 @@ def play():
break break
else: else:
death_timer = 70 death_timer = 70
#PPPPPPPPPPPPPPPPPPPPPPPPP #PPPPPPPPPPPPPPPPPPPPPPPPP
#EEEEEEEEEEEEEEEEEEEEEEEEE #EEEEEEEEEEEEEEEEEEEEEEEEE

24
beings.py

@ -3,18 +3,20 @@ from random import randint
from time import time from time import time
from bullets import * from bullets import *
from particles import * from particles import *
from images import *
import time import time
import sys import sys
############ ############
windowX = 832 windowX = 832
windowY = 832 windowY = 832
############ imgs for player-enemy(self,bullet) # ############ imgs for player-enemy(self,bullet), surfaces
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')
# ############
class Player: class Player:
def __init__(self): def __init__(self):
@ -28,16 +30,16 @@ class Player:
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)
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 > 0 :
self.x -= self.vel self.x -= self.vel
if keys[pygame.K_RIGHT] and self.x + self.vel < windowX- self.width - 5 : if keys[pygame.K_RIGHT] and self.x + self.width + self.vel < windowX:
self.x += self.vel self.x += self.vel
if keys[pygame.K_UP] and self.y + self.height - self.vel > self.height + 5 : if keys[pygame.K_UP] and self.y - self.vel > 0:
self.y -= self.vel self.y -= self.vel
if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY-15 : if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY :
self.y += self.vel self.y += self.vel
def draw(self,window): def draw(self,window):
@ -87,7 +89,7 @@ class Player:
self.tp_cooldown = 100 self.tp_cooldown = 100
def out_of_area(self): def out_of_area(self):
if self.x + self.width > windowX or self.x < 0 or self.y+self.height > windowY or self.y < 0: if self.x + self.width > windowX+3 or self.x < 0 - 3 or self.y+self.height > windowY+3 or self.y < 0 -3:
return True return True
else: else:
return False return False

9
images.py

@ -0,0 +1,9 @@
import pygame
############ imgs for player-enemy(self,bullet), surfaces
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')
############

BIN
pics/timesurf.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

32
surfaces.py

@ -1,12 +1,30 @@
import pygame import pygame
from beings import * from beings import *
from images import timesurf_image
class Surface: class Surface:
def __init__(self,name): def __init__(self,surf_x,surf_y):
if str(name) == 'killsurf': self.x = surf_x
self.width = windowX self.y = surf_y
self.height = windowY self.width = 32
self.height = 64
self.color = (30,70,40) self.color = (30,70,40)
self.rect = pygame.Rect(self.x,self.y,self.width,self.height,)
def place(self,window,surf_x,surf_y): def place(self,window,surf_x,surf_y):
pygame.draw.rect(window,self.color,(surf_x,surf_y,self.width,self.height)) pygame.draw.rect(window,self.color,self.rect)
class SlowTimeSurf:
def __init__(self,surf_x,surf_y):
self.x = surf_x
self.y = surf_y
self.width = 32
self.height = 64
self.color = (0,0,0)
self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
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

Loading…
Cancel
Save