-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEntityTreasure.py
More file actions
114 lines (90 loc) · 3.28 KB
/
EntityTreasure.py
File metadata and controls
114 lines (90 loc) · 3.28 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import Entity
import pygame
import Tile
import Keyboard
import random
import Client
import gui
import copy
class EntityTreasure(Entity.Entity):
def __init__(self,level, x, y,value,image=None):
super(EntityTreasure,self).__init__(level,x,y)
self.value = value
self.decrition = "Some treasure"
self.basicFont = pygame.font.SysFont(None, 32)
self.image = image
self.blocksPath = False
try:
self.image = pygame.transform.scale(self.image, (32, 32))
except:
print "nope!",self.image
print self.x,self.y
def setDescription(self,desc):
self.description = description
def setValue(self,value):
self.value = value
"""Determins if the entity has collided
@Params:
None
@Return:
hasCollided(boolean): if the entity has collided
"""
def hasCollided(self,xa, ya):
xMin = -1
xMax = 33
yMin = -1
yMax = 33
if self.isSolidTile(xa, ya, xMin, yMin):
return True
if self.isSolidTile(xa, ya, xMin+2, yMin):
return True
if self.isSolidTile(xa, ya, xMin+2, yMin+2):
return True
if self.isSolidTile(xa, ya, xMax, yMin):
return True
if self.isSolidTile(xa, ya, xMax-2, yMin):
return True
if self.isSolidTile(xa, ya, xMax-2, yMin+2):
return True
if self.isSolidTile(xa, ya, xMax, yMax):
return True
if self.isSolidTile(xa, ya, xMax-2, yMax):
return True
if self.isSolidTile(xa, ya, xMax-2, yMax-2):
return True
if self.isSolidTile(xa, ya, xMin, yMax):
return True
if self.isSolidTile(xa, ya, xMin+2, yMax):
return True
if self.isSolidTile(xa, ya, xMin+2, yMax-2):
return True
return False
"""Updates logic associated with entity
@Params:
None
@Retrun:
None
"""
def tick(self):
super(EntityTreasure,self).tick()
self.hasCollided(0,0)
if self.entityCollidedWith!=None:
if self.entityCollidedWith.canPickUpTreasure==True:
self.entityCollidedWith.inHand = self
self.level.entities.remove(self)
self.entityCollidedWith = None
"""Renders the entity to the screen
@Params:
screen(pygame.Surface): suface to draw to
xoff(int): x offset of screen
yoff(int): y offset of screen
@Return:
None
"""
def render(self,screen,xoff,yoff):
if self.image!=None:
screen.blit(self.image, (self.x-xoff,self.y-yoff))
else:
text = self.basicFont.render(str(self.value), True, (0,0,0))
textpos = text.get_rect(center=(self.x-xoff,self.y-yoff))
screen.blit(text, textpos)