commit 8a03a924b4c389ed3b0342185be00dfd568bb18d
parent 6b568a38808e020410623b7319e0ee0b7077b1b6
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Fri, 24 Sep 2021 19:50:45 -0500
regularize custom sprites
Diffstat:
3 files changed, 8 insertions(+), 34 deletions(-)
diff --git a/src/entity.py b/src/entity.py
@@ -47,7 +47,7 @@ class CustomSprite(pygame.sprite.Sprite):
def update(self, surface = None):
"""
- Update this DungeonSprite.
+ Update this CustomSprite.
"""
if surface != None:
surface.blit(self.image, self.rect)
diff --git a/src/game.py b/src/game.py
@@ -147,7 +147,7 @@ class Game(object):
# TODO: This is totally not generic. Would it be worth it
# to abstract this in some way? That will have to be
# done for menus anyway...
- self.ui_tray = ui.UIElement(self.sheets["ui_tray"].sprites[(0, 0)], (0, 0))
+ self.ui_tray = entity.CustomSprite(self.sheets["ui_tray"].sprites[(0, 0)], (0, 0))
self.ui_group.add(self.ui_tray)
def switch_board(self, boardname, cellpos):
diff --git a/src/ui.py b/src/ui.py
@@ -1,4 +1,5 @@
import pygame
+from . import entity
from .gamelib import *
#########
@@ -6,40 +7,13 @@ from .gamelib import *
#########
# This file contains:
-# 1. The UIElement class, which is used to make UI compenents.
-# 2. Various classes which make up UI components and are children of UIElement.
-
-###############################
-# Section 1 - UIElement class #
-###############################
-
-class UIElement(pygame.sprite.Sprite):
- """
- Basic sprite extension class for UI elements.
- """
-
- def __init__(self, image, pos):
-
- # Parent initialization
- pygame.sprite.Sprite.__init__(self)
-
- # Other vals
- self.image = image
- self.rect = self.image.get_rect()
- self.rect.topleft = pos
-
- def update(self, surface = None):
- """
- Update the UIElement.
- """
- if surface != None:
- surface.blit(self.image, self.rect)
+# 1. Various classes which make up UI components and are children of UIElement.
####################################
-# Section 2 - UI Component Classes #
+# Section 1 - UI Component Classes #
####################################
-class UIStateButton(UIElement):
+class UIStateButton(entity.CustomSprite):
"""
UIStateButton is a simple button object used
in the UI that calls the game's state switching
@@ -49,10 +23,10 @@ class UIStateButton(UIElement):
state from any state).
"""
- def __init__(self, image, pos, game, to_state, from_states = []):
+ def __init__(self, image, pos, game, to_state, from_states = [], pixcolor = None):
# Parent intialization
- super().__init__(image, pos)
+ super().__init__(image, pos, pixcolor)
# Saved values
self.game = game