My OOP practice project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

4 years ago
import pygame
from random import randint
from time import time
4 years ago
import bullets
from bullets import Bullet
import time
import sys
windowX = 640
windowY = 640
4 years ago
bullets_on_screen = []
clock = pygame.time.Clock()
4 years ago
class Player:
def __init__(self):
self.bul_cooldown = 50
self.tp_cooldown = 100
self.x = 300
self.y = 300
self.vel = 10
self.height = 64
self.width = 32
4 years ago
def update(self,window,start_color,bul_image):
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and self.x > 5 :
self.x -= self.vel
if keys[pygame.K_RIGHT] and self.x < windowX- self.width - 5 :
self.x += self.vel
if keys[pygame.K_UP] and self.y + self.height > self.height + 5 :
self.y -= self.vel
if keys[pygame.K_DOWN] and self.y + self.height < windowY-15 :
self.y += self.vel
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))
4 years ago
def shoot(self,window,start_color,bul_image):
# 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 ?
4 years ago
keys = pygame.key.get_pressed()
if keys[pygame.K_z]: # and self.bul_cooldown == 0
4 years ago
new_bullet = Bullet(self.x + self.width/2, self.y + 10)
bullets_on_screen.append(new_bullet)
#self.bul_cooldown = 20
4 years ago
if int(len(bullets_on_screen)) > 0:
for bullet in bullets_on_screen:
bullet.draw(window,start_color,bul_image)
bullet.move()
if bullet.bullet_y <= -20:
bullets_on_screen.remove(bullet)
print('Bullets: ' + str(len(bullets_on_screen)))
def teleportation(self):
self.vel = 10
if self.tp_cooldown >= 1:
self.tp_cooldown -= 2
print('teleportation cooldown : '+ str(self.tp_cooldown))
4 years ago
keys = pygame.key.get_pressed()
if keys[pygame.K_d] and self.tp_cooldown == 0:
self.y -= 64
self.tp_cooldown = 100