/
herof.py
executable file
·70 lines (55 loc) · 2.04 KB
/
herof.py
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
63
64
65
66
67
68
69
70
import globalvars
import pygame
import invade
import weapons
from pygame.locals import *
god = False
#god = True
class Hero(pygame.sprite.Sprite):
""" Hero() - The hero class is the player's object. """
def __init__(self, pos):
#self.color = (255, 150, 0)
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((32, 32))
self.image = pygame.image.load_basic("img/ship.bmp")
self.image.set_colorkey((255,255,255), RLEACCEL)
self.max_hp = 3
self.cur_hp = self.max_hp
self.gun = weapons.single_gun
self.rect = self.image.get_rect()
self.rect.topleft = pos
self.speed = 3
self.vx = 0
self.vy = 0
self.next_shoot = 0
self.shoot_delay = 300
if god:
self.shoot_delay = 0
self.alive = True
self.next_update = 0
def update(self, t):
if t > self.next_update:
self.rect.top += self.vy
self.rect.left += self.vx
if self.rect.top < 0:
self.rect.top = 0
if self.rect.left < 0:
self.rect.left = 0
if self.rect.right > globalvars.WIDTH:
self.rect.right = globalvars.WIDTH
if self.rect.bottom > globalvars.HEIGHT:
self.rect.bottom = globalvars.HEIGHT
self.next_update = t + 15
def shoot(self):
""" Hero.shoot():
this function returns two bullets, which will be added to the hero_bullet_grp in the main loop """
if self.alive == False:
return
invade.play_sound("sound/laser.wav")
return (self.gun(self.rect))
def give_hp(self, val):
print "before", self.cur_hp
if self.cur_hp < self.max_hp:
self.cur_hp += val
globalvars.hp.set_meter(self.cur_hp, self.max_hp)
print "after", self.cur_hp