Mercurial > touhou
comparison pytouhou/game/item.py @ 150:4f46717390aa
Introduce items, implement ECL instruction 83
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 04 Oct 2011 23:09:41 +0200 |
parents | |
children | 5cf927cbd9c5 |
comparison
equal
deleted
inserted
replaced
149:3673d55a8448 | 150:4f46717390aa |
---|---|
1 # -*- encoding: utf-8 -*- | |
2 ## | |
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
15 | |
16 from math import cos, sin, atan2, pi | |
17 | |
18 | |
19 class Item(object): | |
20 def __init__(self, pos, item_type, angle, speed, player, game_state): | |
21 self._game_state = game_state | |
22 self._sprite = item_type.sprite | |
23 self._removed = False | |
24 self._item_type = item_type | |
25 | |
26 self.hitbox_half_size = item_type.hitbox_size / 2. | |
27 | |
28 self.frame = 0 | |
29 | |
30 self.player = player | |
31 | |
32 self.x, self.y = pos | |
33 self.angle = angle | |
34 self.speed = speed | |
35 dx, dy = cos(angle) * speed, sin(angle) * speed | |
36 self.delta = dx, dy | |
37 | |
38 self._sprite.angle = angle | |
39 | |
40 | |
41 def update(self): | |
42 dx, dy = self.delta | |
43 | |
44 if self.player is not None: | |
45 self.angle = atan2(self.player.y - self.y, self.player.x - self.x) | |
46 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed | |
47 else: | |
48 pass #TODO: item falls! | |
49 | |
50 self.x += dx | |
51 self.y += dy | |
52 |