Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/MAFH2/BattleEngine.py
blob: 3d0505b712d12a6047cd70270c1009776162de41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from GameEngine import GameEngineElement
from Enemy import get_enemy
from BattleMenu import BattleMenuHolder
from AnimatedSprite import Spritesheet
import pygame

from constants import CHAR_PATH, HUD_PATH

from gettext import gettext as _

PLAYER_WAIT = 1
PLAYER_MULT = 2

class BattleEngine(GameEngineElement):
    def __init__(self, dgn):
        GameEngineElement.__init__(self, has_draw=True, has_event=True)

        self.dgn = dgn
        self.current_room = dgn.get_current_room()

        self.font = pygame.font.SysFont("cmr10",18,False,False)

        self.enemy_list = []

        self.state = PLAYER_WAIT
        self.player_input = '0'
        self.active_target = 1

        for i in range(0,4):
            e_index = self.current_room.get_enemy( i )

            if e_index != '0':
                self.enemy_list.append( get_enemy( e_index ) )

        # Preload images
        self.__images = {}
        for i in ['arrow_select']:
            self.__images[i] = pygame.image.load( HUD_PATH + i + ".gif" )

        self.__images['hp'] = Spritesheet( HUD_PATH + "hp.png" ).img_extract(11,1,100,100)
        self.__images['bt'] = Spritesheet( HUD_PATH + "bt.png" ).img_extract(1,11,100,25)

        self.game_engine.start_event_timer(1, 150)

        self.add_to_engine()
        self.game_engine.add_object('battlemenu', BattleMenuHolder( self.menu_callback ) )
        self.game_engine.get_object('battlemenu').show_menu('selection')
        self.game_engine.get_object('mesg').add_line( _('Enemies present, prepare to fight!') )

    def menu_callback(self, selection, menu):
        if selection == 'attack_show':

            if( True ):
                #Show problem
                menu.show_menu('attack')
                menu.set_disp('10 x 4')
                self.state = PLAYER_MULT
            else:
                #Do Attack
                print "DO ATTACK"
                menu.show_menu('selection')

        elif self.state == PLAYER_MULT:
            if selection == 'enter':
                pass

            elif selection == 'clear':
                self.player_input = '0'

            else:
                #MUST BE A NUMBER
                if self.player_input == '0':
                    self.player_input = selection

                else:
                    self.player_input = self.player_input + selection

            menu.set_sec_disp( self.player_input )

    def __attack_phase(self):
        # Enemy Attack
        # Check player health
        pass

    def __end_battle(self):
        #Give items if any
        #self terminate
        pass

    def event_handler(self, event):
        if event.type == pygame.USEREVENT+1:
            return True

        elif event.type == pygame.KEYDOWN:

            newKey=pygame.key.name(event.key)

            if newKey=='[4]' or newKey=='left':
                self.active_target -= 1
                if self.active_target < 1:
                    self.active_target = len(self.enemy_list)
                return True

            elif newKey=='[6]' or newKey=='right':
                self.active_target += 1
                if self.active_target > len(self.enemy_list):
                    self.active_target = 1
                return True


        # We don't want to allow other things to run durning battle
        return True

    def draw(self, screen):
        x=250
        y=150
        i = 1

        tick_time = pygame.time.get_ticks()

        # Draw Enemy and Item Selection
        for enemy in self.enemy_list:
            if self.active_target == i:
                screen.blit(self.__images['arrow_select'], (x+(i*200),y-25))
            enemy.sprite.update( tick_time )
            screen.blit(enemy.sprite.image, (x+(i*200),y))
            i = i+1

        # Draw Hud
        profile = self.game_engine.get_object('profile')

        # Player Health
        health = 10 - profile.hero.healthLevel()
        screen.blit(self.__images['hp'][health], (25,25))