| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 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 |
|
| 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 |
|
| 31 |
if adonthell.input_has_been_pushed (adonthell.SDLK_SPACE) or \ |
| 32 |
adonthell.input_has_been_pushed (adonthell.SDLK_RETURN): |
| 33 |
|
| 34 |
p = self.myself.whosnext () |
| 35 |
|
| 36 |
|
| 37 |
if p != None and p.currentmove () < adonthell.WALK_NORTH: |
| 38 |
|
| 39 |
p.launch_action (self.myself) |
| 40 |
|
| 41 |
|
| 42 |
p = None |
| 43 |
|
| 44 |
|
| 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 |
|
| 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 |
|
| 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 |
|