22 self
.clock
= pygame
.time
.Clock ()
23 self
.screen
= pygame
.display
.set_mode ((720, 512))
24 pygame
.display
.set_caption ("The Adventures of Butaba")
26 # initalize background graphics
27 self
.img_tileset
= pygame
.image
.load (os
.path
.join ("background", "tileset.png")).convert ()
29 self
.img_menu
= pygame
.image
.load (os
.path
.join ("background", "menu_screen.png")).convert ()
31 self
.img_inventory
= pygame
.image
.load (os
.path
.join ("background", "inventory.png")).convert ()
33 self
.img_chestbg
= pygame
.image
.load (os
.path
.join ("background", "chestcontent.png")).convert ()
35 self
.img_dialogue
= pygame
.image
.load (os
.path
.join ("background", "dialog_screen.png")).convert ()
36 self
.img_dialogue
.set_colorkey (pygame
.Color (0, 255, 0))
39 # initialize object graphics
40 self
.img_redpotion
= pygame
.image
.load (os
.path
.join ("objects", "red-potion.png")).convert ()
41 self
.img_redpotion
.set_colorkey (pygame
.Color (0, 255, 0))
42 self
.img_goldcoins
= pygame
.image
.load (os
.path
.join ("objects", "gold-coins.png")).convert ()
43 self
.img_goldcoins
.set_colorkey (pygame
.Color (0, 255, 0))
44 self
.img_wand
= pygame
.image
.load (os
.path
.join ("objects", "wand.png")).convert ()
45 self
.img_wand
.set_colorkey (pygame
.Color (0, 255, 0))
46 self
.img_bulb
= pygame
.image
.load (os
.path
.join ("objects", "bulb.png")).convert ()
47 self
.img_bulb
.set_colorkey (pygame
.Color (0, 255, 0))
48 self
.img_lightning
= pygame
.image
.load (os
.path
.join ("objects", "lightning.png")).convert ()
49 self
.img_lightning
.set_colorkey (pygame
.Color (0, 255, 0))
50 self
.img_key
= pygame
.image
.load (os
.path
.join ("objects", "key.png")).convert ()
51 self
.img_key
.set_colorkey (pygame
.Color (0, 255, 0))
52 self
.img_key2
= pygame
.image
.load (os
.path
.join ("objects", "key2.png")).convert ()
53 self
.img_key2
.set_colorkey (pygame
.Color (0, 255, 0))
54 self
.img_chest
= pygame
.image
.load (os
.path
.join ("objects", "chest.png")).convert ()
55 self
.img_chest
.set_colorkey (pygame
.Color (0, 255, 0))
56 self
.img_bucket
= pygame
.image
.load (os
.path
.join ("objects", "bucket.png")).convert ()
57 self
.img_bucket
.set_colorkey (pygame
.Color (0, 255, 0))
59 # initialize player graphics
60 self
.img_butabafront
= pygame
.image
.load (os
.path
.join ("sprite", "butaba-front.png")).convert ()
61 self
.img_butabafront
.set_colorkey (pygame
.Color (0, 255, 0))
62 self
.img_butababack
= pygame
.image
.load (os
.path
.join ("sprite", "butaba-back.png")).convert ()
63 self
.img_butababack
.set_colorkey (pygame
.Color (0, 255, 0))
64 self
.img_butabaleft
= pygame
.image
.load (os
.path
.join ("sprite", "butaba-left.png")).convert ()
65 self
.img_butabaleft
.set_colorkey (pygame
.Color (0, 255, 0))
66 self
.img_butabaright
= pygame
.image
.load (os
.path
.join ("sprite", "butaba-right.png")).convert ()
67 self
.img_butabaright
.set_colorkey (pygame
.Color (0, 255, 0))
69 # initialize NPC graphics
70 self
.img_bulisafront
= pygame
.image
.load (os
.path
.join ("sprite", "bulisa-front.png")).convert ()
71 self
.img_bulisafront
.set_colorkey (pygame
.Color (0, 255, 0))
73 self
.img_bulisaback
= pygame
.image
.load (os
.path
.join ("sprite", "bulisa-back.png")).convert ()
74 self
.img_bulisaback
.set_colorkey (pygame
.Color (0, 255, 0))
76 self
.img_bulisaleft
= pygame
.image
.load (os
.path
.join ("sprite", "bulisa-left.png")).convert ()
77 self
.img_bulisaleft
.set_colorkey (pygame
.Color (0, 255, 0))
79 self
.img_bulisaright
= pygame
.image
.load (os
.path
.join ("sprite", "bulisa-right.png")).convert ()
80 self
.img_bulisaright
.set_colorkey (pygame
.Color (0, 255, 0))
82 # initialize portraits
83 self
.img_butaba_portrait
= pygame
.image
.load (os
.path
.join ("portraits", "butaba.png")).convert ()
84 self
.img_bulisa_portrait
= pygame
.image
.load (os
.path
.join ("portraits", "bulisa.png")).convert ()
88 # set current level and position of our character
89 self
.currentlevel
= self
.level1
91 # set the status message
92 self
.status_message
= "Game started"
94 self
.butaba
= butaba
.Butaba (5,0, self
.img_butabaleft
,
95 self
.img_butabaright
, self
.img_butabafront
,
96 self
.img_butababack
, self
.img_butaba_portrait
, constants
.RIGHT
)
98 # set up the levels and their interactions
99 def setup_levels (self
):
100 # set up the objects first
101 chest1
= gameobjects
.Chest (2, 6, "chest", self
.img_chest
, constants
.KEY_CHEST1
, True)
102 chest2
= gameobjects
.Chest (6, 6, "chest", self
.img_chest
, constants
.KEY_CHEST2
, True)
103 key2
= gameobjects
.Key (5, 3, "a chest key", self
.img_key
, constants
.KEY_CHEST2
)
104 potion
= gameobjects
.HealthPotion (5, 2, self
.img_redpotion
)
105 gold50
= gameobjects
.GoldCoins (6, 2, self
.img_goldcoins
, 50)
106 gold25
= gameobjects
.GoldCoins (6, 2, self
.img_goldcoins
, 25)
107 gold10
= gameobjects
.GoldCoins (6, 2, self
.img_goldcoins
, 10)
108 bucket
= gameobjects
.Bucket (6, 3, self
.img_bucket
)
110 well1
= gameobjects
.Well (4, 7)
111 well2
= gameobjects
.Well (5, 7)
112 well3
= gameobjects
.Well (4, 8)
113 well4
= gameobjects
.Well (5, 8)
115 npc_bulisa
= npcs
.Bulisa (4, 3, self
.img_bulisaleft
, self
.img_bulisaright
,
116 self
.img_bulisafront
, self
.img_bulisaback
,
117 self
.img_bulisa_portrait
, constants
.FRONT
,
119 [ os
.path
.join ("dialogues", "bulisa1.dlg"),
120 os
.path
.join ("dialogues", "bulisa2.dlg"),
121 os
.path
.join ("dialogues", "bulisa3.dlg"),
122 os
.path
.join ("dialogues", "bulisa4.dlg") ] )
124 chest1
.objects
= [ gold50
, gold25
, key2
, gold10
]
127 self
.level1
= level
.Level (cPickle
.load (file (os
.path
.join ("levels", "level1.dat"))),
128 objects
= [ chest1
] )
130 self
.level1w
= level
.Level (cPickle
.load (file (os
.path
.join ("levels", "level1w.dat"))))
132 self
.level1e
= level
.Level (cPickle
.load (file (os
.path
.join ("levels", "level1e.dat"))),
133 objects
= [ potion
, chest2
], npcs
= [ npc_bulisa
])
135 self
.level1ee
= level
.Level (cPickle
.load (file (os
.path
.join ("levels", "level1ee.dat"))),
136 objects
= [ well1
, well2
, well3
, well4
])
138 self
.level1n
= level
.Level (cPickle
.load (file (os
.path
.join ("levels", "level1n.dat"))),
139 objects
= [ bucket
])
141 # set up the interaction between levels
142 self
.level1
.levelright
= self
.level1e
143 self
.level1
.levelleft
= self
.level1w
144 self
.level1e
.levelleft
= self
.level1
145 self
.level1e
.levelright
= self
.level1ee
146 self
.level1ee
.levelleft
= self
.level1e
147 self
.level1w
.levelright
= self
.level1
148 self
.level1
.leveltop
= self
.level1n
149 self
.level1n
.levelbottom
= self
.level1
151 def main_loop (self
):
156 self
.screen
.fill (pygame
.Color (0,0,0))
158 self
.draw_level_background (self
.currentlevel
)
160 self
.draw_level_objects (self
.currentlevel
)
161 # draw the NPCs in the level
162 self
.draw_level_npcs (self
.currentlevel
)
165 # display the character's inventory
166 self
.draw_inventory ()
167 # draw the status info
170 pygame
.display
.update ()
172 # get keyboard events
173 for event
in pygame
.event
.get ():
174 if event
.type == pygame
.QUIT
:
177 if event
.type == pygame
.KEYDOWN
:
178 if event
.key
== pygame
.K_UP
:
179 self
.move_butaba_up ()
180 elif event
.key
== pygame
.K_DOWN
:
181 self
.move_butaba_down ()
182 elif event
.key
== pygame
.K_LEFT
:
183 self
.move_butaba_left ()
184 elif event
.key
== pygame
.K_RIGHT
:
185 self
.move_butaba_right ()
186 # drinking health potion in inventory
187 elif event
.key
== ord ("h") or event
.key
== ord ("H"):
188 self
.inventory_drink_health_potion ()
190 elif event
.key
== ord ("q") or event
.key
== ord ("Q"):
193 # drink a health potion if it is in the player's inventory
194 def inventory_drink_health_potion (self
):
195 # look for a health potion
196 for item
in self
.butaba
.objects
:
197 if isinstance (item
, gameobjects
.HealthPotion
) is True:
198 self
.use_object (self
.butaba
, item
)
201 def move_butaba_up (self
):
202 # clear any status messages
203 self
.status_message
= None
204 # first if butaba is not facing up, make him face up
205 if self
.butaba
.position
<> constants
.BACK
:
206 self
.butaba
.position
= constants
.BACK
209 # if butaba is trying to move off the top of the screen
210 if self
.butaba
.row
<= 0:
211 # if there is a level above set current level to that one
212 if self
.currentlevel
.leveltop
is not None:
213 lastrow
= len (self
.currentlevel
.leveltop
.background
) - 1
214 # interact with objects
215 if self
.level_interact (self
.currentlevel
.leveltop
, lastrow
, self
.butaba
.col
) is False:
218 # make sure there is no obstacle
219 if self
.check_background_obstacle (self
.currentlevel
.leveltop
, lastrow
, self
.butaba
.col
) is False:
220 self
.currentlevel
= self
.currentlevel
.leveltop
221 self
.butaba
.row
= lastrow
222 # normal upward movement
224 # if there is any object in that place interact with it
225 # if any object is a blocking object then avoid movement
226 if self
.level_interact (self
.currentlevel
, self
.butaba
.row
-1, self
.butaba
.col
) is False:
229 if self
.check_background_obstacle (self
.currentlevel
, self
.butaba
.row
-1, self
.butaba
.col
) is False:
232 def move_butaba_down (self
):
233 # clear any status messages
234 self
.status_message
= None
235 # first if butaba is not facing forward, make him face forward/down
236 if self
.butaba
.position
<> constants
.FRONT
:
237 self
.butaba
.position
= constants
.FRONT
240 # if butaba is trying to move off the bottom of the screen
241 if self
.butaba
.row
>= len (self
.currentlevel
.background
)-1:
242 # if there is a level below set current level to that one
243 if self
.currentlevel
.levelbottom
is not None:
244 # interact with objects if any
245 # if any object is a blocking object then avoid movement
246 if self
.level_interact (self
.currentlevel
.levelbottom
, 0, self
.butaba
.col
) is False:
248 # make sure there is no obstacle at that position
249 if self
.check_background_obstacle (self
.currentlevel
.levelbottom
, 0, self
.butaba
.col
) is False:
250 self
.currentlevel
= self
.currentlevel
.levelbottom
252 # normal downward movement
254 # interact with objects if any
255 # if any object is a blocking object then avoid movement
256 if self
.level_interact (self
.currentlevel
, self
.butaba
.row
+1, self
.butaba
.col
) is False:
258 if self
.check_background_obstacle (self
.currentlevel
, self
.butaba
.row
+1, self
.butaba
.col
) is False:
261 # check if a background tile is an obstacle
262 def check_background_obstacle (self
, level
, row
, col
):
263 if (level
.background
[row
][col
][2] == 1):
268 # get and interact with objects and characters if present in a particular row/col
269 def level_interact (self
, level
, row
, col
):
271 # get list of objects at current location
272 for obj
in level
.objects
:
273 if obj
.row
== row
and obj
.col
== col
:
276 notblock
= self
.interact_objects (level
, objs
)
278 # get npc at current location
280 for npc
in level
.npcs
:
281 if npc
.row
== row
and npc
.col
== col
:
285 # npcs always block the tile. So return false if there is an NPC
287 if current_npc
is not None:
288 self
.interact_npc (current_npc
)
293 # interaction with npcs
294 def interact_npc (self
, npc
):
295 # interact with NPC and get the response ID
296 # if the NPC is Bulisa
298 # if the NPC is dead cannot talk with the NPC
299 if npc
.is_dead
is True:
300 self
.status_message
= "%s is dead! RIP..." % npc
.charname
303 if isinstance (npc
, npcs
.Bulisa
):
305 self
.interact_npc_bulisa (npc
)
307 # interact with NPC Bulisa
308 def interact_npc_bulisa (self
, npc
):
309 # set initial response ID to none
311 # not yet started mission drawing water from well and not refused it
312 if (gamestate
.mission_bulisa_water_from_well
is False
313 and gamestate
.mission_bulisa_water_from_well_refused
is False):
314 # set the current dialogue
315 npc
.currentdialog
= 0
316 # get the response ID
317 resp_id
= utility
.dialogue_play (self
.screen
, self
.img_dialogue
, npc
, self
.butaba
.portrait
, 0, 90)
318 if (gamestate
.mission_bulisa_water_from_well_refused
is True and
319 gamestate
.mission_bulisa_water_from_well
is False):
320 # set the current dialog
321 npc
.currentdialog
= 2
322 resp_id
= utility
.dialogue_play (self
.screen
, self
.img_dialogue
, npc
, self
.butaba
.portrait
, 0, 90)
323 # mission accepted but not completed - check if completed and set value
325 elif (gamestate
.mission_bulisa_water_from_well
is True
326 and gamestate
.mission_bulisa_water_from_well_complete
is False):
327 for invobj
in self
.butaba
.objects
:
328 if isinstance (invobj
, gameobjects
.Bucket
) is True:
329 if invobj
.liquid
== "water":
330 gamestate
.mission_bulisa_water_from_well_complete
= True
331 self
.butaba
.objects
.remove (invobj
)
332 key1
= gameobjects
.Key (5, 3, "a chest key", self
.img_key2
, constants
.KEY_CHEST1
)
333 self
.butaba
.objects
.append (key1
)
336 # water mission is not completed yet
337 if gamestate
.mission_bulisa_water_from_well_complete
is False:
338 npc
.currentdialog
= 1
340 npc
.currentdialog
= 3
342 # get the response ID
343 resp_id
= utility
.dialogue_play (self
.screen
, self
.img_dialogue
, npc
, self
.butaba
.portrait
, 0, 90)
345 # if response ID is 12, then drawing water from well mission is refused
346 if resp_id
== "12" or resp_id
== "18":
347 gamestate
.mission_bulisa_water_from_well_refused
= True
348 # if response ID is 13: that is accepted the drawing water from well mission begins
349 if resp_id
== "13" or resp_id
== "17":
350 gamestate
.mission_bulisa_water_from_well
= True
351 # if response ID is none
352 elif resp_id
is None:
353 self
.status_message
= "You cannot initiate a conversation with %s" % npc
.charname
355 # interaction with objects
356 def interact_objects (self
, container
, objs
):
357 # overall flag for blocking/non-blocking objects
360 # now perform interaction
362 # run the object interact function
363 if obj
.interact () is False:
365 # if object can be picked up ask
366 if obj
.can_pickup
is True:
367 ans
= utility
.ask_question (self
.screen
, "Found %s." % obj
.text
, ["Pick up", obj
.use_str
, "Ignore"], self
.img_menu
)
368 # if the answer is "pick up"
370 self
.pickup_object (container
, obj
)
372 # use the object according to its type
373 self
.use_object (container
, obj
)
374 # if it cannot be picked up, try to use it anyway
376 ans
= utility
.ask_question (self
.screen
, "Found %s." % obj
.text
, [obj
.use_str
, "Ignore"], self
.img_menu
)
378 self
.use_object (container
, obj
)
382 # transfer an object from one container to another
383 # container must have an objects list
384 def transfer_object (self
, source
, obj
, dest
):
385 # remove object from source
386 source
.objects
.remove (obj
)
387 # add object to destination
388 dest
.objects
.append (obj
)
390 # picking up an object
391 def pickup_object (self
, container
, obj
):
392 # only if object can be picked up, pick it up or use it
393 if obj
.can_pickup
is True:
394 # check if the inventory is full
395 if len (self
.butaba
.objects
) >= constants
.MAXITEMS
:
396 self
.status_message
= "Cannot pick up item. Inventory full"
398 # add item to inventory
399 self
.transfer_object (container
, obj
, self
.butaba
)
401 self
.status_message
= "You picked up %s" % obj
.text
403 # this method uses the object first by calling the object use () method
404 # and then performing specific actions as necessary
405 def use_object (self
, container
, obj
):
406 # if the object is a health potion
407 if isinstance (obj
, gameobjects
.HealthPotion
) is True:
408 if self
.butaba
.health
< constants
.MAXHEALTH
:
409 obj
.use (self
.butaba
)
410 container
.objects
.remove (obj
)
411 self
.status_message
= "You gained health"
413 self
.status_message
= "You already have maximum health!"
414 # if the object is a chest
415 elif isinstance (obj
, gameobjects
.Chest
) is True:
416 # if chest is locked, try to open it
417 if obj
.locked
is True:
418 # try opening the chest with every item 9the use () function
419 # of the chest determines if item is a key anyway
421 for invobj
in self
.butaba
.objects
:
422 fittedkey
= obj
.use (invobj
)
424 if fittedkey
is not None:
427 if fittedkey
is None:
428 self
.status_message
= "No key found to open %s" % obj
.text
429 # chest successfully unlocked
431 self
.status_message
= "You unlocked the %s" % obj
.text
432 # remove the key from Butaba
433 self
.butaba
.objects
.remove (fittedkey
)
434 # add an experience point for unlocking chest subject
435 # to a limit of KNOWLEDGEMAX_CHEST_UNLOCK
436 if self
.butaba
.experience
< constants
.KNOWLEDGEMAX_CHEST_UNLOCK
:
437 self
.butaba
.experience
+= 1
438 self
.status_message
+= " and gained experience!"
439 # display the contents of the chest
441 item
= utility
.get_container_object (self
.screen
, obj
, self
.img_chestbg
, 30)
443 self
.interact_objects (obj
, [ item
, ])
445 # if the object is gold coins
446 elif isinstance (obj
, gameobjects
.GoldCoins
) is True:
447 obj
.use (self
.butaba
)
448 self
.status_message
= "You picked up %d gold." % obj
.value
449 # remove the gold coins after adding it to Butaba's gold
450 container
.objects
.remove (obj
)
451 # using a bucket means emptying it
452 elif isinstance (obj
, gameobjects
.Bucket
) is True:
453 if obj
.liquid
is not None:
454 self
.status_message
= "You emptied the bucket of %s" % obj
.liquid
455 obj
.use (self
.butaba
)
457 self
.status_message
= "Bucket is already empty."
459 elif isinstance (obj
, gameobjects
.Well
) is True:
460 # if the well is not dry, i.e. it has some liquid
461 if obj
.liquid
is not None:
462 # search butaba inventory for an empty bucket
463 for invobj
in self
.butaba
.objects
:
464 # bucket found, now check if it is empty
465 if isinstance (invobj
, gameobjects
.Bucket
) is True:
467 if invobj
.liquid
is None:
469 self
.status_message
= "You successfully filled the %s with %s" % (invobj
.text
, obj
.liquid
)
470 if self
.butaba
.strength
< constants
.STRENGTHMAX_DRAW_WELL_WATER
:
471 self
.butaba
.strength
+= 2
472 self
.status_message
+= " and gained strength!"
474 self
.status_message
= "You have no empty bucket to draw %s with!" % obj
.liquid
476 self
.status_message
= "%s appears to be dry!" % obj
.text
478 def move_butaba_left (self
):
479 # clear any status messages
480 self
.status_message
= None
482 # first if Butaba is not facing left, make him face left
483 if self
.butaba
.position
<> constants
.LEFT
:
484 self
.butaba
.position
= constants
.LEFT
487 # if butaba is trying to move off the left edge
488 if self
.butaba
.col
<= 0:
489 # if there is a level to the right set current level to that one
490 if self
.currentlevel
.levelleft
is not None:
491 # get the last column of the previous level
492 lastcol
= len (self
.currentlevel
.levelleft
.background
[0]) - 1
493 # interact with objects if any
494 # if any object is a blocking object then avoid movement
495 if self
.level_interact (self
.currentlevel
.levelleft
, self
.butaba
.row
, lastcol
) is False:
497 # make sure there is no obstacle at that position of movement
498 if self
.check_background_obstacle (self
.currentlevel
.levelleft
, self
.butaba
.row
, lastcol
) is False:
499 self
.currentlevel
= self
.currentlevel
.levelleft
500 self
.butaba
.col
= lastcol
501 # normal left movement
503 # interact with objects if any
504 # if any object is a blocking object then avoid movement
505 if self
.level_interact (self
.currentlevel
, self
.butaba
.row
, self
.butaba
.col
-1) is False:
507 if self
.check_background_obstacle (self
.currentlevel
, self
.butaba
.row
, self
.butaba
.col
-1) is False:
510 def move_butaba_right (self
):
511 # clear any status messages
512 self
.status_message
= None
514 # First if Butaba is not facing right make him face right
515 if self
.butaba
.position
<> constants
.RIGHT
:
516 self
.butaba
.position
= constants
.RIGHT
519 # if butaba is trying to move off the right edge
520 if self
.butaba
.col
>= len (self
.currentlevel
.background
[0])-1:
521 # if there is a level to the right swap current level with that one
522 if self
.currentlevel
.levelright
is not None:
523 # interact with objects if any
524 # if any object is a blocking object then avoid movement
525 if self
.level_interact (self
.currentlevel
.levelright
, self
.butaba
.row
, 0) is False:
528 # make sure there is no obstacle at that position of movement
529 # get the last column of the previous level
530 if self
.check_background_obstacle (self
.currentlevel
.levelright
, self
.butaba
.row
, 0) is False:
531 self
.currentlevel
= self
.currentlevel
.levelright
533 # normal right movement
535 # interact with objects if any
536 # if any object is a blocking object then avoid moving
537 if self
.level_interact (self
.currentlevel
, self
.butaba
.row
, self
.butaba
.col
+ 1) is False:
539 if self
.check_background_obstacle (self
.currentlevel
, self
.butaba
.row
, self
.butaba
.col
+ 1) is False:
542 def draw_butaba (self
):
543 if self
.butaba
.position
== constants
.FRONT
:
544 self
.screen
.blit (self
.butaba
.imagefront
, (self
.butaba
.col
*48, self
.butaba
.row
*48))
545 elif self
.butaba
.position
== constants
.BACK
:
546 self
.screen
.blit (self
.butaba
.imageback
, (self
.butaba
.col
*48, self
.butaba
.row
*48))
547 elif self
.butaba
.position
== constants
.LEFT
:
548 self
.screen
.blit (self
.butaba
.imageleft
, (self
.butaba
.col
*48, self
.butaba
.row
*48))
549 elif self
.butaba
.position
== constants
.RIGHT
:
550 self
.screen
.blit (self
.butaba
.imageright
, (self
.butaba
.col
*48, self
.butaba
.row
*48))
553 # Draw the status infodisplay
554 def draw_status (self
):
555 self
.screen
.blit (self
.img_redpotion
, (485, 10))
556 utility
.put_text (self
.screen
, 550, 25, 20, (255, 0, 0), "%d" % self
.butaba
.health
)
558 self
.screen
.blit (self
.img_lightning
, (620, 10))
559 utility
.put_text (self
.screen
, 660, 25, 20, (255,255,255), "%d" % self
.butaba
.strength
)
561 self
.screen
.blit (self
.img_wand
, (485, 65))
562 utility
.put_text (self
.screen
, 550, 75, 20, (0, 0, 255), "%d" % self
.butaba
.magic
)
564 self
.screen
.blit (self
.img_bulb
, (620, 65))
565 utility
.put_text (self
.screen
, 660, 75, 20, (0, 255, 0), "%d" % self
.butaba
.experience
)
567 self
.screen
.blit (self
.img_goldcoins
, (485, 110))
568 utility
.put_text (self
.screen
, 550, 130, 20, (255, 255, 0), "%d" % self
.butaba
.gold
)
570 if self
.status_message
is not None:
571 utility
.put_text (self
.screen
, 10, 485, 10, (255,255, 0), "%s" % self
.status_message
)
573 # display the inventory of the player
574 def draw_inventory (self
):
575 # draw the inventory slots
578 utility
.put_text (self
.screen
, 490, 170, 16, (255,255 , 0), "Inventory")
579 for i
in range (constants
.MAXITEMS
):
580 self
.screen
.blit (self
.img_inventory
, (440+c
*54, 150+r
*54))
589 for obj
in self
.butaba
.objects
:
590 self
.screen
.blit (obj
.image
, (440+c
*54+2, 150+r
*54+2))
597 # Draw the level background tiles on surface
598 def draw_level_background (self
, level
):
600 for row
in level
.background
:
602 for tilerow
, tilecol
, is_solid
in row
:
605 self
.screen
.blit (self
.img_tileset
, (j
*48, i
*48), pygame
.Rect (tilex
, tiley
, 48, 48))
610 # Draw the level objects
611 def draw_level_objects (self
, level
):
612 for obj
in level
.objects
:
613 if obj
.image
is not None:
614 self
.screen
.blit (obj
.image
, (obj
.col
*48, obj
.row
*48))
617 # Draw the NPCs in the level
618 def draw_level_npcs (self
, level
):
619 for npc
in level
.npcs
:
620 # if npc is not dead then move the NPC randomly depending on their
622 if npc
.is_dead
is False:
624 if random
.randint (1, 500) < npc
.movement_speed
:
625 # whether to change direction?
626 if random
.randint (1, 100) < 25:
627 npc
.position
= random
.randint (0, 3)
630 if npc
.position
== constants
.LEFT
:
631 # cannot move beyond level and cannot move beyond the
633 if npc
.col
> 0 and npc
.col
> npc
.initcol
- npc
.leftlimit
:
634 # check if there is any background obstacle
635 if self
.check_background_obstacle (level
, npc
.row
, npc
.col
- 1) is False:
636 # check if there are any objects
639 for lobj
in level
.objects
:
640 if lobj
.row
== npc
.row
and lobj
.col
== npc
.col
- 1:
643 # check if there any any npcs blocking
644 for lnpc
in level
.npcs
:
645 if lnpc
.row
== npc
.row
and lnpc
.col
== npc
.col
- 1:
648 if objblock
is False and npcblock
is False:
649 # if butaba is not blocking
650 if self
.butaba
.row
<> npc
.row
or self
.butaba
.col
<> npc
.col
- 1:
652 elif npc
.position
== constants
.RIGHT
:
653 # cannot move beyond level and cannot move beyond the
655 if npc
.col
< 9 and npc
.col
< npc
.initcol
+ npc
.rightlimit
:
656 # check if there is any background obstacle
657 if self
.check_background_obstacle (level
, npc
.row
, npc
.col
+ 1) is False:
658 # check if there are any objects
661 for lobj
in level
.objects
:
662 if lobj
.row
== npc
.row
and lobj
.col
== npc
.col
+ 1:
665 # check if there any any npcs blocking
666 for lnpc
in level
.npcs
:
667 if lnpc
.row
== npc
.row
and lnpc
.col
== npc
.col
+ 1:
670 if objblock
is False and npcblock
is False:
671 # if butaba is not blocking
672 if self
.butaba
.row
<> npc
.row
or self
.butaba
.col
<> npc
.col
+ 1:
674 elif npc
.position
== constants
.FRONT
:
675 # cannot move beyond level and cannot move beyond the
676 # lower bottom limit area
677 if npc
.row
< 9 and npc
.row
< npc
.initrow
+ npc
.bottomlimit
:
678 # check if there is any background obstacle
679 if self
.check_background_obstacle (level
, npc
.row
+ 1, npc
.col
) is False:
680 # check if there are any objects
683 for lobj
in level
.objects
:
684 if lobj
.row
== npc
.row
+ 1 and lobj
.col
== npc
.col
:
687 # check if there any any npcs blocking
688 for lnpc
in level
.npcs
:
689 if lnpc
.row
== npc
.row
+ 1 and lnpc
.col
== npc
.col
:
692 if objblock
is False and npcblock
is False:
693 # if butaba is not blocking
694 if self
.butaba
.row
<> npc
.row
+ 1 or self
.butaba
.col
<> npc
.col
:
696 elif npc
.position
== constants
.BACK
:
697 # cannot move beyond level and cannot move beyond the
698 # top upper limit area
699 if npc
.row
> 0 and npc
.row
> npc
.initrow
- npc
.toplimit
:
700 # check if there is any background obstacle
701 if self
.check_background_obstacle (level
, npc
.row
- 1, npc
.col
) is False:
702 # check if there are any objects
705 for lobj
in level
.objects
:
706 if lobj
.row
== npc
.row
- 1 and lobj
.col
== npc
.col
:
709 # check if there any any npcs blocking
710 for lnpc
in level
.npcs
:
711 if lnpc
.row
== npc
.row
- 1 and lnpc
.col
== npc
.col
:
714 # if no object is blocking
715 if objblock
is False and npcblock
is False:
716 # if butaba is not blocking
717 if self
.butaba
.row
<> npc
.row
- 1 or self
.butaba
.col
<> npc
.col
:
720 if npc
.position
== constants
.FRONT
:
722 elif npc
.position
== constants
.BACK
:
724 elif npc
.position
== constants
.LEFT
:
729 self
.screen
.blit (img
, (npc
.col
*48, npc
.row
*48))