-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayable.py
More file actions
48 lines (39 loc) · 1.41 KB
/
Playable.py
File metadata and controls
48 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time
import pygame
import pyautogui
from random import uniform as rand
from Bullet import Bullet
from Identity import Identity
class Playable(Identity):
def __init__(self, x, y, ammoDir: int):
super().__init__(x, y)
self.nextShoot = time.time() + 0.5
self.ammoDirection = ammoDir
self.lastId = 0
def shoot(self):
if time.time() < self.nextShoot:
return
self.nextShoot = time.time()+rand(1, 2.5)
return Bullet(self.x+self.width/2,self.y, self.ammoDirection, 0)
def runFunction(self, screen, enemys):
if self.health > 0:
self.draw(screen)
if len(enemys) != 0:
self.move()
return self.shoot()
def run(self, screen, enemys):
return self.runFunction(screen, enemys)
def move(self):
if time.time() >= self.nextMove:
maxX, maxY = pyautogui.size()
self.nextMove = time.time() + 0.05
if self.x+self.xDeslocation >= maxX or self.x+self.xDeslocation <= 0:
self.xDeslocation*=-1
self.x+=self.xDeslocation
if self.y+self.yDeslocation >= maxY or self.y+self.yDeslocation <= 0:
self.yDeslocation*=-1
self.y+=self.yDeslocation
if self.y < 0:
self.y = 0
elif self.y > maxY-self.height:
self.y = maxY-self.height