Added a shop keep
Justin Armstrong justinmeister@gmail.com
Tue, 18 Mar 2014 23:08:57 -0700
7 files changed,
51 insertions(+),
27 deletions(-)
M
data/components/person.py
→
data/components/person.py
@@ -271,8 +271,8 @@
class Player(Person): """User controlled character""" - def __init__(self, direction): - super(Player, self).__init__('player', 0, 0, direction) + def __init__(self, direction, x=0, y=0): + super(Player, self).__init__('player', x, y, direction) self.item_list = []
M
data/constants.py
→
data/constants.py
@@ -1,20 +1,20 @@
-__author__ = 'justinarmstrong' - -import pygame as pg - """Constants used throughout the game""" +SCREEN_SIZE = (800, 608) + ##GAME STATES""" TOWN = 'town' MAIN_MENU = 'main menu' CASTLE = 'castle' +SHOP = 'shop' ##Colors BLACK = (0, 0, 0) NEAR_BLACK = (1, 0, 0) WHITE = (255, 255, 255) +BLACK_BLUE = (19, 15, 48)
M
data/main.py
→
data/main.py
@@ -1,9 +1,7 @@
from data.states.main_menu import main_menu from data.states.town import town from data.states.castle import castle - -__author__ = 'justinarmstrong' - +from data.states import shop from . import setup, tools from . import constants as c@@ -12,7 +10,8 @@ """Add states to control here"""
run_it = tools.Control(setup.ORIGINAL_CAPTION) state_dict = {c.TOWN: town.Town(c.TOWN, 25, 50), c.MAIN_MENU: main_menu.Menu(c.MAIN_MENU), - c.CASTLE: castle.Castle(c.CASTLE, 25, 27)} + c.CASTLE: castle.Castle(c.CASTLE, 25, 27), + c.SHOP: shop.Shop(c.SHOP)} run_it.setup_states(state_dict, c.MAIN_MENU) run_it.main()
M
data/states/shop.py
→
data/states/shop.py
@@ -4,10 +4,10 @@ This includes weapon, armour, magic and potion shops.
It also includes the inn. These states are scaled twice as big as a level state. """ - +import copy import pygame as pg -from .. import tools -from .. import tilemap as tm +from .. import tools, setup +from .. import constants as c from .. components import person, textbox@@ -23,13 +23,12 @@ """Startup state"""
self.persist = persist self.current_time = current_time self.state = 'normal' - self.level_map = tm.make_level_map(self.name, - self.map_width, - self.map_height) - self.level_surface = tm.make_level_surface(self.level_map) + self.get_image = tools.get_image + self.level_surface = pg.Surface(c.SCREEN_SIZE).convert() + self.level_surface.fill(c.BLACK_BLUE) self.level_rect = self.level_surface.get_rect() - self.player = person.Player('right') - self.shop_owner = self.make_shop_owner() + self.player = self.make_sprite('player', 96, 32, 100) + self.shop_owner = self.make_sprite('man1', 32, 32, 600) self.dialogue_handler = textbox.DialogueHandler(self.player,@@ -37,6 +36,24 @@ self.shop_owner,
self) + def make_sprite(self, key, coordx, coordy, x, y=304): + """Get the image for the player""" + spritesheet = setup.GFX[key] + surface = pg.Surface((32, 32)) + surface.set_colorkey(c.BLACK) + image = self.get_image(coordx, coordy, 32, 32, spritesheet) + rect = image.get_rect() + surface.blit(image, rect) + + surface = pg.transform.scale(surface, (96, 96)) + rect = surface.get_rect(left=x, centery=y) + sprite = pg.sprite.Sprite() + sprite.image = surface + sprite.rect = rect + + return sprite + + def make_shop_owner(self): """Make the shop owner sprite""" return None@@ -44,4 +61,11 @@
def update(self, surface, keys, current_time): """Update level state""" - pass + self.draw_level(surface) + + + def draw_level(self, surface): + """Blit graphics to game surface""" + surface.blit(self.level_surface, self.level_rect) + surface.blit(self.player.image, self.player.rect) + surface.blit(self.shop_owner.image, self.shop_owner.rect)
M
data/states/town/portals.txt
→
data/states/town/portals.txt
@@ -39,7 +39,7 @@ 0000000000011000000000000
0000000000011000000333000 0003330000011000000333000 0003330000011000000222000 -00022200000110000002A2000 +00022200000110000002B2000 0002A20000011000000010000 0000100000011000000010000 0000111111111111111110000
M
data/tilemap.py
→
data/tilemap.py
@@ -75,7 +75,7 @@
def make_level_map(state, width, height): """Blits the different layers of the map onto one surface""" - map = create_background(state, width, height) + map = make_background(state, width, height) map = create_map_layer1(map, state) map = create_map_layer2(map, state) map = scale_map(map)@@ -84,16 +84,17 @@
return map -def create_background(state_name, width, height): +def make_background(state_name, width, height): """Creates the background surface that the rest of the town map will be blitted on""" size = (width*16, height*16) surface = pg.Surface(size) - if state_name == c.CASTLE: + if state_name == c.TOWN: + tile = get_image(0, 0, 16, 16, setup.GFX['tileset2']) + else: tile = pg.Surface((16, 16)) tile.fill(c.NEAR_BLACK) - else: - tile = get_image(0, 0, 16, 16, setup.GFX['tileset2']) + rect = tile.get_rect() for row in range(50):@@ -384,7 +385,7 @@ for column, letter in enumerate(line):
if letter == 'A': portal_group.add(portal.Portal(column, row, c.CASTLE)) elif letter == 'B': - portal_group.add(portal.Portal(column, row, c.TOWN)) + portal_group.add(portal.Portal(column, row, c.SHOP)) return portal_group