forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 48
/
item.py
68 lines (56 loc) · 2.25 KB
/
item.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
import pygame as pg
from pygame.sprite import *
class Item(Sprite):
"""A class to manage speed item droped from the alien"""
def __init__(self, setting, screen, stats, type, posx, posy):
"""Create a item object at the aliens current position"""
super(Item, self).__init__()
self.screen = screen
self.stats = stats
# add item types if you want
if type == 1.1:
self.image = pg.image.load('gfx/heal 1.png')
elif type == 1.2:
self.image = pg.image.load('gfx/heal 2.png')
elif type == 1.3:
self.image = pg.image.load('gfx/heal 3.png')
elif type == 2.1:
self.image = pg.image.load('gfx/time 1.png')
elif type == 2.2:
self.image = pg.image.load('gfx/time 2.png')
elif type == 2.3:
self.image = pg.image.load('gfx/time 3.png')
elif type == 3.1:
self.image = pg.image.load('gfx/shield 1.png')
elif type == 3.2:
self.image = pg.image.load('gfx/shield2.png')
elif type == 3.3:
self.image = pg.image.load('gfx/shield 3.png')
elif type == 4.1:
self.image = pg.image.load('gfx/speed 1.png')
elif type == 4.2:
self.image = pg.image.load('gfx/speed 2.png')
elif type == 4.3:
self.image = pg.image.load('gfx/speed 3.png')
self.type = type
self.rect = self.image.get_rect()
# Create a collision mask
self.mask = pg.mask.from_surface(self.image)
# Create a items rect at (0,0)+-5
##self.rect = pg.Rect(0, 0, setting.bulletWidth, setting.bulletHeight)
self.rect.x = posx
self.rect.y = posy
# store the item position as a decimal value
self.y = float(self.rect.y)
self.itemSpeed = setting.bulletSpeed * 0.3
def update(self):
"""Move the item -y up the screen"""
# update the decimal position of the item
if not self.stats.paused:
self.y += self.itemSpeed
# Update the rect position
self.rect.y = self.y
def drawitem(self):
"""Draw the item to the screen"""
# pg.draw.rect(self.screen, self.color, self.rect)
self.screen.blit(self.image, self.rect)