-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgun.py
More file actions
62 lines (46 loc) · 1.92 KB
/
gun.py
File metadata and controls
62 lines (46 loc) · 1.92 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import time
import pygame
class Gun:
def __init__(self, screen):
self.screen = screen
self.image = pygame.image.load("icons/baseshipa.ico")
self.rect = self.image.get_rect()
self.screen_rect = screen.get_rect()
self.rect.centerx = self.screen_rect.centerx
self.center = float(self.rect.centerx)
self.rect.bottom = self.screen_rect.bottom
self.move_right = False
self.move_left = False
self.machine_gun = False
self.machine_gun_timer = 0
self.invincibility = False
self.invincibility_timer = 0
self.freeze = False
self.freeze_timer = 0
def print(self):
self.screen.blit(self.image, self.rect)
def start(self):
self.center = self.screen_rect.centerx
def activate_machine_gun(self):
self.machine_gun = True
self.machine_gun_timer = time.time()
def activate_invincibility(self):
self.invincibility = True
self.invincibility_timer = time.time()
def activate_freeze(self):
self.freeze = True
self.freeze_timer = time.time()
def update(self):
if self.move_right and self.rect.right < self.screen_rect.right:
self.center += 5
if self.move_left and self.rect.left > self.screen_rect.left:
self.center -= 5
self.rect.centerx = self.center
self.check_time_superpower(self.machine_gun, self.machine_gun_timer, 5)
self.check_time_superpower(self.invincibility, self.invincibility_timer, 5)
self.check_time_superpower(self.freeze, self.freeze_timer, 5)
def check_time_superpower(self, superpower, current_time, superpower_time):
if superpower and time.time() - current_time > superpower_time:
self.machine_gun = False
self.invincibility = False
self.freeze = False