Commits

Patrick Dawson committed 6056d6e

battle gui

Comments (0)

Files changed (5)

     clock = pygame.time.Clock()
     
     sm = ScreenManager(screen)
-    sm.change(FortScreen)
+    sm.change(MenuScreen)
     
     for sndfn in ['click']:
         AudioMixer.load(sndfn)
     def enable(self):
         self.config(col=self.col_bak, label_col=self.label_col_bak)
         self.disabled = False
+
+class TextLog(sgc.widgets.Label):
+    def __init__(self, *args, **kwargs):
+        sgc.widgets.Label.__init__(self, *args, **kwargs)
+        self.lines = []
+        self.max_lines = 6
         
-        
-        
+    def addLine(self, line):
+        self.lines.append(line)
+        if len(self.lines) > self.max_lines:
+            self.lines = self.lines[1:]
+        self.config(text='\n'.join(self.lines))        
+
+
 def IL(fn):
     return ImageLoader.load(fn)
 
 BUILD_FARM = 'BUILD_FARM'
 BUILD_BARRACKS = 'BUILD_BARRACKS'
+BUILD_WALL = 'BUILD_WALL'
+
 CHOP_WOOD = 'CHOP_WOOD'
 HUNT = 'HUNT'
+
 TRAIN_MILITIA = 'TRAIN_MILITIA'
 TRAIN_INFANTRY = 'TRAIN_INFANTRY'
 TRAIN_ARCHER = 'TRAIN_ARCHER'
-Fort in the Woods
+ 
+FORT IN THE WOODS
+
 by Patrick Dawson <pat@dw.is>
 for Ludum Dare 23, 2012-04-22
 
 Libraries used:
 - PyGame
 - sgc
+
+Other:
+- combat rules inspired by Basic Fantasy RPG
 
 class Screen(object):
     def __init__(self, sm):
-        pass
+        self.sm = sm
+        self.widgets = []
+        self.fade_in = True
+    def add(self, w):
+        self.widgets.append(w)
     def show(self):
-        pass
+        for w in self.widgets:
+            w.add(fade=self.fade_in)
     def hide(self):
-        pass
+        for w in self.widgets:
+            w.remove(fade=False)
     def update(self, dt):
         pass
 
 
 class MenuScreen(Screen):
     def __init__(self, sm):
-        self.sm = sm
+        Screen.__init__(self, sm)
+        self.fade_in = False
 
         self.start_btn = MyButton(label="Start Game", pos=(450,400))
         self.start_btn.click = self.clickStart
+        self.add(self.start_btn)
         
         self.exit_btn = MyButton(label="Exit", pos=(450,470))
         self.exit_btn.click = sys.exit
+        self.add(self.exit_btn)
 
         font = pygame.font.Font('data/Artifika-Regular.ttf', 48)
         title_surf = font.render('Fort in the Woods', True, (255,255,255))
         signature_rect.bottomright = 1024 - 8, 768 - 8
     
         self.title = sgc.widgets.Simple(surf=title_surf, pos=title_rect.topleft)
+        self.add(self.title)
         self.signature = sgc.widgets.Simple(surf=signature_surf, pos=signature_rect.topleft)
+        self.add(self.signature)
 
-    def show(self):
-        self.start_btn.add(0, fade=False)
-        self.exit_btn.add(1, fade=False)
-        self.title.add(fade=False)
-        self.signature.add(fade=False)
-        
-    def hide(self):
-        self.start_btn.remove(fade=False)
-        self.exit_btn.remove(fade=False)
-        self.title.remove(fade=False)
-        self.signature.remove(fade=False)
-        
     def clickStart(self):
         self.sm.change(IntroScreen)
             
 class IntroScreen(Screen):
     def __init__(self, sm):
-        self.sm = sm
+        Screen.__init__(self, sm)
         
         mytxt = """
         You have been ordered to establish an outpost in enemy territory. Your
         """
         
         self.txt = sgc.widgets.Label(text=mytxt, pos=(100,200))
+        self.add(self.txt)
         
         self.btn_continue = MyButton(label="Continue", pos=(500,400))
         self.btn_continue.click = self.clickContinue
-        
-    def show(self):
-        self.txt.add()
-        self.btn_continue.add(0)
-        
-    def hide(self):
-        self.txt.remove(fade=False)
-        self.btn_continue.remove(fade=False)
+        self.add(self.btn_continue)
         
     def clickContinue(self):
         self.sm.change(FortScreen)
 
+
 class BattleScreen(Screen):
-    pass
+    def __init__(self, sm):
+        Screen.__init__(self, sm)
+        self.t = 0
+        self.bf = Battlefield()
+        self.bf_widget = sgc.widgets.Simple(surf=self.bf.canvas, pos=(64,8))
+        self.add(self.bf_widget)
+                
+        self.txt = TextLog(pos=(64,600))
+        self.txt.addLine('Combat begins!')
+        self.txt.addLine('test2')
+        self.txt.addLine('test3')
+        self.txt.addLine('test4')
+        self.txt.addLine('test5')
+        self.txt.addLine('test6')
+        self.add(self.txt)
+        
+    def update(self, dt):
+        self.t += dt
+        if self.t >= 1000:
+            self.t = 0
+            AudioMixer.play('hit1')
+            self.txt.addLine('beep')
+
 
 class Battlefield(object):
-    pass
+    def __init__(self):
+        self.size = (14*64, 9*64)
+        self.canvas = pygame.Surface(self.size, flags=pygame.SRCALPHA)
+        self.archer_slots = [(1,3),(1,5),(1,2),(1,6),(1,1),(1,7),(1,0),(1,8),(1,4),
+                             (0,3),(0,5),(0,2),(0,6),(0,1),(0,7),(0,0),(0,8),(0,4)]
+        self.foot_slots = [(4,3),(4,5),(4,2),(4,6),(4,1),(4,7),(4,0),(4,8),(4,4),
+                             (3,3),(3,5),(3,2),(3,6),(3,1),(3,7),(3,0),(3,8),(3,4)]
         
+        self.enemy_slots = [(6,3),(6,5),(6,2),(6,6),(6,1),(6,7),(6,0),(6,8),(6,4),
+                             (7,3),(7,5),(7,2),(7,6),(7,1),(7,7),(7,0),(7,8),(7,4)]
+        self.draw_canvas()
         
+    def draw_canvas(self):
+        self.canvas.fill((100,100,100))
+        self.blit_grass()
+        self.blit_wall()
+        
+    def blit_grass(self):
+        for x in range(14):
+            for y in range(9):
+                self.canvas.blit(IL("grass"), (x*64,y*64))
+                
+    def blit_wall(self):
+        w = IL("walls_wood")
+        walls = []
+        for x in range(3):
+            for y in range(3):
+                walls.append(w.subsurface((x*64,y*64,64,64)))
+                
+        for x in range(14):
+            for y in range(9):
+                if x == 2:
+                    if y == 4:
+                        self.canvas.blit(walls[4], (x*64,y*64))
+                    else:
+                        self.canvas.blit(walls[1], (x*64,y*64))
+                        
+        for pos in self.archer_slots:
+            self.canvas.blit(IL("archer"), (pos[0]*64,pos[1]*64))
+        for pos in self.foot_slots:
+            self.canvas.blit(IL("infantry"), (pos[0]*64,pos[1]*64))
+            
+        from random import choice
+        elist = [IL("enemy_militia"), IL("enemy_infantry"), IL("enemy_archer")]
+        for pos in self.enemy_slots:
+            self.canvas.blit(choice(elist), (pos[0]*64,pos[1]*64))
+
+
 class FortScreen(Screen):
     def __init__(self, sm):
-        self.sm = sm
+        Screen.__init__(self, sm)
         self.fs = FortSurface()
         self.rd = ResourceDisplay()
         
+        self.fs_widget = sgc.widgets.Simple(surf=self.fs.canvas, pos=(256-4,192-4))
+        self.rd_widget = sgc.widgets.Simple(surf=self.rd.canvas, pos=(256-4,24-4))
+        
         self.font1 = pygame.font.Font('data/Artifika-Regular.ttf', 32)
         self.font2 = pygame.font.Font('data/Artifika-Regular.ttf', 22)
         t1 = self.font1.render('TURN 1', True, WHITE)
         
         self.btn_build_farm = MyButton(label="Build Farm\n-10 Wood", pos=(10,200))
         self.btn_build_barracks = MyButton(label="Build Barracks\n-20 Wood", pos=(130,200))
+        self.btn_build_wall = MyButton(label="Build Walls\n-50 Wood", pos=(10,260))
         
         self.btn_chop_wood = MyButton(label="Chop Wood\n+5 Wood", col=BUTTON_COLOR2, pos=(10,350))
         self.btn_hunt = MyButton(label="Hunt\n+5 Food", col=BUTTON_COLOR2, pos=(130,350))
 
         self.btn_build_farm.click = partial(self._doTask, BUILD_FARM)
         self.btn_build_barracks.click = partial(self._doTask, BUILD_BARRACKS)
+        self.btn_build_wall.click = partial(self._doTask, BUILD_WALL)
         self.btn_chop_wood.click = partial(self._doTask, CHOP_WOOD)
         self.btn_hunt.click = partial(self._doTask, HUNT)
         self.btn_train_militia.click = partial(self._doTask, TRAIN_MILITIA)
         self.btn_train_archer.click = partial(self._doTask, TRAIN_ARCHER)
         self.btn_next_turn.click = self.clickNextTurn
         
-        self.btn_next_turn.disable()
+        #self.btn_next_turn.disable()
         self.btn_train_militia.disable()
         self.btn_train_infantry.disable()
         self.btn_train_archer.disable()
         
-    def show(self):
-        self.txt1.add()
-        self.txt2.add()
-        self.btn_build_farm.add()
-        self.btn_build_barracks.add()
-        self.btn_chop_wood.add()
-        self.btn_hunt.add()
-        self.btn_train_militia.add()
-        self.btn_train_infantry.add()
-        self.btn_train_archer.add()
-        self.btn_reset.add()
-        self.btn_next_turn.add()
-    
-    def hide(self):
-        self.txt1.remove(fade=False)
-        self.txt2.remove(fade=False)
-        self.btn_build_farm.remove(fade=False)
-        self.btn_build_barracks.remove(fade=False)
-        self.btn_chop_wood.remove(fade=False)
-        self.btn_hunt.remove(fade=False)
-        self.btn_train_militia.remove(fade=False)
-        self.btn_train_infantry.remove(fade=False)
-        self.btn_train_archer.remove(fade=False)
-        self.btn_reset.remove(fade=False)
-        self.btn_next_turn.remove(fade=False)
-        
-    def update(self, dt):
-        self.fs.draw(self.sm.surface)
-        self.rd.draw(self.sm.surface)
+        self.add(self.fs_widget)
+        self.add(self.rd_widget)
+        self.add(self.txt1)
+        self.add(self.txt2)
+        self.add(self.btn_build_farm)
+        self.add(self.btn_build_barracks)
+        self.add(self.btn_build_wall)
+        self.add(self.btn_chop_wood)
+        self.add(self.btn_hunt)
+        self.add(self.btn_train_militia)
+        self.add(self.btn_train_infantry)
+        self.add(self.btn_train_archer)
+        self.add(self.btn_reset)
+        self.add(self.btn_next_turn)
         
     def _doTask(self, task):
         ok = FORT.assign(task)
     def blit_plots(self):
         for p in self.plots:
             self.canvas.blit(p.img, (p.pos[0]*64,p.pos[1]*64))
+
         
-    def draw(self, surface):
-        surface.blit(self.canvas, (256-4,192-4))
-