-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickup.py
62 lines (45 loc) · 2.1 KB
/
pickup.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
# pickup.py: Defines the pickups, these are special types off tiles which will act in certain ways until they have been picked upp and afterwards reverting to just a piece of floor. All effects are set by the instances of pickups by themselves (game core does nothing in this case)
# Author: Niklas Hedlund
from tile import Floor
from weapon import *
from config import *
from pygame import image, draw, rect
import os
class Pickup(Floor):
def __init__(self, location, tileTextures, groundImage):
Floor.__init__(self, location, tileTextures)
self.groundImage = groundImage
self.glowImage = image.load(os.path.join(GRAPHICPATH, "pickup_glow.png"))
self.used = False
def draw(self, screen, game, numTicks = 0):
Floor.draw(self, screen, game, numTicks)
if not self.used:
#Draw the pickup image on top of tile image
rect = self.getRectScreen(game)
screen.blit(self.glowImage, Rect(rect.topleft, (32,32)))
screen.blit(self.groundImage, rect)
#draw.circle(screen, (0, 0, 150), rect.center, int(rect.width * 0.6), 1)
def onCollision(self, game, isPlayer):
if not isPlayer or self.used:
return False
return self.onPickup(game)
def onPickup(self, game):
return False
class WeaponPickup(Pickup):
def __init__(self, location, tileTextures, weaponObj):
Pickup.__init__(self, location, tileTextures, weaponObj.groundImage)
self.weaponObj = weaponObj
def onPickup(self, game):
game.player.weapons.insert(0, self.weaponObj)
self.used = True
return False
class HealthPickup(Pickup):
def __init__(self, location, tileTextures):
groundImage = image.load(os.path.join(GRAPHICPATH, "health_pickup.png"))
Pickup.__init__(self, location, tileTextures, groundImage)
def onPickup(self, game):
game.player.health += 2.5
if game.player.health > game.player.maxHealth:
game.player.health = game.player.maxHealth
self.used = True
return False