|
|
@ -1,16 +1,18 @@ |
|
|
|
import pygame |
|
|
|
import pygame |
|
|
|
from random import randint |
|
|
|
from random import randint |
|
|
|
from time import time |
|
|
|
from time import time |
|
|
|
import bullets |
|
|
|
from bullets import * |
|
|
|
from bullets import Bullet |
|
|
|
|
|
|
|
import time |
|
|
|
import time |
|
|
|
import sys |
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
############ |
|
|
|
############ |
|
|
|
windowX = 832 |
|
|
|
windowX = 832 |
|
|
|
windowY = 832 |
|
|
|
windowY = 832 |
|
|
|
bullets_on_screen = [] |
|
|
|
|
|
|
|
enemy_bul_on_screen = [] |
|
|
|
bullet_image = pygame.image.load('pics/second_bullet.png') |
|
|
|
|
|
|
|
enemy_bul_img = pygame.image.load('pics/bullet.png') |
|
|
|
|
|
|
|
enemy_image = pygame.image.load('pics/32x64.png') |
|
|
|
|
|
|
|
player_image = pygame.image.load('pics/32x64.png') |
|
|
|
############ |
|
|
|
############ |
|
|
|
|
|
|
|
|
|
|
|
class Player: |
|
|
|
class Player: |
|
|
@ -23,12 +25,12 @@ class Player: |
|
|
|
self.height = 64 |
|
|
|
self.height = 64 |
|
|
|
self.width = 32 |
|
|
|
self.width = 32 |
|
|
|
|
|
|
|
|
|
|
|
def update(self,window,start_color,bul_image): |
|
|
|
def update(self): |
|
|
|
keys = pygame.key.get_pressed() |
|
|
|
keys = pygame.key.get_pressed() |
|
|
|
if keys[pygame.K_LEFT] and self.x - self.vel > 5 : |
|
|
|
if keys[pygame.K_LEFT] and self.x - self.vel > 5 : |
|
|
|
self.x -= self.vel |
|
|
|
self.x -= self.vel |
|
|
|
|
|
|
|
|
|
|
|
if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 : |
|
|
|
if keys[pygame.K_RIGHT] and self.x + self.vel < windowX- self.width - 5 : |
|
|
|
self.x += self.vel |
|
|
|
self.x += self.vel |
|
|
|
|
|
|
|
|
|
|
|
if keys[pygame.K_UP] and self.y + self.height - self.vel > self.height + 5 : |
|
|
|
if keys[pygame.K_UP] and self.y + self.height - self.vel > self.height + 5 : |
|
|
@ -37,13 +39,13 @@ class Player: |
|
|
|
if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY-15 : |
|
|
|
if keys[pygame.K_DOWN] and self.y + self.height + self.vel < windowY-15 : |
|
|
|
self.y += self.vel |
|
|
|
self.y += self.vel |
|
|
|
|
|
|
|
|
|
|
|
def draw(self,window,color,player_image): |
|
|
|
def draw(self,window): |
|
|
|
pygame.draw.rect(window,color,(self.x,self.y,self.width,self.height)) |
|
|
|
pygame.draw.rect(window,(0,0,0),(self.x,self.y,self.width,self.height)) |
|
|
|
window.blit(player_image,(self.x, self.y)) |
|
|
|
window.blit(player_image,(self.x, self.y)) |
|
|
|
self.player_rect = pygame.Rect(self.x, self.y, self.width, self.height) |
|
|
|
self.player_rect = pygame.Rect(self.x, self.y, self.width, self.height) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def shoot(self,window,start_color,bul_image): |
|
|
|
def shoot(self,window): |
|
|
|
# if self.bul_cooldown >= 1: #With cooldown the game looks not so spicy. |
|
|
|
# if self.bul_cooldown >= 1: #With cooldown the game looks not so spicy. |
|
|
|
# self.bul_cooldown -= 2 #Maybe it will be the matter of upgrades ? |
|
|
|
# self.bul_cooldown -= 2 #Maybe it will be the matter of upgrades ? |
|
|
|
|
|
|
|
|
|
|
@ -55,7 +57,7 @@ class Player: |
|
|
|
|
|
|
|
|
|
|
|
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,(0,0,0),bullet_image) |
|
|
|
bullet.move() |
|
|
|
bullet.move() |
|
|
|
if bullet.bullet_y <= -20: |
|
|
|
if bullet.bullet_y <= -20: |
|
|
|
bullets_on_screen.remove(bullet) |
|
|
|
bullets_on_screen.remove(bullet) |
|
|
@ -113,9 +115,9 @@ class Enemy: |
|
|
|
self.en_width = 32 |
|
|
|
self.en_width = 32 |
|
|
|
self.en_height = 64 |
|
|
|
self.en_height = 64 |
|
|
|
self.vel = 3 |
|
|
|
self.vel = 3 |
|
|
|
def draw(self,window,en_color,en_image): |
|
|
|
def draw(self,window): |
|
|
|
pygame.draw.rect(window,en_color,(self.enemy_x, self.enemy_y, self.en_width, self.en_height)) |
|
|
|
pygame.draw.rect(window,(0,0,0),(self.enemy_x, self.enemy_y, self.en_width, self.en_height)) |
|
|
|
window.blit(en_image,(self.enemy_x, self.enemy_y)) |
|
|
|
window.blit(enemy_image,(self.enemy_x, self.enemy_y)) |
|
|
|
self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height) #Rect object for collision |
|
|
|
self.enemy_rect = pygame.Rect(self.enemy_x, self.enemy_y, self.en_width, self.en_height) #Rect object for collision |
|
|
|
def move(self,side): |
|
|
|
def move(self,side): |
|
|
|
if str(side) == "right": |
|
|
|
if str(side) == "right": |
|
|
@ -126,12 +128,12 @@ class Enemy: |
|
|
|
self.enemy_y -= self.vel |
|
|
|
self.enemy_y -= self.vel |
|
|
|
elif str(side) == "down": |
|
|
|
elif str(side) == "down": |
|
|
|
self.enemy_y += self.vel |
|
|
|
self.enemy_y += self.vel |
|
|
|
def enemy_shoot(self,window,start_color,bul_image): |
|
|
|
def enemy_shoot(self,window): |
|
|
|
new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10) |
|
|
|
new_bullet = Bullet(self.enemy_x + self.en_width/2, self.enemy_y + 10) |
|
|
|
enemy_bul_on_screen.append(new_bullet) |
|
|
|
enemy_bul_on_screen.append(new_bullet) |
|
|
|
if int(len(enemy_bul_on_screen)) > 0: |
|
|
|
if int(len(enemy_bul_on_screen)) > 0: |
|
|
|
for bullet in enemy_bul_on_screen: |
|
|
|
for bullet in enemy_bul_on_screen: |
|
|
|
bullet.draw(window,start_color,bul_image) |
|
|
|
bullet.draw(window,(0,0,0),enemy_bul_img) |
|
|
|
bullet.movedwn() |
|
|
|
bullet.movedwn() |
|
|
|
if bullet.bullet_y >= windowY +20: |
|
|
|
if bullet.bullet_y >= windowY +20: |
|
|
|
enemy_bul_on_screen.remove(bullet) |
|
|
|
enemy_bul_on_screen.remove(bullet) |
|
|
|