all repos — Legends-RPG @ d4842499160b2b7f27df95928231834d218d5ff4

A fantasy mini-RPG built with Python and Pygame.

Cure spell can be used from menu now (also used Vim for the first time to make a commit-worthy change, yay me)
Justin Armstrong justinmeister@gmail.com
Fri, 23 May 2014 22:33:08 -0700
commit

d4842499160b2b7f27df95928231834d218d5ff4

parent

78f7dd5b0cc124cef7ca6aecee53f7cd7caf2486

M .gitignore.gitignore

@@ -1,6 +1,7 @@

*.py[cod] *.idea +*.swp # C extensions *.so
M The_Stolen_Crown.pyThe_Stolen_Crown.py

@@ -3,7 +3,7 @@ __author__ = 'justinarmstrong'

"""This is a fantasy RPG game about a warrior whose quest is to recover a magic crown""" - + import sys import pygame as pg from data import setup
M data/battlegui.pydata/battlegui.py

@@ -39,7 +39,7 @@ c.SELECT_MAGIC: 'Select a magic spell.',

c.SELECT_ITEM: 'Select an item.', c.SELECT_ENEMY: 'Select an enemy.', c.ENEMY_ATTACK: 'Enemy attacks player!', - c.PLAYER_ATTACK: 'Player attacks enemy.', + c.PLAYER_ATTACK: 'Player attacks enemy! ', c.RUN_AWAY: 'RUN AWAY!!!', c.ENEMY_DAMAGED: self.enemy_damaged(), c.ENEMY_DEAD: 'Enemy killed.',

@@ -49,7 +49,8 @@ c.DRINK_ETHER_POTION: 'Magic Points Increased.',

c.FIRE_SPELL: 'FIRE BLAST!', c.BATTLE_WON: 'Battle won!', c.SHOW_EXPERIENCE: self.show_experience(), - c.LEVEL_UP: self.level_up()} + c.LEVEL_UP: self.level_up(), + c.TWO_ACTIONS: 'Two actions per turn mode is now available.'} return state_dict
M data/constants.pydata/constants.py

@@ -65,6 +65,7 @@ FLEE = 'flee'

FADE_DEATH = 'fade death' SHOW_EXPERIENCE = 'show experience' LEVEL_UP = 'level up' +TWO_ACTIONS = 'two actions' #EVENTS
M data/menugui.pydata/menugui.py

@@ -24,7 +24,8 @@

def make_state_dict(self): """Make state dictionary""" state_dict = {'selectmenu': self.navigate_select_menu, - 'itemsubmenu': self.navigate_item_submenu} + 'itemsubmenu': self.navigate_item_submenu, + 'magicsubmenu': self.navigate_magic_submenu} return state_dict

@@ -40,6 +41,19 @@ """Nav the item submenu"""

self.pos_list = self.make_item_menu_pos_list() self.rect.topleft = self.pos_list[pos_index] + def navigate_magic_submenu(self, pos_index): + """Nav the magic submenu""" + self.pos_list = self.make_magic_menu_pos_list() + self.rect.topleft = self.pos_list[pos_index] + + def make_magic_menu_pos_list(self): + """ + Make the list of possible arrow positions for magic submenu. + """ + pos_list = [(310, 119), + (310, 169)] + + return pos_list def make_select_menu_pos_list(self): """Make the list of possible arrow positions"""

@@ -50,7 +64,6 @@ pos = (35, 356 + (i * 50))

pos_list.append(pos) return pos_list - def make_item_menu_pos_list(self): """Make the list of arrow positions in the item submenu"""

@@ -228,6 +241,14 @@ posx = 80

posy = starty + (i * 50) self.slots[(posx, posy)] = item + def assign_magic_slots(self, magic_list, starty): + """ + Assign each magic spell to a slot in the menu. + """ + for i, spell in enumerate(magic_list): + posx = 120 + posy = starty + (i * 50) + self.slots[(posx, posy)] = spell def blit_item_lists(self, surface): """Blit item list to info box surface"""

@@ -243,8 +264,6 @@ text_image = self.font.render(text, True, c.NEAR_BLACK)

text_rect = text_image.get_rect(topleft=coord) surface.blit(text_image, text_rect) - - def show_magic(self): """Show list of magic spells the player knows""" title = 'MAGIC'

@@ -254,11 +273,14 @@ if item in self.possible_magic:

item_list.append(item) item_list = sorted(item_list) + self.slots = {} + self.assign_magic_slots(item_list, 80) + surface, rect = self.make_blank_info_box(title) for i, item in enumerate(item_list): text_image = self.font.render(item, True, c.NEAR_BLACK) - text_rect = text_image.get_rect(x=50, y=80+(i*50)) + text_rect = text_image.get_rect(x=100, y=80+(i*50)) surface.blit(text_image, text_rect) self.image = surface

@@ -353,6 +375,10 @@ if self.info_box.state == 'items':

if not self.arrow.state == 'itemsubmenu': self.arrow_index = 0 self.arrow.state = 'itemsubmenu' + elif self.info_box.state == 'magic': + if not self.arrow.state == 'magicsubmenu': + self.arrow_index = 0 + self.arrow.state = 'magicsubmenu' elif keys[pg.K_LEFT]: self.arrow.state = 'selectmenu'

@@ -374,6 +400,8 @@ self.arrow_index = 0

self.info_box.state = 'stats' elif self.arrow.state == 'itemsubmenu': self.select_item() + elif self.arrow.state == 'magicsubmenu': + self.select_magic() self.allow_input = False elif keys[pg.K_RETURN]:

@@ -400,9 +428,8 @@

if (posx, posy) in self.info_box.slots: if self.info_box.slots[(posx, posy)][:7] == 'Healing': potion = 'Healing Potion' - stat = self.game_data['player stats']['health'] value = 30 - self.drink_potion(potion, stat, value) + self.drink_potion(potion, health, value) elif self.info_box.slots[(posx, posy)][:5] == 'Ether': potion = 'Ether Potion' stat = self.game_data['player stats']['magic points']

@@ -422,6 +449,33 @@ if 'Chain Mail' in self.inventory['equipped armor']:

self.inventory['equipped armor'].remove('Chain Mail') else: self.inventory['equipped armor'].append('Chain Mail') + + def select_magic(self): + """ + Select spell from magic menu. + """ + health = self.game_data['player stats']['health'] + magic = self.game_data['player stats']['magic points'] + posx = self.arrow.rect.x - 190 + posy = self.arrow.rect.y - 39 + + if (posx, posy) in self.info_box.slots: + if self.info_box.slots[(posx, posy)][:4] == 'Cure': + self.use_cure_spell() + + def use_cure_spell(self): + """ + Use cure spell to heal player. + """ + health = self.game_data['player stats']['health'] + magic = self.game_data['player stats']['magic points'] + inventory = self.game_data['player inventory'] + + if magic['current'] > inventory['Cure']['magic points']: + magic['current'] -= inventory['Cure']['magic points'] + health['current'] += inventory['Cure']['power'] + if health['current'] > health['maximum']: + health['current'] = health['maximum'] def drink_potion(self, potion, stat, value): """
M data/states/battle.pydata/states/battle.py

@@ -45,6 +45,7 @@ self.player_action_dict = self.make_player_action_dict()

self.player_level = self.game_data['player stats']['Level'] self.enemies_to_attack = [] self.action_selected = False + self.just_leveled_up = False def make_player_action_dict(self): """

@@ -263,6 +264,13 @@ self.enter_show_experience_state()

elif self.state == c.LEVEL_UP: if (self.current_time - self.timer) > 2200: + if self.game_data['player stats']['Level'] == 3: + self.enter_two_actions_per_turn_state() + else: + self.end_battle() + + elif self.state == c.TWO_ACTIONS: + if (self.current_time - self.timer) > 3000: self.end_battle() elif self.state == c.SHOW_EXPERIENCE:

@@ -276,6 +284,7 @@ player_stats['magic points']['maximum'] += int(player_stats['magic points']['maximum']*.20)

new_experience = int((player_stats['Level'] * 100) * .75) player_stats['experience to next level'] = new_experience self.enter_level_up_state() + self.just_leveled_up = True else: self.end_battle()

@@ -500,7 +509,7 @@ def enter_player_attack_state(self):

""" Transition battle into the Player attack state. """ - self.state = c.PLAYER_ATTACK + self.state = self.info_box.state = c.PLAYER_ATTACK enemy_to_attack = self.enemies_to_attack.pop(0) if enemy_to_attack in self.enemy_list: self.player.enter_attack_state(enemy_to_attack)

@@ -640,6 +649,10 @@ Transition battle into the LEVEL UP state.

""" self.state = self.info_box.state = c.LEVEL_UP self.info_box.reset_level_up_message() + self.set_timer_to_current_time() + + def enter_two_actions_per_turn_state(self): + self.state = self.info_box.state = c.TWO_ACTIONS self.set_timer_to_current_time() def execute_player_actions(self):
M data/states/levels.pydata/states/levels.py

@@ -247,7 +247,7 @@ 'Henceforth, I name thee Grand Protector of this Town!',

'Go forth and be recognized.', 'You are the greatest warrior this world has ever known.'] thank_you_dialogue = ['Thank you for retrieving my crown.', - 'My kingdom is forever in you debt.'] + 'My kingdom is forever in your debt.'] if self.game_data['crown quest'] and not self.game_data['delivered crown']: sprite.dialogue = retrieved_crown_dialogue
M data/states/shop.pydata/states/shop.py

@@ -277,11 +277,13 @@

item = {'type': 'Healing Potion', 'price': 15, 'quantity': 1, + 'power': None, 'dialogue': healing_dialogue} item2 = {'type': 'Ether Potion', 'price': 15, 'quantity': 1, + 'power': None, 'dialogue': ether_dialogue} return [item, item2]
M data/tools.pydata/tools.py

@@ -192,7 +192,7 @@ player_magic = {'current': 100,

'maximum': 100} player_stats = {'health': player_health, - 'Level': 1, + 'Level': 2, 'experience to next level': 20, 'magic points': player_magic, 'attack points': 10,