Skip to content

Commit

Permalink
Items are more fleshed out, and equipment is now displayed. Also, if …
Browse files Browse the repository at this point in the history
…you have nothing in that slot, it is automatically equipped
  • Loading branch information
Katie Cunningham authored and Katie Cunningham committed Apr 12, 2012
1 parent bb271dc commit a6f9a02
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
11 changes: 5 additions & 6 deletions roguey/classes/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
MONSTERS = 12
TILE_SIZE = 48
DIRECTIONS = ['north', 'south', 'east', 'west']
ALL_TREASURES = {
"hat": "Quite cunning",
"sqord": "Knock-off sword. Probably from Ikea.",
"book": "What the hell are you going to do with this?",
"rainbow": "Joy in a box."
}
LONG_STRING = "X" * 50

EQUIPMENT_TYPES = ('hat', 'shirt', 'pants', 'shoes', 'back', 'neck', 'hands', 'weapon')
START_EQUIPMENT = {}
for treasure in EQUIPMENT_TYPES:
START_EQUIPMENT[treasure] = None

TREASURE_TYPES = ('hat', 'shirt', 'pants', 'shoes', 'back', 'neck', 'hands', 'weapon', 'trash')

IMG_DIR = dirname(dirname(abspath(__file__))) + "/images/"
3 changes: 2 additions & 1 deletion roguey/classes/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def add_treasure(self, treasure):
''' Adds the treasure to the player's inventory
'''
text = "You found a %s. %s" % (treasure.title, treasure.description)
self.inventory.add_to_inventory(treasure.title)
self.inventory.add_to_inventory(treasure, self.player_stats)
self.screen.draw_alert(text)

def move(self, hor, vert):
Expand Down Expand Up @@ -73,6 +73,7 @@ def move(self, hor, vert):
if treasure:
self.add_treasure(treasure)
self.screen.draw_inventory(self.inventory)
self.screen.draw_equipment(self.player_stats.equipped)
self.screen.draw_player(self.map.player)
self.screen.draw_screen_layers(self.map, self.player_stats)

Expand Down
36 changes: 30 additions & 6 deletions roguey/classes/gamescreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ def __init__(self):
self.player_blit = pygame.image.load(IMG_DIR + 'dude.png')
self.screen.blit(self.bg, (0,0))
self.inventory_screen = self.small_font.render("Inventory", True, WHITE, BLACK)
self.equipment_screen = self.small_font.render("Equipment", True, WHITE, BLACK)
self.draw_alert("Welcome to Katie's Roguelike!")
self.stats_screen = self.small_font.render("ARGH", True, WHITE, BLACK)
self.draw_inventory()
self.draw_equipment()
pygame.display.flip()

def draw_player(self, coord):
Expand Down Expand Up @@ -47,18 +50,39 @@ def draw_alert(self, alert, color=WHITE):
self.screen.blit(self.alert, (0, 790))
pygame.display.flip()

def draw_inventory(self, inventory):
def draw_equipment(self, equipment=START_EQUIPMENT):
self.screen.blit(self.equipment_screen, (1008, 200))
for i in range(equipment.keys().__len__()):
line = self.small_font.render(LONG_STRING, True, BLACK, BLACK)
self.screen.blit(line, (1008, ((i+1)*15)+200))
pygame.display.flip()
i = 1
for slot in equipment.keys():
try:
line_text = slot + ": " + equipment[slot].title
except:
line_text = slot + ": "
line = self.small_font.render(line_text, True, WHITE, BLACK)
self.screen.blit(line, (1008, i*15+200))
i += 1



def draw_inventory(self, inventory=None):
''' Renders the inventory for the user
'''
self.screen.blit(self.inventory_screen, (1008, 100))
items = inventory.get_items()
self.screen.blit(self.inventory_screen, (1008, 400))
if inventory:
items = inventory.get_items()
else:
items = []
for i in range(items.__len__()):
line = self.small_font.render(LONG_STRING, True, BLACK, BLACK)
self.screen.blit(line, (1008, ((i+1)*15)+100))
self.screen.blit(line, (1008, ((i+1)*15)+400))
pygame.display.flip()
for item in items:
line = self.small_font.render(item, True, WHITE, BLACK)
self.screen.blit(line, (1008, (items.index(item)+1)*15+100))
line = self.small_font.render(item.title, True, WHITE, BLACK)
self.screen.blit(line, (1008, (items.index(item)+1)*15+400))

def draw_treasure(self, treasure_map):
''' Draws the treasure chests yet to be opened.
Expand Down
18 changes: 13 additions & 5 deletions roguey/classes/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ def __init__(self):
def get_items(self):
return self.inventory.keys()

def add_to_inventory(self, item):
def add_to_inventory(self, item, player):
''' Adds an item to the inventory
'''
try:
self.inventory[item] += 1
except:
self.inventory[item] = 1
if item.type == "trash":
return
if player.equipped[item.type]:
try:
self.inventory[item] += 1
except:
self.inventory[item] = 1
else:
player.equip_item(item)


class Player(object):
Expand Down Expand Up @@ -52,5 +57,8 @@ def attempt_block(self, attack):
def get_attack(self):
return self.strength

def equip_item(self, item):
self.equipped[item.type] = item



0 comments on commit a6f9a02

Please sign in to comment.