all repos — Legends-RPG @ c0a1a80585351c8001637d8bf163dd13b033aaa7

A fantasy mini-RPG built with Python and Pygame.

Credits scene works without crashing now, still has placeholder text.
Justin Armstrong justinmeister@gmail.com
Tue, 17 Jun 2014 18:28:16 -0700
commit

c0a1a80585351c8001637d8bf163dd13b033aaa7

parent

7606c0c7c7335bda8b7801f1f9498f3f965723fd

4 files changed, 43 insertions(+), 32 deletions(-)

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

@@ -155,22 +155,8 @@ 'The sorceror who lives there has my crown.',

'Please retrieve it for me.'] self.talking_sprite.dialogue = new_dialogue self.end_dialogue(current_time) - elif (self.game_data['crown quest'] - and not self.game_data['delivered crown']): - retrieved_crown_dialogue = ['My crown! You recovered my stolen crown!!!', - 'I can not believe what I see before my eyes.', - 'You are truly a brave and noble warrior.', - 'Henceforth, I name thee Grand Protector of this Town!', - 'Go forth and be recognized.', - 'You are the greatest warrior this world has ever known.'] - self.game_data['talked to king'] = True - self.talking_sprite.dialogue = retrieved_crown_dialogue + elif self.game_data['crown quest']: self.game_data['delivered crown'] = True - self.end_dialogue(current_time) - elif self.game_data['delivered crown']: - thank_you_dialogue = ['Thank you for retrieving my crown.', - 'My kingdom is forever in your debt.'] - self.talking_sprite.dialogue = thank_you_dialogue self.end_dialogue(current_time) else: self.end_dialogue(current_time)
M data/main.pydata/main.py

@@ -1,4 +1,5 @@

from data.states import shop, levels, battle, main_menu, death +from data.states import credits from . import setup, tools from . import constants as c

@@ -24,6 +25,7 @@ DUNGEON5 = 'dungeon5'

INSTRUCTIONS = 'instructions' DEATH_SCENE = 'death scene' LOADGAME = 'load game' +CREDITS = 'credits' def main():

@@ -48,7 +50,8 @@ DUNGEON4: levels.LevelState(DUNGEON4, True),

DUNGEON5: levels.LevelState(DUNGEON5, True), INSTRUCTIONS: main_menu.Instructions(), LOADGAME: main_menu.LoadGame(), - DEATH_SCENE: death.DeathScene() + DEATH_SCENE: death.DeathScene(), + CREDITS: credits.Credits() } run_it.setup_states(state_dict, c.MAIN_MENU)
M data/states/credits.pydata/states/credits.py

@@ -1,3 +1,4 @@

+import copy import pygame as pg from .. import tools, setup from .. import constants as c

@@ -7,7 +8,7 @@ class CreditEntry(object):

""" The text for each credit for the game. """ - def __init__(self): + def __init__(self, level): self.font = pg.font.Font(setup.FONTS[c.MAIN_FONT], 22) self.credit_sprites = self.make_credits() self.index = 0

@@ -16,12 +17,14 @@ self.state_dict = self.make_state_dict()

self.state = c.TRANSITION_IN self.alpha = 0 self.timer = 0.0 + self.level = level def make_credits(self): """ Make a list of lists for all the credit surfaces. """ - credits = [['PROGRAMMING AND GAME DESIGN', 'Justin Armstrong'], + credits = [['THE STOLEN CROWN', 'A Fantasy RPG'], + ['PROGRAMMING AND GAME DESIGN', 'Justin Armstrong'], ['ART', 'John Smith'], ['MUSIC', 'John Smith'], ['SPECIAL THANKS', '/r/pygame']]

@@ -32,9 +35,10 @@ for credit in credits:

subcredit_list = [] for i, subcredit in enumerate(credit): text_sprite = pg.sprite.Sprite() - text_sprite.image = self.font.render(subcredit, True, c.WHITE) - text_sprite.rect = text_sprite.image.get_rect(centerx = 400, - y=300+(i*50)) + text_sprite.text_image = self.font.render(subcredit, True, c.WHITE) + text_sprite.rect = text_sprite.text_image.get_rect(centerx = 400, + y=250+(i*50)) + text_sprite.image = pg.Surface(text_sprite.rect.size) subcredit_list.append(text_sprite) credit_sprites.append(subcredit_list)

@@ -52,9 +56,12 @@ return state_dict

def transition_in(self): for credit in self.current_credit: + credit.image = pg.Surface(credit.rect.size).convert() + credit.image.set_colorkey(c.BLACK) credit.image.set_alpha(self.alpha) + credit.image.blit(credit.text_image, (0, 0)) - self.alpha += c.TRANSITION_SPEED + self.alpha += 5 if self.alpha >= 255: self.alpha = 255 self.state = c.NORMAL

@@ -62,22 +69,30 @@ self.timer = self.current_time

def transition_out(self): for credit in self.current_credit: + credit.image = pg.Surface(credit.rect.size).convert() + credit.image.set_colorkey(c.BLACK) credit.image.set_alpha(self.alpha) - self.alpha -= c.TRANSITION_SPEED + credit.image.blit(credit.text_image, (0, 0)) + + self.alpha -= 5 if self.alpha <= 0: self.alpha = 0 - self.index += 1 + if self.index < len(self.credit_sprites) - 1: + self.index += 1 + else: + self.level.done = True + self.level.next = c.MAIN_MENU self.current_credit = self.credit_sprites[self.index] self.state = c.TRANSITION_IN def normal_update(self): - if (self.current_time - self.timer) > 5000: + if (self.current_time - self.timer) > 2500: self.state = c.TRANSITION_OUT - def update(self, surface, current_time, *args): + def update(self, current_time): self.current_time = current_time update_method = self.state_dict[self.state] - update() + update_method() def draw(self, surface): """

@@ -87,7 +102,7 @@ for credit_sprite in self.current_credit:

surface.blit(credit_sprite.image, credit_sprite.rect) -class Credits(tools._state): +class Credits(tools._State): """ End Credits Scene. """

@@ -109,10 +124,10 @@ self.music = setup.MUSIC['overworld']

self.volume = 0.4 self.current_time = current_time self.background = pg.Surface(setup.SCREEN_RECT.size) - self.background.fill(c.BLACKBLUE) - self.credit = CreditEntry() + self.background.fill(c.BLACK_BLUE) + self.credit = CreditEntry(self) - def update(self, surface, current_time, *args): + def update(self, surface, keys, current_time): """ Update scene. """
M data/states/levels.pydata/states/levels.py

@@ -292,7 +292,6 @@ '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 - self.game_data['delivered crown'] = True self.reset_dialogue = (sprite, thank_you_dialogue) elif self.game_data['delivered crown']: sprite.dialogue = thank_you_dialogue

@@ -344,6 +343,7 @@ self.sprites.update(current_time)

self.collision_handler.update(keys, current_time) self.check_for_battle() self.check_for_portals() + self.check_for_end_of_game() self.dialogue_handler.update(keys, current_time) self.check_for_menu(keys) self.viewport_update()

@@ -392,6 +392,13 @@ self.game_data['last direction'] = self.player.direction

self.game_data['last state'] = self.name self.set_new_start_pos() + def check_for_end_of_game(self): + """ + Switch scene to credits if main quest is complete. + """ + if self.game_data['delivered crown']: + self.next = c.CREDITS + self.state = 'transition_out' def set_new_start_pos(self): """