Browse Source

Fixes and optimization

master
Unbewohnte 4 years ago
parent
commit
3adb46d2a7
  1. 20
      Main.py
  2. 4
      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 player import *
from enemy import *
from surfaces import Surface
pygame.init()
pygame.display.set_caption('Healthless')
windowX = 600
windowY = 600
windowX = 640
windowY = 640
window = pygame.display.set_mode((windowX,windowY))
icon = pygame.image.load('pics/logo.png')
pygame.display.set_icon(icon)
######## Load Images
bullet_image = pygame.image.load('pics/second_bullet.png')
enemy_image = pygame.image.load('pics/enemy.png')
player_image = pygame.image.load('pics/player.png')
enemy_image = pygame.image.load('pics/32x64.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)))
@ -28,8 +29,9 @@ def play():
clock = pygame.time.Clock()
start_color = (0,0,0)
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 ???
player = Player(300,300,10,64,32,100) #(300,300,10,64,32,100) x,y,vel,height,width, health ???
enemy = Enemy()
player = Player()
test_surface = Surface()
while True:
for event in pygame.event.get():
@ -38,9 +40,11 @@ def play():
pygame.quit(),sys.exit()
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.draw(window,start_color,player_image)
player.update(window,start_color,bullet_image)

4
bullets.py

@ -2,8 +2,8 @@ import pygame
import random
class Bullet:
def __init__(self, bullet_x,bullet_y):
self.bullet_x = bullet_x + random.randint(-8,8) # -8 -- 8
def __init__(self, bullet_x, bullet_y):
self.bullet_x = bullet_x + random.randint(-9,9) # -8 -- 8
self.bullet_y = bullet_y
self.bullet_width = 4
self.bullet_height = 12

13
enemy.py

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

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

13
surfaces.py

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

Loading…
Cancel
Save