Mercurial > touhou
comparison src/th06/enemy.rs @ 693:14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 17 Aug 2019 15:33:45 +0200 |
parents | a35df65e0d57 |
children | 05e0425a8bc5 |
comparison
equal
deleted
inserted
replaced
692:a35df65e0d57 | 693:14fddc27e6f5 |
---|---|
45 y: self.y + offset.dy, | 45 y: self.y + offset.dy, |
46 } | 46 } |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 impl std::ops::Sub<Position> for Position { | |
51 type Output = Offset; | |
52 fn sub(self, other: Position) -> Offset { | |
53 Offset { | |
54 dx: other.x - self.x, | |
55 dy: other.y - self.y, | |
56 } | |
57 } | |
58 } | |
59 | |
50 #[derive(Debug, Clone)] | 60 #[derive(Debug, Clone)] |
51 struct Callback; | 61 struct Callback; |
52 | 62 |
53 #[derive(Debug, Clone)] | 63 #[derive(Debug, Clone)] |
54 /// XXX | 64 /// XXX |
58 } | 68 } |
59 | 69 |
60 #[derive(Debug, Clone, Default)] | 70 #[derive(Debug, Clone, Default)] |
61 struct Process; | 71 struct Process; |
62 | 72 |
73 /// Struct representing the player. | |
74 pub struct Player { | |
75 pos: Position, | |
76 } | |
77 | |
63 /// God struct of our game. | 78 /// God struct of our game. |
64 pub struct Game { | 79 pub struct Game { |
65 enemies: Vec<Rc<RefCell<Enemy>>>, | 80 enemies: Vec<Rc<RefCell<Enemy>>>, |
66 anmrunners: Vec<Rc<RefCell<AnmRunner>>>, | 81 anmrunners: Vec<Rc<RefCell<AnmRunner>>>, |
82 player: Rc<RefCell<Player>>, | |
67 prng: Rc<RefCell<Prng>>, | 83 prng: Rc<RefCell<Prng>>, |
68 rank: Rank, | 84 rank: Rank, |
69 difficulty: i32, | 85 difficulty: i32, |
70 } | 86 } |
71 | 87 |
73 /// Create said god struct. | 89 /// Create said god struct. |
74 pub fn new(prng: Rc<RefCell<Prng>>, rank: Rank) -> Game { | 90 pub fn new(prng: Rc<RefCell<Prng>>, rank: Rank) -> Game { |
75 Game { | 91 Game { |
76 enemies: Vec::new(), | 92 enemies: Vec::new(), |
77 anmrunners: Vec::new(), | 93 anmrunners: Vec::new(), |
94 player: Rc::new(RefCell::new(Player { pos: Position { x: 192., y: 384. } })), | |
78 prng, | 95 prng, |
79 rank, | 96 rank, |
80 difficulty: 0, | 97 difficulty: 0, |
81 } | 98 } |
82 } | 99 } |
104 let anmrunner = anmrunner.borrow(); | 121 let anmrunner = anmrunner.borrow(); |
105 let sprite = anmrunner.get_sprite(); | 122 let sprite = anmrunner.get_sprite(); |
106 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite)); | 123 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite)); |
107 } | 124 } |
108 sprites | 125 sprites |
126 } | |
127 | |
128 pub(crate) fn get_player(&self) -> Rc<RefCell<Player>> { | |
129 self.player.clone() | |
109 } | 130 } |
110 } | 131 } |
111 | 132 |
112 /// Common to all elements in game. | 133 /// Common to all elements in game. |
113 struct Element { | 134 struct Element { |
438 pub(crate) fn get_difficulty(&self) -> i32 { | 459 pub(crate) fn get_difficulty(&self) -> i32 { |
439 let game = self.game.upgrade().unwrap(); | 460 let game = self.game.upgrade().unwrap(); |
440 let game = game.borrow(); | 461 let game = game.borrow(); |
441 game.difficulty | 462 game.difficulty |
442 } | 463 } |
464 | |
465 // TODO: use a trait for positionable entities. | |
466 pub(crate) fn get_angle_to(&self, player: Rc<RefCell<Player>>) -> f32 { | |
467 let player = player.borrow(); | |
468 let offset = self.pos - player.pos; | |
469 offset.dy.atan2(offset.dx) | |
470 } | |
443 } | 471 } |
444 | 472 |
445 trait Renderable { | 473 trait Renderable { |
446 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>>; | 474 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>>; |
447 } | 475 } |