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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
from fortuneengine.GameEngineElement import GameEngineElement
from Enemy import get_enemy
from BattleMenu import BattleMenuHolder
from MagicMenu import MagicMenuHolder
from AnimatedSprite import Spritesheet
import pygame
from constants import CHAR_PATH, HUD_PATH
from gettext import gettext as _
import random
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':
menu.set_sec_disp('0')
self.player_input = '0'
random.seed()
isCrit = random.randint(0,100)
tempR1 = random.randint(0,10)
tempR2 = random.randint(0,10)
self.critAns = tempR1 * tempR2
if( isCrit > 90 ):
#Show problem
menu.show_menu('attack')
menu.set_disp('%d x %d' %(tempR1, tempR2))
self.state = PLAYER_MULT
else:
#Do Attack
print "Non Crit"
menu.show_menu('selection')
menu.set_sec_disp('')
self.__attack_phase(menu)
elif self.state == PLAYER_MULT:
if selection == 'enter':
#figure out damage for crit attack
if int(self.player_input) == (self.critAns):
menu.set_disp('Correct!')
else:
menu.set_disp('Incorrect')
menu.set_sec_disp('0')
self.__attack_phase(menu)
elif selection == 'clear':
self.player_input = '0'
elif selection == 'fire':
menu.set_disp('Fire Cast!')
self.game_engine.add_object('firemenu', MagicMenuHolder( self.menu_callback ) )
self.game_engine.get_object('firemenu').show_menu('fire')
print("got here")
#self.__attack_phase(menu)
elif selection == 'heal':
menu.set_disp('Heal Cast!')
self.__attack_phase(menu)
elif selection == 'lightning':
menu.set_disp('Lightning Cast!')
self.__attack_phase(menu)
elif selection == 'missile':
menu.set_disp('Missile Cast!')
self.__attack_phase(menu)
elif selection == 'scan':
menu.set_disp('Enemy Scanned!')
self.__attack_phase(menu)
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, menu):
# Check to see how much hp enemy has left.
# Enemy Attack
# Check player health
print("in __attack_phase")
menu.set_sec_disp('0')
self.__end_battle(menu)
def __end_battle(self, menu):
#Give items if any
#self terminate
menu.show_menu('selection')
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
elif newKey=='return':
self.enemy = self.active_target
#do damage calculations
return True
# We don't want to allow other things to run during 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))
|