Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 6c4c63e29da3b219b77ebefbb515d23eb2113c58
parent f6e54bfd10856099a978381dadc647fe19fcceca
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 27 Aug 2021 13:41:49 -0500

notes, message move, and ui button added

Diffstat:
Mmain.py | 18++++++++++++++++++
Msrc/game.py | 2+-
Msrc/message.py | 2+-
Msrc/ui.py | 29+++++++++++++++++++++++++++++
4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/main.py b/main.py @@ -1,6 +1,24 @@ import pygame from src import game +## GLOBAL TODO: +# 1. The UI is essentially at a different resolution from the actual game. This looks bad. Ideally the game's assets should be available in 2 main +# resolutions: 240p (320x240 window AKA 4:3 aspect ratio) and 360p (640x360 window AKA 16:9 aspect ratio). Both of these scale correctly to higher +# resolutions (especially the latter) and offer unique advantages: 240p is more accurate to traditional 80's PC and pre-6th generation console +# resolutions, and is desired by retro-purists and those that want the experience to be more like playing on a CRT (it also looks better with the +# kind of screen effects this group likes, such as artificial scanlines, and optional support for such effects might be highly desired by a minority +# of the playerbase); conversely, 360p scales perfectly to 720p, 1080p, and even 4K, meaning that it will support most modern screens, so the art +# will also look good for the group that sees pixel art as less of a retro-throwback thing and more of a modern stylistic choice (this group also +# usually prefers the clean, sharp-edged, LEGO-block look of pixel art on a modern LCD as well). Resolution should be handled internally like so: in +# the options menu, there should be a resolution list and a fullscreen checkbox. Changing this should change the resolution and fullscreen-state in +# real-time without having to restart the game. The resolution list should include all common screen and window dimensions. Internally, these listed +# resolutions will be associated either with the 240p assets or the 360p assets, and will have a list of scale factors which represent multiples of +# these dimensions that correspond to the base scaling of the original assets. Therefore, what is needed is to seperate the images into two broad +# categories (240p and 360p), and have copies of these images that are scaled by all needed multiples for every resolution. This could be accomplished +# by simply making that many assets, or by making only the basic ones and scaling assets internally on startup and after a resolution change using +# pygame's image transform features. As an addition, game elements that are positioned according to their absolute screen position, rather than being +# positioned according to the relative location of another game element, should be accounted for in the aforementioned resolution association lists. + ########### # main.py # ########### diff --git a/src/game.py b/src/game.py @@ -39,7 +39,7 @@ class Game(object): # Game components self.interface = interface.Interface(self) - self.message_board = message.MessageBoard(self, ((SCREEN_WIDTH // 3) - 2, SCREEN_HEIGHT - 16), (self.viewport_rect.right + 16, 4)) + self.message_board = message.MessageBoard(self, (313, 620), (696, 72)) # TODO: Hardcoded. Need to make the whole UI resolution-aware... # Pygame sprite objects self.player = None diff --git a/src/message.py b/src/message.py @@ -59,7 +59,7 @@ class MessageBoard(object): # Other vals self.messages = [] self.rendered_messages = pygame.sprite.Group() - self.max_messages = (SCREEN_HEIGHT // MESSAGE_FONT_SIZE) - 2 + self.max_messages = (self.board_rect.height // MESSAGE_FONT_SIZE) def post(self, text, data): """ diff --git a/src/ui.py b/src/ui.py @@ -38,3 +38,32 @@ class UIElement(pygame.sprite.Sprite): #################################### # Section 2 - UI Component Classes # #################################### + +class UIStateButton(UIElement): + """ + UIStateButton is a simple button object used + in the UI that calls the game's state switching + function whenever clicked. It also has a list of + which states it can switch from, but this can be + empty (indicating it can switch to its associated + state from any state). + """ + + def __init__(self, image, pos, game, to_state, from_states = []): + + # Parent intialization + super().__init__(image, pos) + + # Saved values + self.game = game + self.to_state = to_state + self.from_states = from_states + + def be_clicked(self, data = None): + """ + Activate the state switch if we can. 'data' + is the data that gets passed to the game's + switch_mode function. + """ + if self.game.state_mode in self.from_states: + self.game.switch_switch_mode(self.to_state, data)