-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtopview_objects.py
210 lines (178 loc) · 7.7 KB
/
topview_objects.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# -*- coding: utf-8 -*-
#================================================
#
# Dummy Objects for the Top-View Example (please execute topview_example.py)
#
# Copyright (C) 2010 Wil Alvarez <[email protected]>
#
#===================================================
import pygame
from ngine import objects
from ngine.resources import tools
# A class that represent a little square box on screen
class Tux(objects.Actor):
def __init__(self, res, pos, group):
objects.Actor.__init__(self, group)
self.res = res
ckey = (0,255, 0)
orig = self.res.image.get('tux')
self.front_array = [
tools.get_image_at(orig, 0, 64, 32, 32, ckey),
tools.get_image_at(orig, 32, 64, 32, 32, ckey),
tools.get_image_at(orig, 64, 64, 32, 32, ckey),
]
self.back_array = [
tools.get_image_at(orig, 0, 96, 32, 32, ckey),
tools.get_image_at(orig, 32, 96, 32, 32, ckey),
tools.get_image_at(orig, 64, 96, 32, 32, ckey),
]
self.right_array = [
tools.get_image_at(orig, 32, 0, 32, 32, ckey),
tools.get_image_at(orig, 64, 0, 32, 32, ckey),
tools.get_image_at(orig, 96, 0, 32, 32, ckey),
]
self.left_array = [
tools.get_image_at(orig, 32, 32, 32, 32, ckey),
tools.get_image_at(orig, 64, 32, 32, 32, ckey),
tools.get_image_at(orig, 96, 32, 32, 32, ckey),
]
self.front_image = tools.get_image_at(orig, 0, 64, 32, 32, ckey)
self.back_image = tools.get_image_at(orig, 0, 96, 32, 32, ckey)
self.right_image = tools.get_image_at(orig, 0, 0, 32, 32, ckey)
self.left_image = tools.get_image_at(orig, 128, 32, 32, 32, ckey)
self.xspeed = 2.5
self.yspeed = 2.5
self.anim_delay = 8
self.set_image(self.front_image, pos)
self.set_relative_rect()
self.set_array(self.front_array)
def on_move(self, xdir, ydir):
if xdir < 0:
self.set_array(self.left_array)
elif xdir > 0:
self.set_array(self.right_array)
elif ydir < 0:
self.set_array(self.back_array)
elif ydir > 0:
self.set_array(self.front_array)
def update(self):
if self.xdir == 0 and self.ydir == 0:
if self.last_xdir < 0:
self.image = self.left_image
elif self.last_xdir > 0:
self.image = self.right_image
elif self.last_ydir < 0:
self.image = self.back_image
elif self.last_ydir > 0:
self.image = self.front_image
self.xdir = 0
self.ydir = 0
# A class that represent a little square box on screen
class DeadBox(objects.SpriteObject):
def __init__(self, pos):
objects.SpriteObject.__init__(self)
image = pygame.Surface((32, 32))
image.fill((0,0,255))
self.set_image(image, pos)
# A class that represent a little square box on screen
class ItemBox(objects.SpriteObject):
def __init__(self, pos):
objects.SpriteObject.__init__(self)
image = pygame.Surface((32, 32))
image.fill((90,20,100))
self.set_image(image, pos)
# A class that represent a little square box on screen
class Block(objects.SpriteObject, objects.UnwalkableObject):
def __init__(self, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
image = pygame.Surface((32, 32))
image.fill((255,255,0))
self.set_image(image, pos)
self.set_relative_rect()
class Tree(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, res, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
orig = self.res.image.get('map')
image = tools.get_image_at(orig, 0, 256, 32, 32)
self.set_image(image, pos)
self.set_relative_rect()
class WaterWell(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, res, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
orig = self.res.image.get('map')
image = tools.get_image_at(orig, 0, 32, 32, 32)
self.set_image(image, pos)
self.set_relative_rect()
class Gravestone(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, res, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
orig = self.res.image.get('map')
image = tools.get_image_at(orig, 32, 256, 32, 32)
self.set_image(image, pos)
self.set_relative_rect()
class CrossGravestone(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, res, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
orig = self.res.image.get('map')
image = tools.get_image_at(orig, 64, 256, 32, 32)
self.set_image(image, pos)
self.set_relative_rect()
class Fence(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, t_id, res, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
orig = self.res.image.get('map')
if t_id == '17':
image = tools.get_image_at(orig, 0, 64, 32, 32)
elif t_id == '19':
image = tools.get_image_at(orig, 64, 64, 32, 32)
elif t_id == '18':
image = tools.get_image_at(orig, 32, 64, 32, 32)
elif t_id == '33':
image = tools.get_image_at(orig, 0, 128, 32, 32)
elif t_id == '34':
image = tools.get_image_at(orig, 32, 128, 32, 32)
elif t_id == '35':
image = tools.get_image_at(orig, 64, 128, 32, 32)
elif t_id == '25':
image = tools.get_image_at(orig, 0, 96, 32, 32)
self.set_image(image, pos)
if t_id == '34':
self.set_relative_rect(32, 20, top=self.rect.top + 6)
elif t_id == '25':
self.set_relative_rect(14, 32, left=self.rect.left + 2)
else:
self.set_relative_rect()
class Coin(objects.SpriteObject, objects.CollidableObject):
def __init__(self, res, pos):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
self.anim_delay = 5
ckey = (0, 255, 0)
orig = res.image.get('coin32')
array = [
tools.get_image_at(orig, 0, 0, 32, 32, ckey),
tools.get_image_at(orig, 32, 0, 32, 32, ckey),
tools.get_image_at(orig, 64, 0, 32, 32, ckey),
tools.get_image_at(orig, 96, 0, 32, 32, ckey),
]
self.set_image(array[0], pos)
self.set_relative_rect()
self.set_array(array)
def update(self):
self.next_image()