From 868aa7724aa05e6236e8fdff3a922403fc53c8ea Mon Sep 17 00:00:00 2001 From: Kevin Hockey Date: Thu, 05 Aug 2010 00:37:53 +0000 Subject: TermBox integrated --- diff --git a/MAFH2/MafhActivity.py b/MAFH2/MafhActivity.py index c148985..584d83d 100755 --- a/MAFH2/MafhActivity.py +++ b/MAFH2/MafhActivity.py @@ -7,7 +7,7 @@ from Comic import Comic from Profile import Profile from MafhGameManager import MafhGameManager -ge = GameEngine(width=1200, height=900, always_draw=True) +ge = GameEngine(width=1200, height=900, always_draw=True, fps_cap=15) def start_game(): ge.add_object('manager', MafhGameManager() ) diff --git a/MAFH2/TermBox.py b/MAFH2/TermBox.py index 9a3e6e9..2c93cfc 100644 --- a/MAFH2/TermBox.py +++ b/MAFH2/TermBox.py @@ -1,5 +1,7 @@ import pygame from fortuneengine.GameEngineElement import GameEngineElement +from fortuneengine.DrawableFontObject import DrawableFontObject +from fortuneengine.DrawableObject import DrawableObject class TermBox(GameEngineElement): def __init__(self, x,y,width,height,lines): GameEngineElement.__init__(self, has_draw=True, has_event=False) @@ -7,25 +9,27 @@ class TermBox(GameEngineElement): self.max_lines = lines self.x = x self.y = y - self.width = width - self.height = height + surf = pygame.Surface((width,height)) + surf.fill([0,0,0]) + self.box = DrawableObject([surf],"") + self.box.setPosition(x,y) self.font = pygame.font.Font(None, 20) self.__lines = [] - + for i in range(lines): + self.__lines.append(DrawableFontObject('', self.font)) + self.game_engine.get_scene().addObject(self.box) + self.game_engine.get_scene().addObjects(self.__lines) self.add_to_engine() def add_line(self, line): - self.__lines.append( line ) - if len( self.__lines ) > self.max_lines: - self.__lines.pop(0) + for i in range(self.max_lines-1, 0, -1): + if i == 0: + self.__lines[i].changeText(line, [255,255,255]) + else: + self.__lines[i] = self.__lines[i-1] def draw(self,screen,time_delta): - dirtyList=[] #added Jul 20 - pygame.draw.rect(screen, [0, 0, 0], (self.x, self.y, self.width, self.height)) i=0 for line in self.__lines: - ren = self.font.render(line, 1, [255, 255, 255]) -# screen.blit(ren, (self.x, self.y + i*self.font.get_height())) - dirtyList.append(ren.get_rect().move( (self.x, self.y + i*self.font.get_height()) )) #added Jul 20 + line.setPosition(self.x, self.y + i*self.font.get_height()) i+=1 - return dirtyList #added Jul 20 -- cgit v0.9.1