Skip to content
Permalink
Browse files

display current room name

  • Loading branch information...
jakubthedeveloper committed May 17, 2018
1 parent d1cb407 commit 5792b52a11448f66b5b9f4dd78d493f5ad99138c
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 game.py
@@ -9,6 +9,8 @@
class Game(object):
level = None
click_pointer = None
guiFont = None
currentRoomName = ''

def __init__(self, level):
self.screen = pygame.display.get_surface()
@@ -43,6 +45,10 @@ def drawObjects(self, dt):
def drawPlayer(self, dt):
self.screen.blit(self.player.getTile(), (self.player.position_x, self.level.getFloorY(self.player.current_floor) - self.player.HEIGHT))

def drawGui(self, dt):
label = self.guiFont.render(self.currentRoomName, 1, (255,255,0))
self.screen.blit(label, (30, self.screen.get_height() - 30))

def eventLoop(self):
for event in pygame.event.get():
if event.type == pygame.QUIT or event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
@@ -67,11 +73,17 @@ def update(self, dt):
# player is on target floor - go to point
self.player.goTo(self.click_pointer, dt)

self.updateCurrentRoom()

This comment has been minimized.

Copy link
@jakubthedeveloper

jakubthedeveloper May 17, 2018

Author Owner

To można jeszcze zoptymalizować, ponieważ odpalanie metody updateCurrentRoom() w każdej iteracji pętli zdarzeń (gdy postać się przemieszcza) jest kosztowne.


def updateCurrentRoom(self):
self.currentRoomName = self.level.getRoomName(self.player.position_x, self.player.current_floor)

def draw(self, dt):
self.drawBackground()
self.drawObjects(dt)
self.drawPlayer(dt)
self.drawForeground()
self.drawGui(dt)
self.click_pointer.draw(self.screen)
pygame.display.flip()

@@ -83,5 +95,10 @@ def main_loop(self):
self.draw(dt)
dt = self.clock.tick(self.fps) / 1000.0

def init(self):
self.guiFont = pygame.font.SysFont("monospace", 18)
self.updateCurrentRoom()

def run(self):
self.init()
self.main_loop()
BIN +924 Bytes (120%) game.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from roomData import roomData

class Level(object):
NAME = 'House'
FLOOR_Y = [
@@ -10,6 +12,18 @@ class Level(object):
744
]

ROOMS = [
roomData(0, 240, 438, 'Office'),
roomData(0, 455, 653, 'Playroom'),
roomData(1, 240, 438, 'Bedroom'),
roomData(1, 455, 653, 'Bathroom'),
roomData(1, 679, 865, 'Laundry'),
roomData(2, 240, 438, 'TV room'),
roomData(2, 455, 653, 'Kitchen'),
roomData(2, 679, 912, 'Garage'),
roomData(3, 679, 912, 'Boiler room')
]

LIFT_X = 660
LIFT_MARGIN = 12

@@ -41,3 +55,10 @@ def getFloorIndex(self, y):
return key
key = key + 1
return 0

def getRoomName(self, x, floor):
for roomData in self.ROOMS:
if (roomData.floor == floor and x >= roomData.minX and x <= roomData.maxX):
return roomData.name

return str(x)
BIN +725 Bytes (140%) levels/level1.pyc
Binary file not shown.
@@ -0,0 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

class roomData():
def __init__(self, floor, minX, maxX, name):
self.floor = floor
self.minX = minX
self.maxX = maxX
self.name = name
BIN +619 Bytes roomData.pyc
Binary file not shown.

0 comments on commit 5792b52

Please sign in to comment.
You can’t perform that action at this time.