poprawiony pierwszy program, funkcjonalnosc mniejsza niz w finalnym, ale dziala
This commit is contained in:
parent
cd4012ce2b
commit
a4a9d8c38b
BIN
img/szarylaser.png
Normal file
BIN
img/szarylaser.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
49
main.py
49
main.py
@ -1,4 +1,5 @@
|
||||
import pygame
|
||||
#11.45
|
||||
import pygame.freetype
|
||||
import random
|
||||
pygame.init()
|
||||
@ -34,7 +35,7 @@ class player(object):
|
||||
pygame.draw.rect(window, (255, 0, 0), self.hitbox, 2)
|
||||
pygame.draw.rect(window, (255, 0, 0), self.hitbox1, 2)
|
||||
|
||||
class enemy(object):
|
||||
class Enemy(object):
|
||||
def __init__(self,x,y,width,height,health,design,vel):
|
||||
self.x = x
|
||||
self.y = y
|
||||
@ -68,8 +69,8 @@ class enemy(object):
|
||||
def redrawGameWindow():
|
||||
window.blit(bg,(0,0))
|
||||
spaceship.draw(window)
|
||||
for enemy in enemys:
|
||||
enemy.draw(window)
|
||||
for Enemy in enemies:
|
||||
Enemy.draw(window)
|
||||
for bullet in bullets:
|
||||
bullet.draw(window)
|
||||
#zawszeostatnie
|
||||
@ -80,14 +81,14 @@ clock = pygame.time.Clock()
|
||||
run=True
|
||||
spaceship=player((x-100)/2,y-105,100,100)
|
||||
bullets=[]
|
||||
enemys=[]
|
||||
enemys.append(enemy(random.randint(0,x-100),0,100,100,10,pygame.image.load('img/enemy2.png'),1)) #enemi[0]
|
||||
#enemys.append(enemy(random.randint(0,x-100),0,100,100,20,pygame.image.load('img/enemy1.png'),3)) #enemi[1]
|
||||
#enemys.append(enemy(random.randint(0,x-100),0,100,100,50,pygame.image.load('img/enemy3.png'),2)) #enemi[2]
|
||||
enemies=[]
|
||||
wave_lenght=0
|
||||
#enemies.append(Enemy(random.randint(0,x-100),0,100,100,10,pygame.image.load('img/enemy2.png'),1)) #enemi[0]
|
||||
#enemies.append(Enemy(random.randint(0,x-100),0,100,100,20,pygame.image.load('img/enemy1.png'),3)) #enemi[1]
|
||||
#enemies.append(Enemy(random.randint(0,x-100),0,100,100,50,pygame.image.load('img/enemy3.png'),2)) #enemi[2]
|
||||
on_window=[]
|
||||
score=1
|
||||
#mainloop
|
||||
i=0
|
||||
while run:
|
||||
clock.tick(27)
|
||||
# enemi self.hitbox = (self.x, self.y, self.width, self.height)
|
||||
@ -95,30 +96,35 @@ while run:
|
||||
# dol st self.hitbox1 = (self.x, self.y + 40, 100, 60)
|
||||
# if score%8==0:
|
||||
# i+=1
|
||||
# enemys.append(enemy(random.randint(0, x - 100), 0, 100, 100, 10, pygame.image.load('img/enemy2.png'), 1))
|
||||
# enemies.append(Enemy(random.randint(0, x - 100), 0, 100, 100, 10, pygame.image.load('img/enemy2.png'), 1))
|
||||
# break
|
||||
#najutrosprobujforem
|
||||
if spaceship.hitbox1[1]+spaceship.hitbox1[3] < enemys[0].hitbox[1]+enemys[0].hitbox[3]:
|
||||
if len(enemies)==0:
|
||||
wave_lenght+=3
|
||||
for i in range (wave_lenght):
|
||||
enemy=Enemy(random.randint(0, x - 100), 0, 100, 100, 10, pygame.image.load('img/enemy2.png'), 1) # enemi[0]
|
||||
enemies.append(enemy)
|
||||
for enemy in enemies[:]:
|
||||
|
||||
if spaceship.hitbox1[1]+spaceship.hitbox1[3] < enemy.hitbox[1]+enemy.hitbox[3]:
|
||||
print ('przelecial')
|
||||
if spaceship.hitbox[1]< enemys[i].hitbox[1]+enemys[i].hitbox[3]and spaceship.hitbox[0]<enemys[i].hitbox[0]+enemys[i].hitbox[2] and enemys[i].hitbox[0]<spaceship.hitbox[0]+spaceship.hitbox[2]:#nadlatuje od gory do dzioba/jego koniec mniejszy niz moj poczatek czyli po lewej/jego poczatek mniejszy niz moj koniec czyli po prawej
|
||||
if spaceship.hitbox[1]< enemy.hitbox[1]+enemy.hitbox[3]and spaceship.hitbox[0]<enemy.hitbox[0]+enemy.hitbox[2] and enemy.hitbox[0]<spaceship.hitbox[0]+spaceship.hitbox[2]:#nadlatuje od gory do dzioba/jego koniec mniejszy niz moj poczatek czyli po lewej/jego poczatek mniejszy niz moj koniec czyli po prawej
|
||||
print('zderzenie')
|
||||
if spaceship.hitbox1[1]< enemys[i].hitbox[1]+enemys[i].hitbox[3]and spaceship.hitbox1[0]<enemys[i].hitbox[0]+enemys[i].hitbox[2] and enemys[i].hitbox[0]<spaceship.hitbox1[0]+spaceship.hitbox1[2]:#nadlatuje od gory do dzioba/jego koniec mniejszy niz moj poczatek czyli po lewej/jego poczatek mniejszy niz moj koniec czyli po prawej
|
||||
if spaceship.hitbox1[1]< enemy.hitbox[1]+enemy.hitbox[3]and spaceship.hitbox1[0]<enemy.hitbox[0]+enemy.hitbox[2] and enemy.hitbox[0]<spaceship.hitbox1[0]+spaceship.hitbox1[2]:#nadlatuje od gory do dzioba/jego koniec mniejszy niz moj poczatek czyli po lewej/jego poczatek mniejszy niz moj koniec czyli po prawej
|
||||
print ('zderzenie')
|
||||
for event in pygame.event.get():
|
||||
if event.type== pygame.QUIT:
|
||||
run=False
|
||||
for bullet in bullets:
|
||||
if bullet.y-bullet.radius<enemys[i].hitbox[1]+enemys[i].hitbox[3] and bullet.y+bullet.radius>enemys[i].hitbox[1]:
|
||||
if bullet.x+bullet.radius>enemys[i].hitbox[0] and bullet.x-bullet.radius<enemys[i].hitbox[0]+enemys[0].hitbox[2]:
|
||||
enemys[i].health-=1
|
||||
if bullet.y-bullet.radius<enemy.hitbox[1]+enemy.hitbox[3] and bullet.y+bullet.radius>enemy.hitbox[1]:
|
||||
if bullet.x+bullet.radius>enemy.hitbox[0] and bullet.x-bullet.radius<enemy.hitbox[0]+enemy.hitbox[2]:
|
||||
enemy.health-=1
|
||||
bullets.pop(bullets.index(bullet))
|
||||
score+=1
|
||||
if enemys[i-1].health==0:
|
||||
enemys.pop(enemys.index((enemy)))
|
||||
if enemy.health==0:
|
||||
enemies.remove(enemy)
|
||||
if bullet.y> 0:
|
||||
bullet.y -=bullet.vel
|
||||
else:
|
||||
bullets.pop(bullets.index(bullet))
|
||||
|
||||
keys=pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT] and spaceship.x>0:
|
||||
spaceship.x -= spaceship.vel
|
||||
@ -127,4 +133,7 @@ while run:
|
||||
if keys[pygame.K_SPACE]:
|
||||
if len(bullets) < 50:
|
||||
bullets.append(projectile(round(spaceship.x + spaceship.width // 2), round(spaceship.y), 6, (255, 0, 0), 1))
|
||||
for event in pygame.event.get():
|
||||
if event.type== pygame.QUIT:
|
||||
run=False
|
||||
redrawGameWindow()
|
||||
|
Loading…
Reference in New Issue
Block a user