summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2016-11-12 17:26:44 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2016-11-12 17:27:41 (GMT)
commit738a03336bb2b86ecfd9a0317458d89928b6c638 (patch)
tree1438b78d6c4c62e2cf09557ca53dc8a21ea19e1f
parentf9c9b76c8cae3302d91b17e4ed2b65b21ff5874e (diff)
downloadcontroller-keyboard-738a03336bb2b86ecfd9a0317458d89928b6c638.zip
controller-keyboard-738a03336bb2b86ecfd9a0317458d89928b6c638.tar.gz
Fix HeadsUpDisplay screen size scaling; Add FPS
The width wasn't correctly calculated (read: not calculated at all) making the everything but the left-aligned locations incorrect. The height was correctly calculated however. Guess I forgot to make the changes when I fixed the height. Also added an FPS counter to the top right corner.
-rw-r--r--lib/Environment.py7
-rw-r--r--lib/HeadsUpDisplay.py13
-rw-r--r--main.py2
3 files changed, 11 insertions, 11 deletions
diff --git a/lib/Environment.py b/lib/Environment.py
index 2e4c54f..049dd96 100644
--- a/lib/Environment.py
+++ b/lib/Environment.py
@@ -2,6 +2,7 @@
2import yaml 2import yaml
3import pygame 3import pygame
4import platform 4import platform
5import math
5from os import path 6from os import path
6from lib.Utils import load_image, tile_image 7from lib.Utils import load_image, tile_image
7from lib.EventHandler import JoyHandler, KeyHandler, Sectors 8from lib.EventHandler import JoyHandler, KeyHandler, Sectors
@@ -10,7 +11,9 @@ from lib.HeadsUpDisplay import HUD as HeadsUpDisplay, Locations as HudLocs
10from lib.xinput import XInputJoystick 11from lib.xinput import XInputJoystick
11 12
12class EnvironmentController(object): 13class EnvironmentController(object):
13 def __init__(self): 14 def __init__(self, clock=None):
15 self.clock = clock
16
14 self.background = tile_image(load_image('pics/bg_castle.png')) 17 self.background = tile_image(load_image('pics/bg_castle.png'))
15 pygame.joystick.init() 18 pygame.joystick.init()
16 19
@@ -56,6 +59,8 @@ class EnvironmentController(object):
56 screen.blit(self.background, (0,0)) 59 screen.blit(self.background, (0,0))
57 self.TxtObject.draw(screen) 60 self.TxtObject.draw(screen)
58 self.controller.draw(screen) 61 self.controller.draw(screen)
62 self.hud.set_text(HudLocs.TOPRIGHT, str(math.floor(self.clock.get_fps())))
63 self.hud.draw(screen)
59 64
60 def load_layout(self, layout_file): 65 def load_layout(self, layout_file):
61 pass 66 pass
diff --git a/lib/HeadsUpDisplay.py b/lib/HeadsUpDisplay.py
index 9668d2f..a02b3d0 100644
--- a/lib/HeadsUpDisplay.py
+++ b/lib/HeadsUpDisplay.py
@@ -12,11 +12,6 @@ class HUD(object):
12 self.default_color = (255, 255, 255) 12 self.default_color = (255, 255, 255)
13 self.colorkey = (0,0,0) 13 self.colorkey = (0,0,0)
14 14
15 def set_size(self, size):
16 """ Set the size of the screen. """
17 self.Width = size[0]
18 self.Height = size[1]
19
20 def clear_text(self, loc): 15 def clear_text(self, loc):
21 """ Clear all HUD text. """ 16 """ Clear all HUD text. """
22 if loc & Locations.TOPLEFT: 17 if loc & Locations.TOPLEFT:
@@ -74,15 +69,15 @@ class HUD(object):
74 if self.locations[Locations.TOPLEFT]: 69 if self.locations[Locations.TOPLEFT]:
75 destination.blit(self.locations[Locations.TOPLEFT], (0, 0)) 70 destination.blit(self.locations[Locations.TOPLEFT], (0, 0))
76 if self.locations[Locations.TOPCENTER]: 71 if self.locations[Locations.TOPCENTER]:
77 destination.blit(self.locations[Locations.TOPCENTER], ((self.Width / 2 - self.locations[Locations.TOPCENTER].get_width() / 2), 0)) 72 destination.blit(self.locations[Locations.TOPCENTER], ((destination.get_width() / 2 - self.locations[Locations.TOPCENTER].get_width() / 2), 0))
78 if self.locations[Locations.TOPRIGHT]: 73 if self.locations[Locations.TOPRIGHT]:
79 destination.blit(self.locations[Locations.TOPRIGHT], (self.Width - self.locations[Locations.TOPRIGHT].get_width(), 0)) 74 destination.blit(self.locations[Locations.TOPRIGHT], (destination.get_width() - self.locations[Locations.TOPRIGHT].get_width(), 0))
80 if self.locations[Locations.BOTTOMLEFT]: 75 if self.locations[Locations.BOTTOMLEFT]:
81 destination.blit(self.locations[Locations.BOTTOMLEFT], (0, destination.get_height() - self.locations[Locations.BOTTOMLEFT].get_height())) 76 destination.blit(self.locations[Locations.BOTTOMLEFT], (0, destination.get_height() - self.locations[Locations.BOTTOMLEFT].get_height()))
82 if self.locations[Locations.BOTTOMCENTER]: 77 if self.locations[Locations.BOTTOMCENTER]:
83 destination.blit(self.locations[Locations.BOTTOMCENTER], ((self.Width / 2 - self.locations[Locations.BOTTOMCENTER].get_width() / 2), destination.get_height() - self.locations[Locations.BOTTOMCENTER].get_height())) 78 destination.blit(self.locations[Locations.BOTTOMCENTER], ((destination.get_width() / 2 - self.locations[Locations.BOTTOMCENTER].get_width() / 2), destination.get_height() - self.locations[Locations.BOTTOMCENTER].get_height()))
84 if self.locations[Locations.BOTTOMRIGHT]: 79 if self.locations[Locations.BOTTOMRIGHT]:
85 destination.blit(self.locations[Locations.BOTTOMRIGHT], (self.Width - self.locations[Locations.BOTTOMRIGHT].get_width(), destination.get_height() - self.locations[Locations.BOTTOMRIGHT].get_height())) 80 destination.blit(self.locations[Locations.BOTTOMRIGHT], (destination.get_width() - self.locations[Locations.BOTTOMRIGHT].get_width(), destination.get_height() - self.locations[Locations.BOTTOMRIGHT].get_height()))
86 81
87class Locations(): 82class Locations():
88 TOPLEFT = 1 83 TOPLEFT = 1
diff --git a/main.py b/main.py
index b62f1ef..bfe99e0 100644
--- a/main.py
+++ b/main.py
@@ -25,7 +25,7 @@ class Game(object):
25 self.tps = cap 25 self.tps = cap
26 self.clock = pygame.time.Clock() 26 self.clock = pygame.time.Clock()
27 27
28 self.controller = EnvironmentController() 28 self.controller = EnvironmentController(self.clock)
29 29
30 def main(self): 30 def main(self):
31 running = True 31 running = True