Browse Source

Deleted messy and unecessary code

master
Unbewohnte 4 years ago
parent
commit
0e8c0916f6
  1. 16
      Main.py
  2. 32
      beings.py

16
Main.py

@ -15,11 +15,6 @@ window = pygame.display.set_mode((windowX,windowY))
icon = pygame.image.load('pics/logo.png')
pygame.display.set_icon(icon)
font = pygame.font.Font('freesansbold.ttf', 46)
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')
########
################################################################
@ -49,13 +44,12 @@ def play():
# main_surface.place(window,145,145)
player.teleportation()
player.shoot(window,start_color,bullet_image)
player.draw(window,start_color,player_image)
player.update(window,start_color,bullet_image)
player.shoot(window)
player.draw(window)
player.update()
player.collision()
if player.out_of_area():
death_timer -= 1
print('death_timer',death_timer)
timertext_color = (255-death_timer-60,3.6*death_timer,10)
text = font.render(str(death_timer), True, timertext_color) #Actual text
window.blit(text,text_rect)
@ -66,8 +60,8 @@ def play():
death_timer = 70
enemy.enemy_shoot(window,start_color,enemy_bul_img)
enemy.draw(window,start_color,enemy_image)
enemy.enemy_shoot(window)
enemy.draw(window)
enemy.move('right')
if enemy.enemy_x >= windowX-10: #That returning thingy

32
beings.py

@ -1,16 +1,18 @@
import pygame
from random import randint
from time import time
import bullets
from bullets import Bullet
from bullets import *
import time
import sys
############
windowX = 832
windowY = 832
bullets_on_screen = []
enemy_bul_on_screen = []
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')
############
class Player:
@ -23,12 +25,12 @@ class Player:
self.height = 64
self.width = 32
def update(self,window,start_color,bul_image):
def update(self):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.x - self.vel > 5 :
self.x -= self.vel
if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 :
if keys[pygame.K_RIGHT] and self.x + self.vel < windowX- self.width - 5 :
self.x += self.vel
if keys[pygame.K_UP] and self.y + self.height - self.vel > self.height + 5 :
@ -37,13 +39,13 @@ class Player:
if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY-15 :
self.y += self.vel
def draw(self,window,color,player_image):
pygame.draw.rect(window,color,(self.x,self.y,self.width,self.height))
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.player_rect = pygame.Rect(self.x, self.y, self.width, self.height)
def shoot(self,window,start_color,bul_image):
def shoot(self,window):
# if self.bul_cooldown >= 1: #With cooldown the game looks not so spicy.
# self.bul_cooldown -= 2 #Maybe it will be the matter of upgrades ?
@ -55,7 +57,7 @@ class Player:
if int(len(bullets_on_screen)) > 0:
for bullet in bullets_on_screen:
bullet.draw(window,start_color,bul_image)
bullet.draw(window,(0,0,0),bullet_image)
bullet.move()
if bullet.bullet_y <= -20:
bullets_on_screen.remove(bullet)
@ -113,9 +115,9 @@ class Enemy:
self.en_width = 32
self.en_height = 64
self.vel = 3
def draw(self,window,en_color,en_image):
pygame.draw.rect(window,en_color,(self.enemy_x, self.enemy_y, self.en_width, self.en_height))
window.blit(en_image,(self.enemy_x, self.enemy_y))
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) #Rect object for collision
def move(self,side):
if str(side) == "right":
@ -126,12 +128,12 @@ class Enemy:
self.enemy_y -= self.vel
elif str(side) == "down":
self.enemy_y += self.vel
def enemy_shoot(self,window,start_color,bul_image):
def enemy_shoot(self,window):
new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10)
enemy_bul_on_screen.append(new_bullet)
if int(len(enemy_bul_on_screen)) > 0:
for bullet in enemy_bul_on_screen:
bullet.draw(window,start_color,bul_image)
bullet.draw(window,(0,0,0),enemy_bul_img)
bullet.movedwn()
if bullet.bullet_y >= windowY +20:
enemy_bul_on_screen.remove(bullet)

Loading…
Cancel
Save