comparison src/th06/enemy.rs @ 718:c187e0a6b751

ecl_vm: Implement 121 functions 0 and 1.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 24 Sep 2019 17:49:23 +0200
parents 6d4802abe134
children 414f8611f344
comparison
equal deleted inserted replaced
717:d5d5496e4e53 718:c187e0a6b751
72 /// Struct representing the player. 72 /// Struct representing the player.
73 pub struct Player { 73 pub struct Player {
74 pos: Position, 74 pos: Position,
75 } 75 }
76 76
77 /// Struct representing an enemy bullet.
78 pub struct Bullet {
79 /// Current position of the bullet.
80 pub pos: Position,
81
82 /// Current speed of the bullet.
83 pub speed: f32,
84
85 /// Current XXX of the bullet.
86 pub dpos: [f32; 3],
87
88 /// Current XXX of the bullet.
89 pub flags: u32,
90
91 /// Current frame of the bullet.
92 pub frame: i32,
93
94 /// Current attributes of the bullet.
95 pub attributes: [f32; 2],
96 }
97
77 /// God struct of our game. 98 /// God struct of our game.
78 pub struct Game { 99 pub struct Game {
79 enemies: Vec<Rc<RefCell<Enemy>>>, 100 enemies: Vec<Rc<RefCell<Enemy>>>,
80 anmrunners: Vec<Rc<RefCell<AnmRunner>>>, 101 anmrunners: Vec<Rc<RefCell<AnmRunner>>>,
102 pub(crate) bullets: Vec<Rc<RefCell<Bullet>>>,
81 player: Rc<RefCell<Player>>, 103 player: Rc<RefCell<Player>>,
82 prng: Rc<RefCell<Prng>>, 104 pub(crate) prng: Rc<RefCell<Prng>>,
83 rank: Rank, 105 rank: Rank,
84 difficulty: i32, 106 difficulty: i32,
85 } 107 }
86 108
87 impl Game { 109 impl Game {
88 /// Create said god struct. 110 /// Create said god struct.
89 pub fn new(prng: Rc<RefCell<Prng>>, rank: Rank) -> Game { 111 pub fn new(prng: Rc<RefCell<Prng>>, rank: Rank) -> Game {
90 Game { 112 Game {
91 enemies: Vec::new(), 113 enemies: Vec::new(),
92 anmrunners: Vec::new(), 114 anmrunners: Vec::new(),
115 bullets: Vec::new(),
93 player: Rc::new(RefCell::new(Player { pos: Position { x: 192., y: 384. } })), 116 player: Rc::new(RefCell::new(Player { pos: Position { x: 192., y: 384. } })),
94 prng, 117 prng,
95 rank, 118 rank,
96 difficulty: 0, 119 difficulty: 0,
97 } 120 }
121 let sprite = anmrunner.get_sprite(); 144 let sprite = anmrunner.get_sprite();
122 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite)); 145 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite));
123 } 146 }
124 sprites 147 sprites
125 } 148 }
149
150 // TODO: Fix this function so we can stop making Game::bullets pub.
151 /*
152 /// Apply a function on all bullets.
153 pub fn iter_bullets(&mut self, mut f: impl FnMut(Bullet)) {
154 self.bullets.iter().map(|bullet| {
155 let mut bullet = bullet.borrow_mut();
156 f(*bullet)
157 });
158 }
159 */
126 160
127 pub(crate) fn get_player(&self) -> Rc<RefCell<Player>> { 161 pub(crate) fn get_player(&self) -> Rc<RefCell<Player>> {
128 self.player.clone() 162 self.player.clone()
129 } 163 }
130 } 164 }