Browse Source

Fixes and optimization

master
Unbewohnte 4 years ago
parent
commit
3adb46d2a7
  1. 20
      Main.py
  2. 2
      bullets.py
  3. 13
      enemy.py
  4. BIN
      pics/32x64.png
  5. 0
      pics/enemy(30x60).png
  6. 0
      pics/player(32x64).png
  7. 33
      player.py
  8. 13
      surfaces.py

20
Main.py

@ -6,19 +6,20 @@ import time
from bullets import * from bullets import *
from player import * from player import *
from enemy import * from enemy import *
from surfaces import Surface
pygame.init() pygame.init()
pygame.display.set_caption('Healthless') pygame.display.set_caption('Healthless')
windowX = 600 windowX = 640
windowY = 600 windowY = 640
window = pygame.display.set_mode((windowX,windowY)) window = pygame.display.set_mode((windowX,windowY))
icon = pygame.image.load('pics/logo.png') icon = pygame.image.load('pics/logo.png')
pygame.display.set_icon(icon) pygame.display.set_icon(icon)
######## Load Images ######## Load Images
bullet_image = pygame.image.load('pics/second_bullet.png') bullet_image = pygame.image.load('pics/second_bullet.png')
enemy_image = pygame.image.load('pics/enemy.png') enemy_image = pygame.image.load('pics/32x64.png')
player_image = pygame.image.load('pics/player.png') player_image = pygame.image.load('pics/32x64.png')
######## ########
#rand_color = (int(random.randint(0,254)),int(random.randint(0,254)) ,int(random.randint(0,254))) #rand_color = (int(random.randint(0,254)),int(random.randint(0,254)) ,int(random.randint(0,254)))
@ -28,8 +29,9 @@ def play():
clock = pygame.time.Clock() clock = pygame.time.Clock()
start_color = (0,0,0) start_color = (0,0,0)
pygame.mouse.set_visible(False) pygame.mouse.set_visible(False)
enemy = Enemy(10,random.randint(10,250),30,60,30,30) #(100,100,30,60,30,30) x,y,width,height, damage and health ??? enemy = Enemy()
player = Player(300,300,10,64,32,100) #(300,300,10,64,32,100) x,y,vel,height,width, health ??? player = Player()
test_surface = Surface()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
@ -38,9 +40,11 @@ def play():
pygame.quit(),sys.exit() pygame.quit(),sys.exit()
break break
window.fill((0,70,80)) window.fill((41, 64, 59)) # (41,64,59)
player.debug() test_surface.place(window,352,352)
player.teleportation()
player.shoot(window,start_color,bullet_image) player.shoot(window,start_color,bullet_image)
player.draw(window,start_color,player_image) player.draw(window,start_color,player_image)
player.update(window,start_color,bullet_image) player.update(window,start_color,bullet_image)

2
bullets.py

@ -3,7 +3,7 @@ import random
class Bullet: class Bullet:
def __init__(self, bullet_x, bullet_y): def __init__(self, bullet_x, bullet_y):
self.bullet_x = bullet_x + random.randint(-8,8) # -8 -- 8 self.bullet_x = bullet_x + random.randint(-9,9) # -8 -- 8
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

13
enemy.py

@ -5,13 +5,12 @@ from bullets import Bullet
class Enemy: class Enemy:
def __init__(self,enemy_x,enemy_y,en_width,en_height,en_damage,en_health): def __init__(self):
self.enemy_x = enemy_x self.enemy_x = 100
self.enemy_y = enemy_y self.enemy_y = 100
self.en_width = en_width self.en_width = 32
self.en_height = en_height self.en_height = 64
self.en_damage = en_damage
self.en_health = en_health
def draw(self,window,en_color,en_image): 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)) 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)) window.blit(en_image,(self.enemy_x, self.enemy_y))

BIN
pics/32x64.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

0
pics/enemy.png → pics/enemy(30x60).png

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

0
pics/player.png → pics/player(32x64).png

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

33
player.py

@ -1,22 +1,22 @@
import pygame import pygame
from random import randint
from time import time
import bullets import bullets
from bullets import Bullet from bullets import Bullet
import time import time
import sys import sys
windowX = 600 windowX = 640
windowY = 600 windowY = 640
bullets_on_screen = [] bullets_on_screen = []
class Player: class Player:
def __init__(self,x,y,vel,height,width,health): def __init__(self):
self.x = x self.x = 300
self.y = y self.y = 300
self.vel = vel self.vel = 10
self.height = height self.height = 64
self.width = width self.width = 32
self.health = health
def update(self,window,start_color,bul_image): def update(self,window,start_color,bul_image):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
@ -35,11 +35,14 @@ class Player:
def draw(self,window,color,player_image): def draw(self,window,color,player_image):
self.rect = pygame.draw.rect(window,color,(self.x,self.y,self.width,self.height)) self.rect = pygame.draw.rect(window,color,(self.x,self.y,self.width,self.height))
window.blit(player_image,(self.x, self.y)) window.blit(player_image,(self.x, self.y))
def shoot(self,window,start_color,bul_image): def shoot(self,window,start_color,bul_image):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_z]: if keys[pygame.K_z]:
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) bullets_on_screen.append(new_bullet)
if int(len(bullets_on_screen)) > 0: if int(len(bullets_on_screen)) > 0:
for bullet in bullets_on_screen: for bullet in bullets_on_screen:
bullet.draw(window,start_color,bul_image) bullet.draw(window,start_color,bul_image)
@ -48,12 +51,8 @@ class Player:
bullets_on_screen.remove(bullet) bullets_on_screen.remove(bullet)
print('Bullets: ' + str(len(bullets_on_screen))) print('Bullets: ' + str(len(bullets_on_screen)))
def debug(self): def teleportation(self):
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_d]: if keys[pygame.K_d]:
self.x = 300 self.x = randint(10,550)
self.y = 300 self.y = randint(10,550)
# def check__health(self): ################################# Work with that
# if self.health <= 0:
# mainmenu.deathscreen()

13
surfaces.py

@ -1,13 +1,12 @@
import pygame import pygame
class surface: class Surface:
def __init__(self,name): def __init__(self):
self.surf_name = name self.width = 64
if self.surf_name == 'kill': self.height = 64
killsurf()
def killsurf(self): def killsurf(self):
pass pass
def place(self,name,pos,width,height): def place(self,window,surf_x,surf_y):
pass pygame.draw.rect(window,(100,200,240),(surf_x,surf_y,self.width,self.height))

Loading…
Cancel
Save