Mercurial > touhou
changeset 153:37df8c618c2e
Add falling items.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 09 Oct 2011 16:54:49 -0700 |
parents | 86807b8a63bd |
children | 364935f6e313 |
files | pytouhou/game/game.py pytouhou/game/games.py pytouhou/game/item.py pytouhou/game/itemtype.py |
diffstat | 4 files changed, 48 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/game.py +++ b/pytouhou/game/game.py @@ -51,10 +51,17 @@ class Game(object): self.ecl_runner = ECLMainRunner(ecl, self.new_enemy, self) + def drop_bonus(self, x, y, _type): + player = self.players[0] #TODO + item_type = self.item_types[_type] + item = Item((x, y), item_type, self) + self.items.append(item) + + def change_bullets_into_star_items(self): player = self.players[0] #TODO item_type = self.item_types[6] - self.items.extend(Item((bullet.x, bullet.y), item_type, 0.0, item_type.speed, player, self) for bullet in self.bullets) + self.items.extend(Item((bullet.x, bullet.y), item_type, self, player=player) for bullet in self.bullets) self.bullets = []
--- a/pytouhou/game/games.py +++ b/pytouhou/game/games.py @@ -31,13 +31,14 @@ class EoSDGame(Game): BulletType(etama3, 7, 13, 20, 20, 20, hitbox_size=11), BulletType(etama3, 8, 13, 20, 20, 20, hitbox_size=9), BulletType(etama4, 0, 1, 2, 2, 2, hitbox_size=32)] - item_types = [ItemType(etama3, 0, 7, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 1, 8, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 2, 9, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 3, 10, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 4, 11, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 5, 12, speed=8., hitbox_size=42), #TODO: hitbox - ItemType(etama3, 6, 13, speed=8., hitbox_size=42)] #TODO: hitbox + #TODO: hitbox + item_types = [ItemType(etama3, 0, 7, hitbox_size=42, score=10), #Power + ItemType(etama3, 1, 8, hitbox_size=42, score=100000), #Point, TODO: changes for hard, lunatic and poc + ItemType(etama3, 2, 9, hitbox_size=42, score=10), #Big power + ItemType(etama3, 3, 10, hitbox_size=42), #Bomb + ItemType(etama3, 4, 11, hitbox_size=42, score=1000), #Full power + ItemType(etama3, 5, 12, hitbox_size=42), #1up + ItemType(etama3, 6, 13, hitbox_size=42, score=500)] #Star player00 = resource_loader.get_anm_wrapper(('player00.anm',)) player01 = resource_loader.get_anm_wrapper(('player01.anm',))
--- a/pytouhou/game/item.py +++ b/pytouhou/game/item.py @@ -15,9 +15,11 @@ from math import cos, sin, atan2, pi +from pytouhou.utils.interpolator import Interpolator + class Item(object): - def __init__(self, pos, item_type, angle, speed, player, game): + def __init__(self, start_pos, item_type, game, angle=pi/2, speed=8., player=None, end_pos=None): self._game = game self._sprite = item_type.sprite self._removed = False @@ -29,12 +31,22 @@ class Item(object): self.player = player - self.x, self.y = pos + self.x, self.y = start_pos self.angle = angle self.speed = speed dx, dy = cos(angle) * speed, sin(angle) * speed self.delta = dx, dy + if not player: + #TODO: find the formulae in the binary. + self.speed_interpolator = None + if end_pos: + self.pos_interpolator = Interpolator(start_pos, 0, + end_pos, 60) + else: + self.speed_interpolator = Interpolator((-2.,), 0, + (0.,), 60) + self._sprite.angle = angle @@ -46,12 +58,24 @@ class Item(object): def update(self): dx, dy = self.delta + if self.frame == 60: + self.speed_interpolator = Interpolator((0.,), 60, + (3.,), 180) + if self.player is not None: self.angle = atan2(self.player.y - self.y, self.player.x - self.x) - dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed + self.x += cos(self.angle) * self.speed + self.y += sin(self.angle) * self.speed + elif self.speed_interpolator is None: + self.pos_interpolator.update(self.frame) + self.x, self.y = self.pos_interpolator.values else: - pass #TODO: item falls! + self.speed_interpolator.update(self.frame) + self.speed, = self.speed_interpolator.values + dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed + self.delta = dx, dy + self.x += dx + self.y += dy - self.x += dx - self.y += dy + self.frame += 1
--- a/pytouhou/game/itemtype.py +++ b/pytouhou/game/itemtype.py @@ -1,12 +1,11 @@ from pytouhou.game.sprite import Sprite class ItemType(object): - def __init__(self, anm_wrapper, sprite_index, indicator_sprite_index, speed, - hitbox_size): + def __init__(self, anm_wrapper, sprite_index, indicator_sprite_index, hitbox_size, score=0): self.anm_wrapper = anm_wrapper self.sprite = Sprite() self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(sprite_index) self.indicator_sprite = Sprite() self.indicator_sprite.anm, self.indicator_sprite.texcoords = anm_wrapper.get_sprite(indicator_sprite_index) - self.speed = speed self.hitbox_size = hitbox_size + self.score = score