all repos — Legends-RPG @ 2de767605689fc11924fff2ea10628bb0e5b1961

A fantasy mini-RPG built with Python and Pygame.

Polished up user input for menus and dialogue
Justin Armstrong justinmeister@gmail.com
Mon, 24 Mar 2014 10:13:59 -0700
commit

2de767605689fc11924fff2ea10628bb0e5b1961

parent

9ee373a472b1ac434cf268cdcf3875ada4c57b29

M data/components/textbox.pydata/components/textbox.py

@@ -21,7 +21,6 @@ def __init__(self, dialogue, index=0, image_key='dialoguebox', item=None):

self.item = item self.bground = setup.GFX[image_key] self.rect = self.bground.get_rect(centerx=400) - self.timer = 0.0 self.arrow_timer = 0.0 self.font = pg.font.Font(setup.FONTS['Fixedsys500c'], 22) self.dialogue_list = dialogue

@@ -30,6 +29,7 @@ self.image = self.make_dialogue_box_image()

self.arrow = NextArrow() self.check_to_draw_arrow() self.done = False + self.allow_input = False self.name = image_key

@@ -64,12 +64,11 @@

def terminate_check(self, keys): """Remove textbox from sprite group after 2 seconds""" + if keys[pg.K_SPACE] and self.allow_input: + self.done = True - if self.timer == 0.0: - self.timer = self.current_time - elif (self.current_time - self.timer) > 300: - if keys[pg.K_SPACE]: - self.done = True + if not keys[pg.K_SPACE]: + self.allow_input = True def check_to_draw_arrow(self):
M data/shopgui.pydata/shopgui.py

@@ -19,6 +19,7 @@ self.state = 'dialogue'

self.font = pg.font.Font(setup.FONTS['Fixedsys500c'], 22) self.index = 0 self.timer = 0.0 + self.allow_input = False self.item = level.item self.dialogue = level.dialogue self.accept_dialogue = level.accept_dialogue

@@ -129,13 +130,17 @@ def control_dialogue(self, keys, current_time):

"""Control the dialogue boxes""" self.dialogue_box = self.make_dialogue_box(self.dialogue, self.index) - if self.index < (len(self.dialogue) - 1): + if self.index < (len(self.dialogue) - 1) and self.allow_input: if keys[pg.K_SPACE]: self.index += 1 + self.allow_input = False - elif self.index == (len(self.dialogue) - 1): - self.state = 'select' - self.timer = current_time + if self.index == (len(self.dialogue) - 1): + self.state = 'select' + self.timer = current_time + + if not keys[pg.K_SPACE]: + self.allow_input = True def make_selection(self, keys, current_time):

@@ -149,12 +154,17 @@ self.selection_arrow.rect.topleft = self.arrow_pos2

elif keys[pg.K_UP]: self.selection_arrow.rect.topleft = self.arrow_pos1 elif keys[pg.K_SPACE] and (current_time - self.timer) > 200: - if self.selection_arrow.rect.topleft == self.arrow_pos2: - self.level.done = True - self.level.game_data['last direction'] = 'down' - elif self.selection_arrow.rect.topleft == self.arrow_pos1: - self.state = 'confirm' - self.timer = current_time + if self.allow_input: + if self.selection_arrow.rect.topleft == self.arrow_pos2: + self.level.done = True + self.level.game_data['last direction'] = 'down' + elif self.selection_arrow.rect.topleft == self.arrow_pos1: + self.state = 'confirm' + self.timer = current_time + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True

@@ -169,13 +179,18 @@ if keys[pg.K_DOWN]:

self.selection_arrow.rect.topleft = self.arrow_pos2 elif keys[pg.K_UP]: self.selection_arrow.rect.topleft = self.arrow_pos1 - elif keys[pg.K_SPACE] and (current_time - self.timer) > 200: + elif keys[pg.K_SPACE] and self.allow_input: if self.selection_arrow.rect.topleft == self.arrow_pos1: self.buy_item() + self.allow_input = False else: self.state = 'select' + self.allow_input = False self.timer = current_time self.selection_arrow.rect.topleft = self.arrow_pos1 + + if not keys[pg.K_SPACE]: + self.allow_input = True def buy_item(self):

@@ -200,10 +215,14 @@ """Reject player selection if they do not have enough gold"""

dialogue = ["You don't have enough gold!"] self.dialogue_box = self.make_dialogue_box(dialogue, 0) - if keys[pg.K_SPACE] and (current_time - self.timer) > 200: + if keys[pg.K_SPACE] and self.allow_input: self.state = 'select' self.timer = current_time self.selection_arrow.rect.topleft = self.arrow_pos1 + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True def accept_purchase(self, keys, current_time):

@@ -211,10 +230,14 @@ """Accept purchase and confirm with message"""

self.dialogue_box = self.make_dialogue_box(self.accept_dialogue, 0) self.gold_box = self.make_gold_box() - if keys[pg.K_SPACE] and (current_time - self.timer) > 200: + if keys[pg.K_SPACE] and self.allow_input: self.state = 'select' self.timer = current_time self.selection_arrow.rect.topleft = self.arrow_pos1 + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True def has_item(self, keys, current_time):

@@ -222,10 +245,14 @@ """Tell player he has item already"""

dialogue = ["You have that item already."] self.dialogue_box = self.make_dialogue_box(dialogue, 0) - if keys[pg.K_SPACE] and (current_time - self.timer) > 200: + if keys[pg.K_SPACE] and self.allow_input: self.state = 'select' self.timer = current_time self.selection_arrow.rect.topleft = self.arrow_pos1 + self.allow_input = False + + if not keys[pg.K_SPACE]: + self.allow_input = True def add_player_item(self, item):
M data/states/town/blockers.txtdata/states/town/blockers.txt

@@ -44,7 +44,7 @@ T00B2B0000011000000010B0T

0TB010000001100000001B0T0 T0B011111111111111111BT0T 0TB000000001100000000B0T0 -B0B0B00B000110000000B0T0T -B0BBB00B000110000000BT0T0 -0T0B0B0000011000000B00T00 -00000B0000011000000B00000+B0B0B000000110000000B0T0T +B0BBB0B0000110000000BT0T0 +0T0B0BBB00011000000B00T00 +00000B0B00011000000B00000
M data/states/town/layer1.txtdata/states/town/layer1.txt

@@ -44,7 +44,7 @@ T0T2220000011000000010T0T

0T0010000001100000001T0T0 T0T0111111111111111110T0T 0T0000000001100000000T0T0 -T0T0T00W000110000000T0T0T -000T00000001100000000T0T0 -0T000T0000011000000T00T00 +T0T0T000W0011000000TT0T0T +000T00T000011000T0T00T0T0 +0T000T0T000110000T0T00T00 0000000000011000000000000
M data/states/town/sprite_start_pos.txtdata/states/town/sprite_start_pos.txt

@@ -44,7 +44,7 @@ 0002220000011000000010000

0000100000011000000010000 0000111111111111111110000 0000000000011000000000000 -0000000D0F011000000000000 -0000000D00011000000000000 +00000000DF011000000000000 +00000000D0011000000000000 0000000000011000000000000 000000000001P000000000000