comparison pytouhou/game/game.py @ 198:13918723d1bc

Modify difficulty when it has to.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 30 Oct 2011 11:31:19 -0700
parents e1bc8c4cbb1a
children d348892ef012
comparison
equal deleted inserted replaced
197:e1bc8c4cbb1a 198:13918723d1bc
43 self.items = [] 43 self.items = []
44 44
45 self.stage = stage 45 self.stage = stage
46 self.rank = rank 46 self.rank = rank
47 self.difficulty = difficulty 47 self.difficulty = difficulty
48 self.difficulty_counter = 0
49 self.difficulty_min = 12 if rank == 0 else 10
50 self.difficulty_max = 20 if rank == 0 else 32
48 self.boss = None 51 self.boss = None
49 self.spellcard = None 52 self.spellcard = None
50 self.bonus_list = [0,0,1,0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,0,2] 53 self.bonus_list = [0,0,1,0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,0,2]
51 self.prng = prng or Random() 54 self.prng = prng or Random()
52 self.frame = 0 55 self.frame = 0
58 self.ecl_runner = ECLMainRunner(ecl, self) 61 self.ecl_runner = ECLMainRunner(ecl, self)
59 62
60 # See 102h.exe@0x413220 if you think you're brave enough. 63 # See 102h.exe@0x413220 if you think you're brave enough.
61 self.deaths_count = self.prng.rand_uint16() % 3 64 self.deaths_count = self.prng.rand_uint16() % 3
62 self.next_bonus = self.prng.rand_uint16() % 8 65 self.next_bonus = self.prng.rand_uint16() % 8
66
67
68 def modify_difficulty(self, diff):
69 self.difficulty_counter += diff
70 while self.difficulty_counter < 0:
71 self.difficulty -= 1
72 self.difficulty_counter += 100
73 while self.difficulty_counter >= 100:
74 self.difficulty += 1
75 self.difficulty_counter -= 100
76 if self.difficulty < self.difficulty_min:
77 self.difficulty = self.difficulty_min
78 elif self.difficulty > self.difficulty_max:
79 self.difficulty = self.difficulty_max
63 80
64 81
65 def drop_bonus(self, x, y, _type, end_pos=None): 82 def drop_bonus(self, x, y, _type, end_pos=None):
66 player = self.players[0] #TODO 83 player = self.players[0] #TODO
67 if _type > 6: 84 if _type > 6:
94 111
95 112
96 def run_iter(self, keystate): 113 def run_iter(self, keystate):
97 # 1. VMs. 114 # 1. VMs.
98 self.ecl_runner.run_iter() 115 self.ecl_runner.run_iter()
116 if self.frame % (32*60) == (32*60): #TODO: check if that is really that frame.
117 self.modify_difficulty(+100)
99 118
100 # 2. Filter out destroyed enemies 119 # 2. Filter out destroyed enemies
101 self.enemies = [enemy for enemy in self.enemies if not enemy._removed] 120 self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
102 self.effects = [enemy for enemy in self.effects if not enemy._removed] 121 self.effects = [enemy for enemy in self.effects if not enemy._removed]
103 self.bullets = [bullet for bullet in self.bullets if not bullet._removed] 122 self.bullets = [bullet for bullet in self.bullets if not bullet._removed]
234 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2 253 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2
235 or by2 < gy1 or by1 > gy2): 254 or by2 < gy1 or by1 > gy2):
236 bullet.grazed = True 255 bullet.grazed = True
237 player.state.graze += 1 256 player.state.graze += 1
238 player.state.score += 500 # found experimentally 257 player.state.score += 500 # found experimentally
258 self.modify_difficulty(+6)
239 self.new_particle((px, py), 0, .8, 192) #TODO: find the real size and range. 259 self.new_particle((px, py), 0, .8, 192) #TODO: find the real size and range.
240 #TODO: display a static particle during one frame at 260 #TODO: display a static particle during one frame at
241 # 12 pixels of the player, in the axis of the “collision”. 261 # 12 pixels of the player, in the axis of the “collision”.
242 262
243 for item in self.items: 263 for item in self.items:
266 self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)] 286 self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)]
267 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)] 287 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)]
268 self.players_bullets = [bullet for bullet in self.players_bullets if bullet.is_visible(384, 448)] 288 self.players_bullets = [bullet for bullet in self.players_bullets if bullet.is_visible(384, 448)]
269 289
270 # Filter out-of-scren items 290 # Filter out-of-scren items
271 self.items = [item for item in self.items if item.y < 448] 291 items = []
292 for item in self.items:
293 if item.y < 448:
294 items.append(item)
295 else:
296 self.modify_difficulty(-3)
297 self.items = items
272 298
273 # Disable boss mode if it is dead/it has timeout 299 # Disable boss mode if it is dead/it has timeout
274 if self.boss and self.boss._removed: 300 if self.boss and self.boss._removed:
275 self.boss = None 301 self.boss = None
276 302