Debian Codegraph @

scripts/schedules/mapcharacters/keyboard_control.py

raw symbols SCIP
1 #
2 # $Id$
3 #
4 # (C) Copyright 2001 Alexandre Courbot
5 # Part of the Adonthell Project http://adonthell.linuxgames.com
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY.
11 #
12 # See the COPYING file for more details
13 #
14
15 import adonthell
16
17 class keyboard_control:
18
19 def __init__ (self, mapcharinstance):
20 self.myself = mapcharinstance
21 self.wnd = None
22
23 def run (self):
24 # -- allow smooth movement on the veranda
25 if self.myself.get_val ("on_veranda") == 1 and self.wnd == None:
26 self.enable_veranda_hack ()
27 elif self.myself.get_val ("on_veranda") != 1 and self.wnd != None:
28 self.disable_veranda_hack ()
29
30 # -- react to the action key
31 if adonthell.input_has_been_pushed (adonthell.SDLK_SPACE) or \
32 adonthell.input_has_been_pushed (adonthell.SDLK_RETURN):
33 # -- see whether a character(/object) is next to the player
34 p = self.myself.whosnext ()
35
36 # - Yes :)
37 if p != None and p.currentmove () < adonthell.WALK_NORTH:
38 # -- launch the other guy's (object's) action script
39 p.launch_action (self.myself)
40
41 # -- Cleanup
42 p = None
43
44 # -- otherwise launch an action event
45 elif p == None:
46 evt = adonthell.action_event ()
47 evt.submap = self.myself.submap ()
48 evt.x = self.myself.posx ()
49 evt.y = self.myself.posy ()
50 evt.dir = self.myself.currentmove ()
51 evt.c = self.myself
52 adonthell.event_handler_raise_event (evt)
53
54 # -- move the player around
55 elif adonthell.input_is_pushed (adonthell.SDLK_UP): self.myself.go_north ()
56 elif adonthell.input_is_pushed (adonthell.SDLK_DOWN): self.myself.go_south ()
57 elif adonthell.input_is_pushed (adonthell.SDLK_RIGHT): self.myself.go_east ()
58 elif adonthell.input_is_pushed (adonthell.SDLK_LEFT): self.myself.go_west ()
59
60 # -- BEGIN veranda hack
61 def enable_veranda_hack (self):
62 self.wnd = adonthell.win_container ()
63 self.wnd.set_visible (False)
64 self.wnd.thisown = 0
65 self.wnd.py_signal_connect (self.on_draw, adonthell.win_event_DRAW, self.myself)
66 adonthell.win_manager_get_active ().add (self.wnd)
67
68 def disable_veranda_hack (self):
69 adonthell.win_manager_get_active ().remove (self.wnd)
70 del self.wnd
71 self.wnd = None
72
73 def on_draw (self, mychar):
74 if mychar.submap () == 0 and mychar.posx () >= 17 and mychar.posx () <= 19 \
75 and mychar.posy () == 12:
76 view = adonthell.gamedata_engine ().get_mapview ()
77
78 x = (mychar.posx () - view.posx () - mychar.base_x ()) * 20 \
79 + mychar.offx () - view.offx ()
80
81 y = (mychar.posy () - view.posy () - mychar.base_y ()) * 20 \
82 + mychar.offy () - view.offy ()
83
84 mychar.draw (x, y)
85 # -- END veranda hack