commit 61849f08f0b6f992b89d71ead80da5cdf95ca384
parent 401023fb8f2d341e280b82e49a34ee4bec803630
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Wed, 26 Aug 2020 02:48:58 -0500
Images now display
Diffstat:
5 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/data/img/jisella_1.png b/data/img/jisella_1.png
Binary files differ.
diff --git a/src/constants.py b/src/constants.py
@@ -1,5 +1,6 @@
import pygame, os
-from . import images
+
+# NOTE: constants.py should not import anything from the local project to avoid circular dependencies
############################################
# Constants to be included across the game #
@@ -10,15 +11,10 @@ SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
FRAMERATE = 60
-TILE_WIDTH = 64
-TILE_HEIGHT = 64
+TILE_WIDTH = 32
+TILE_HEIGHT = 32
COLORKEY = (255, 0, 255)
# Paths
DATA_PATH = os.path.join(os.getcwd(), "data")
IMG_PATH = os.path.join(DATA_PATH, "img")
-
-# Spritesheets
-sheets = {
- "jisella_1" : images.Sheet("jisella_1.png", (TILE_WIDTH, TILE_HEIGHT), 72)
-}
diff --git a/src/game.py b/src/game.py
@@ -1,5 +1,6 @@
import pygame
-from . import interface
+from . import interface, vgo
+from .images import SHEETS
from .constants import SCREEN_WIDTH, SCREEN_HEIGHT, FRAMERATE
class Game(object):
@@ -14,6 +15,9 @@ class Game(object):
# Subsystems
self.interface = interface.Interface(self)
+ #TESTING
+ self.testvgo = vgo.Entity(SHEETS["jisella_1"].sprites[(0, 0)], (100, 100))
+
# Utility methods
def toggle_on(self):
self.on = not self.on
@@ -23,8 +27,8 @@ class Game(object):
self.frame_clock.tick(framerate)
def update_game(self):
-
self.screen.fill((0, 0, 0))
+ self.testvgo.update(self.screen)
pygame.display.update()
def mainloop(self):
diff --git a/src/images.py b/src/images.py
@@ -1,5 +1,5 @@
import pygame, os
-from .constants import COLORKEY, IMG_PATH
+from .constants import TILE_WIDTH, TILE_HEIGHT, COLORKEY, IMG_PATH
class Sheet(object):
"""
@@ -31,16 +31,14 @@ class Sheet(object):
#Step 1: attempt to load the appropriate image file
try:
- self.sheet = pygame.image.load(os.path.join(IMG_PATH, filename).convert()
+ self.sheet = pygame.image.load(os.path.join(IMG_PATH, filename))
#catch a missing file error and stop, set up graceful failure
except:
-
self.sheet = None
#Step 2: if sheet exists, divide it into sprites
if self.sheet != None:
-
self.sprites = {} # empty dict to hold our loaded images
#vals to track our progress thru the sheet
@@ -51,11 +49,10 @@ class Sheet(object):
while len(self.sprites) < total_sprites:
#get a rect that can be used to make a subsurface of the sheet
- new_rect = pygame.Rect((x * sprite_size[0], y * sprite_size[1]),
- sprite_size)
+ new_rect = pygame.Rect((x * sprite_size[0], y * sprite_size[1]), sprite_size)
#load image, store it in our dict, set its colorkey
- self.sprites[(x, y)] = self.sheet.subsurface(new_rect).convert()
+ self.sprites[(x, y)] = self.sheet.subsurface(new_rect)
self.sprites[(x, y)].set_colorkey(COLORKEY)
x += 1 # scoot over to the right
@@ -72,3 +69,15 @@ class Sheet(object):
else:
return 1 # failure :C
+
+###############################################################################
+###############################################################################
+
+#######################################
+# Spritesheets to be used in the game #
+# THIS SHOULD PROBABLY BE IN ITS OWN #
+# FILE SOMEWHERE!!! #
+#######################################
+SHEETS = {
+ "jisella_1" : Sheet("jisella_1.png", (TILE_WIDTH, TILE_HEIGHT), 72)
+}
diff --git a/src/vgo.py b/src/vgo.py
@@ -17,7 +17,6 @@ class VisibleGameObject(pygame.sprite.Sprite):
pass
def update(self, surface = None):
-
if surface != None:
surface.blit(self.image, self.rect)