From 3adb46d2a7b4b569a22ebaf8dcfd68e7abbd7176 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Fri, 7 Aug 2020 18:14:46 +0300 Subject: [PATCH] Fixes and optimization --- Main.py | 20 +++++++++------ bullets.py | 6 ++--- enemy.py | 13 +++++----- pics/32x64.png | Bin 0 -> 16990 bytes pics/{enemy.png => enemy(30x60).png} | Bin pics/{player.png => player(32x64).png} | Bin player.py | 33 ++++++++++++------------- surfaces.py | 13 +++++----- 8 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 pics/32x64.png rename pics/{enemy.png => enemy(30x60).png} (100%) rename pics/{player.png => player(32x64).png} (100%) diff --git a/Main.py b/Main.py index c450e0c..767b690 100644 --- a/Main.py +++ b/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) diff --git a/bullets.py b/bullets.py index f28b089..650fc2c 100644 --- a/bullets.py +++ b/bullets.py @@ -2,11 +2,11 @@ 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 + self.bullet_height = 12 self.bullet_vel = random.randint(12,22) #12 -- 22 def draw(self,window,start_color,bullet_image): self.rect = pygame.draw.rect(window,start_color,(self.bullet_x,self.bullet_y,self.bullet_width,self.bullet_height)) diff --git a/enemy.py b/enemy.py index 9febfb3..13e2854 100644 --- a/enemy.py +++ b/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)) diff --git a/pics/32x64.png b/pics/32x64.png new file mode 100644 index 0000000000000000000000000000000000000000..b7b1a0653e2a3ec0c79a91f76f7fb9cc4e91ce56 GIT binary patch literal 16990 zcmeI3dsGuw9><5Gw%}T;(%Pz&7+xxbnIt5T7=lQ6DM1=RKx$=@Oh_cjgk*rAfVhHI zYO%JIBHMzGYU`t*)wb&cb=$I)inU?|Y^$PT718x>Ft(@NvuDqloCC@4 z{_gkpyZ3W{_s+~8vnDnsVvO@7X9$AEL`6zu?|@1$pAWxKpAG8R&NrTgP7L1Lh`qz z8D=u9U5KcBfjI&en=SMY z5VHA<-VamkO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=E?dCBEbwC~@xvFK-+i1dH`(J@iky1;8&H%6~?d3E~JX%o0r zqZ4FfcVG8BH?jJe%nY&)$@M8&TjDUH%@Xrg$AV~&`X!=zAK5bD$%f+nB@Vuwoj9v$ zY_V`OC$6rCzU_3mnZO>?Y?_f za*^AvBKEpdoJULE}Q7T=F=%)gmlbGlft zypatyLY&dG|^fg z_fM2(x+_u%m)2>gq7rI65@a1k-;_mOJ7UVx$^U%^^=WE)eNR?hv(MM1tL8e3)A%8d z&+ts}i>1tXk5eTZr>;FdS6y&Iz5QyQJlMa}w`S$NuCdqQ=3U%wKn}Udl7ZX;ksXZSuv%!36PHx^$pExzvhtE3?nLQnTn+(-> Xzrc8|dK7uCLQqs#jHGII%HRJ3D)eo< literal 0 HcmV?d00001 diff --git a/pics/enemy.png b/pics/enemy(30x60).png similarity index 100% rename from pics/enemy.png rename to pics/enemy(30x60).png diff --git a/pics/player.png b/pics/player(32x64).png similarity index 100% rename from pics/player.png rename to pics/player(32x64).png diff --git a/player.py b/player.py index 304ec12..62676c0 100644 --- a/player.py +++ b/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) diff --git a/surfaces.py b/surfaces.py index 8aac7b2..ac9c085 100644 --- a/surfaces.py +++ b/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))