Commits

Patrick Dawson committed 806bb44

.

Comments (0)

Files changed (7)

         if len(self.lines) > self.max_lines:
             self.lines = self.lines[1:]
         self.config(text='\n'.join(self.lines))
+        
+    def clear(self):
+        self.lines = []
+        self.config(text='')
 
 
 def IL(fn):

data/plot_barracks.png

Old
Old image
New
New image

data/plot_empty.png

Old
Old image
New
New image

data/plot_farm.png

Old
Old image
New
New image

data/tree.png

Old
Old image
New
New image
     
 class Character(object):
     def __init__(self):
+        self.img = None
+        self.pos = None
         self.hp = 1
         self.ac = 11 # no armor
         self.dmg = (1,4)
 
 class Militia(Character):
     def __init__(self):
+        self.img = IL("militia")
         self.hp = 6 # level 1 fighter
         self.ac = 13 # leather
         self.dmg = (1,6) # short spear
         
 class Infantry(Character):
     def __init__(self):
+        self.img = IL("infantry")
         self.hp = 12 # level 2 fighter
         self.ac = 16 # chainmail + shield
         self.dmg = (1,8) # longsword
         
 class Archer(Character):
     def __init__(self):
+        self.img = IL("archer")
         self.hp = 6
         self.ac = 13
         self.dmg = (1,8)
         self.ab = 1
         self.str = 0
         self.dex = 2
+        
+class EnemyMilitia(Militia):
+    def __init__(self):
+        Militia.__init__(self)
+        self.img = IL("enemy_militia")
+
+class EnemyInfantry(Militia):
+    def __init__(self):
+        Infantry.__init__(self)
+        self.img = IL("enemy_infantry")
+
+class EnemyArcher(Militia):
+    def __init__(self):
+        Archer.__init__(self)
+        self.img = IL("enemy_archer")
+
 
 class WoodWalls(object):
     pass
 
+
+class GameEvents(object):
+    attack = {
+        2 : [(EnemyMilitia,2)],
+    }
+
 class Fort(object):
     def __init__(self):
         self.pop = {
         }
         self.tasks = []
         self.turn = 1
+        self.battle = False
         self.buildings = []
         self.free_plots = 6
         self.free_barracks = 0
         self.walls = None
+        self.observers = []
+        self.defenders = []
+        self.attackers = []
         self.reset_tasks()
         
     def reset_tasks(self):
         self.turn += 1
         self.reset_tasks()
 
+        if self.turn in GameEvents.attack:
+            self.start_battle(GameEvents.attack[self.turn])
+            
+    def start_battle(self, enemy_force):
+        self.defenders = []
+        self.attackers = []
+        for etype, enum in enemy_force:
+            for n in range(enum):
+                self.attackers.append(etype())
+        for ptype, pnum in self.pop.items():
+            for n in range(pnum):
+                if ptype == MILITIA:
+                    self.defenders.append(Militia())
+                elif ptype == INFANTRY:
+                    self.defenders.append(Infantry())
+                elif ptype == ARCHER:
+                    self.defenders.append(Archer())
+        self.battle = True
+        for o in self.observers:
+            o.battle_start()
+        
+    def battle_observe(self, o):
+        self.observers.append(o)
+
 
 class Battle(object):
     def __init__(self):
     def __init__(self, surface):
         self.screen = None
         self.surface = surface
+        self.screen_cache = {
+            MenuScreen : MenuScreen(self),
+            IntroScreen : IntroScreen(self),
+            FortScreen : FortScreen(self),
+            BattleScreen : BattleScreen(self),
+        }
         
     def change(self, new_screen):
         if self.screen is not None:
             self.screen.hide()
-        self.screen = new_screen(self)
+        self.screen = self.screen_cache[new_screen]
         self.screen.show()
         
     def update(self, dt):
         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)
         
+        FORT.battle_observe(self)
+        
+    def battle_start(self):
+        self.txt.clear()
+        self.txt.addLine('Combat begins!')
+        self.bf.draw_canvas()
+        
     def update(self, dt):
+        self.sm.surface.blit(self.bf.canvas, (64,8))
         self.t += dt
         if self.t >= 1000:
             self.t = 0
             AudioMixer.play('hit1')
-            self.txt.addLine('beep')
+            self.txt.addLine('tick')
 
 
 class Battlefield(object):
     def draw_canvas(self):
         self.canvas.fill((100,100,100))
         self.blit_grass()
-        self.blit_wall()
+        if FORT.walls is not None:
+            self.blit_wall()
+        self.blit_trees()
+        self.blit_defenders()
+        self.blit_attackers()
         
     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_trees(self):
+        for x in range(14):
+            for y in range(9):
+                if x > 9:
+                    self.canvas.blit(IL("tree"), (x*64,y*64))
+                
     def blit_wall(self):
         w = IL("walls_wood")
         walls = []
                     else:
                         self.canvas.blit(walls[1], (x*64,y*64))
                         
+                        
+    def blit_defenders(self):
+        aslot = 0
+        fslot = 0
+        for d in FORT.defenders:
+            pos = None
+            if type(d) == Archer:
+                pos = self.archer_slots[aslot]
+                aslot += 1
+            else:
+                pos = self.foot_slots[fslot]
+                fslot += 1
+            
+            d.pos = pos
+            self.canvas.blit(d.img, (pos[0]*64,pos[1]*64))
+    
+    def blit_attackers(self):
+        eslot = 0
+        for e in FORT.attackers:
+            pos = self.enemy_slots[eslot]
+            eslot += 1
+            
+            e.pos = pos
+            self.canvas.blit(e.img, (pos[0]*64,pos[1]*64))
+                        
+                        
+        """                        
         for pos in self.archer_slots:
             self.canvas.blit(IL("archer"), (pos[0]*64,pos[1]*64))
         for pos in self.foot_slots:
         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):
         self.rd.blit_resources()
         self.fs.draw_canvas()
         self.update_buttons()
-        # TODO: stuff
-        #self.sm.change(BattleScreen)
+        
+        if FORT.battle:
+            self.sm.change(BattleScreen)
         
     def update(self, dt):
         self.draw()