commit cd4012ce2b10e082a8f17862cbf8f6ca017fe9e5 Author: Amadeusz Lewandowski Date: Sun Jan 10 07:08:43 2021 +0100 stan na 10.01 diff --git a/img/bg.jpg b/img/bg.jpg new file mode 100644 index 0000000..46c34b1 Binary files /dev/null and b/img/bg.jpg differ diff --git a/img/enemy1.png b/img/enemy1.png new file mode 100644 index 0000000..331bb01 Binary files /dev/null and b/img/enemy1.png differ diff --git a/img/enemy2.png b/img/enemy2.png new file mode 100644 index 0000000..4877438 Binary files /dev/null and b/img/enemy2.png differ diff --git a/img/enemy3.png b/img/enemy3.png new file mode 100644 index 0000000..74abbf0 Binary files /dev/null and b/img/enemy3.png differ diff --git a/img/statek.png b/img/statek.png new file mode 100644 index 0000000..01d1fc4 Binary files /dev/null and b/img/statek.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..00e52b5 --- /dev/null +++ b/main.py @@ -0,0 +1,130 @@ +import pygame +import pygame.freetype +import random +pygame.init() +x=1366 +y=768 +window=pygame.display.set_mode((x, y)) +pygame.display.set_caption("Gra Pracownia Programowania") +bg=pygame.image.load('img/bg.jpg ') +look = pygame.image.load('img/statek.png') +class projectile(object): + def __init__(self, x, y, radius, color, facing): + self.x = x + self.y = y + self.radius = radius + self.color = color + self.vel =16 * facing + def draw(self, window): + pygame.draw.circle(window, self.color, (self.x, self.y), self.radius) + +class player(object): + def __init__(self, x, y, width, height): + self.x = x + self.y = y + self.width = width + self.height = height + self.vel = 25 + self.hitbox = (self.x + 30, self.y, 40, 40) + self.hitbox1 = (self.x, self.y + 40, 100, 60) + def draw(self,window): + window.blit(look,(self.x,self.y)) + self.hitbox = (self.x+30, self.y, 40, 40) + self.hitbox1 = (self.x, self.y+40, 100, 60) + pygame.draw.rect(window, (255, 0, 0), self.hitbox, 2) + pygame.draw.rect(window, (255, 0, 0), self.hitbox1, 2) + +class enemy(object): + def __init__(self,x,y,width,height,health,design,vel): + self.x = x + self.y = y + self.width = width + self.height = height + self.path = [self.x, y-height] + self.health= health + self.design=design + self.vel=vel + self.hitbox = (self.x, self.y, self.width, self.height) + def draw (self,window): + self.move() + self.hitbox = (self.x, self.y, self.width, self.height) + window.blit(self.design,(self.x,self.y)) + pygame.draw.rect(window, (255, 0, 0), self.hitbox, 2) + def move (self): + if self.vel>0: + if self.health>0: + self.y+=self.vel + def hit(self): + if self.health>0: + self.health-=1 + else: + print('umar') + print('hit') + def colision(self): + font1 = pygame.font.SysFont('comicsans', 100) + text = font1.render('zderzenie', 1, (255, 0, 0)) + window.blit(text, (250 - (text.get_width() / 2), 200)) +#mainstuff +def redrawGameWindow(): + window.blit(bg,(0,0)) + spaceship.draw(window) + for enemy in enemys: + enemy.draw(window) + for bullet in bullets: + bullet.draw(window) + #zawszeostatnie + pygame.display.update() +## +font=pygame.font.SysFont('comicsans',30,True,True) +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] +on_window=[] +score=1 +#mainloop +i=0 +while run: + clock.tick(27) + # enemi self.hitbox = (self.x, self.y, self.width, self.height) + # statek self.hitbox = (self.x + 30, self.y, 40, 40) + # 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)) + # break + #najutrosprobujforem + if spaceship.hitbox1[1]+spaceship.hitbox1[3] < enemys[0].hitbox[1]+enemys[0].hitbox[3]: + print ('przelecial') + if spaceship.hitbox[1]< enemys[i].hitbox[1]+enemys[i].hitbox[3]and spaceship.hitbox[0]enemys[i].hitbox[1]: + if bullet.x+bullet.radius>enemys[i].hitbox[0] and bullet.x-bullet.radius 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 + if keys[pygame.K_RIGHT] and spaceship.x< x-100: + spaceship.x += spaceship.vel + 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)) + redrawGameWindow()