Mercurial > touhou
annotate src/th06/enemy.rs @ 686:aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 17 Aug 2019 04:28:24 +0200 |
parents | c8bb28961d31 |
children | ac092b70c39a |
rev | line source |
---|---|
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 //! Module providing an Enemy struct, to be changed by EclRunner. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 use crate::th06::anm0::Anm0; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 use crate::th06::anm0_vm::{Sprite, AnmRunner}; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
5 use crate::th06::ecl::Rank; |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 use crate::th06::interpolator::{Interpolator1, Interpolator2}; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 use crate::util::prng::Prng; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 use std::cell::RefCell; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 use std::collections::HashMap; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 use std::rc::{Rc, Weak}; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
12 /// The 2D position of an object in the game. |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
13 #[derive(Debug, Clone, Copy, Default, PartialEq)] |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
14 pub struct Position { |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
15 pub(crate) x: f32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
16 pub(crate) y: f32, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
19 /// An offset which can be added to a Position. |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
20 #[derive(Debug, Clone, Copy, Default, PartialEq)] |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
21 pub struct Offset { |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 dx: f32, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 dy: f32, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 impl Position { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
27 /// Create said position. |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 pub fn new(x: f32, y: f32) -> Position { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 Position { x, y } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 impl Offset { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
34 /// Create said offset. |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 pub fn new(dx: f32, dy: f32) -> Offset { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 Offset { dx, dy } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 impl std::ops::Add<Offset> for Position { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 type Output = Position; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 fn add(self, offset: Offset) -> Position { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 Position { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 x: self.x + offset.dx, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 y: self.y + offset.dy, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 #[derive(Debug, Clone)] |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 struct Callback; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 #[derive(Debug, Clone)] |
684
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
54 /// XXX |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
55 pub struct Laser { |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
56 /// XXX |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
57 pub placeholder: u32 |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
58 } |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
60 #[derive(Debug, Clone, Default)] |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 struct Process; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
63 /// God struct of our game. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
64 pub struct Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
65 enemies: Vec<Rc<RefCell<Enemy>>>, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
66 anmrunners: Vec<Rc<RefCell<AnmRunner>>>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 prng: Rc<RefCell<Prng>>, |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
68 rank: Rank, |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
69 difficulty: i32, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
72 impl Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
73 /// Create said god struct. |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
74 pub fn new(prng: Rc<RefCell<Prng>>, rank: Rank) -> Game { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
75 Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
76 enemies: Vec::new(), |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
77 anmrunners: Vec::new(), |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
78 prng, |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
79 rank, |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
80 difficulty: 0, |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
81 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
82 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
83 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
84 /// Run the simulation for a single frame. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
85 pub fn run_frame(&mut self) { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
86 /* |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
87 for eclrunner in self.eclrunners { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
88 eclrunner.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
89 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
90 */ |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
91 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
92 for anmrunner in self.anmrunners.iter() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
93 let mut anmrunner = anmrunner.borrow_mut(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
94 anmrunner.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
95 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
96 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
97 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
98 /// Returns a list of all sprites currently being displayed on screen. |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
99 pub fn get_sprites(&self) -> Vec<(f32, f32, f32, Rc<RefCell<Sprite>>)> { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
100 let mut sprites = vec![]; |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
101 for enemy in self.enemies.iter() { |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
102 let enemy = enemy.borrow(); |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
103 let anmrunner = enemy.anmrunner.upgrade().unwrap(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
104 let anmrunner = anmrunner.borrow(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
105 let sprite = anmrunner.get_sprite(); |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
106 sprites.push((enemy.pos.x, enemy.pos.y, enemy.z, sprite)); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
107 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
108 sprites |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
109 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
110 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
111 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 /// Common to all elements in game. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 struct Element { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 pos: Position, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 removed: bool, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 anmrunner: AnmRunner, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
119 #[derive(PartialEq)] |
677
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
120 pub(crate) struct DifficultyCoeffs { |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
121 pub(crate) speed_a: f32, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
122 pub(crate) speed_b: f32, |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
123 pub(crate) nb_a: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
124 pub(crate) nb_b: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
125 pub(crate) shots_a: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
126 pub(crate) shots_b: i16, |
677
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
127 } |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
128 |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
129 impl Default for DifficultyCoeffs { |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
130 fn default() -> DifficultyCoeffs { |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
131 DifficultyCoeffs { |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
132 speed_a: -0.5, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
133 speed_b: 0.5, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
134 nb_a: 0, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
135 nb_b: 0, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
136 shots_a: 0, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
137 shots_b: 0, |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
138 } |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
139 } |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
140 } |
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
141 |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
142 #[derive(Debug, Clone, Default, PartialEq)] |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
143 pub(crate) struct BulletAttributes { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
144 pub(crate) anim: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
145 pub(crate) sprite_index_offset: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
146 pub(crate) pos: Position, // Doesn’t have a z field. |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
147 pub(crate) launch_angle: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
148 pub(crate) angle: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
149 pub(crate) speed: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
150 pub(crate) speed2: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
151 pub(crate) extended_attributes: (i32, i32, i32, i32, f32, f32, f32, f32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
152 // unknown: x32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
153 pub(crate) bullets_per_shot: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
154 pub(crate) number_of_shots: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
155 pub(crate) bullet_type: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
156 // zero: x32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
157 pub(crate) flags: u32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
158 pub(crate) ins84_param: i32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
159 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
160 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
161 impl BulletAttributes { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
162 /// Fire! |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
163 pub fn fire(&mut self) { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
164 println!("PAN!"); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
165 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
166 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
167 |
677
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
168 #[derive(PartialEq)] |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
169 pub(crate) enum Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
170 Left, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
171 Center, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
172 Right, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
173 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
174 |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
175 impl Default for Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
176 fn default() -> Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
177 Direction::Center |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
178 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
179 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
180 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 /// The enemy struct, containing everything pertaining to an enemy. |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
182 #[derive(Default)] |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 pub struct Enemy { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 // Common to all elements in game. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
185 pub(crate) pos: Position, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
186 pub(crate) removed: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
187 pub(crate) anmrunner: Weak<RefCell<AnmRunner>>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 // Specific to enemy. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 // Floats. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
191 pub(crate) z: f32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
192 pub(crate) angle: f32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
193 pub(crate) speed: f32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
194 pub(crate) rotation_speed: f32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
195 pub(crate) acceleration: f32, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 // Ints. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
198 pub(crate) type_: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
199 pub(crate) bonus_dropped: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
200 pub(crate) die_score: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
201 /// XXX |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
202 pub frame: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
203 pub(crate) life: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
204 pub(crate) death_flags: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
205 pub(crate) current_laser_id: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
206 pub(crate) low_life_trigger: Option<u32>, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
207 pub(crate) timeout: Option<u32>, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
208 pub(crate) remaining_lives: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
209 pub(crate) bullet_launch_interval: u32, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
210 pub(crate) bullet_launch_timer: u32, |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
211 pub(crate) death_anim: i32, |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
212 pub(crate) direction: Direction, |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
213 pub(crate) update_mode: u32, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 // Bools. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
216 pub(crate) visible: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
217 pub(crate) was_visible: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
218 pub(crate) touchable: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
219 pub(crate) collidable: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
220 pub(crate) damageable: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
221 pub(crate) boss: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
222 pub(crate) automatic_orientation: bool, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
223 pub(crate) delay_attack: bool, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 // Tuples. |
677
082c39d7d1c3
Use a struct for difficulty coeffs, so that we can impl Default on it.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
668
diff
changeset
|
226 pub(crate) difficulty_coeffs: DifficultyCoeffs, |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
227 pub(crate) bullet_attributes: BulletAttributes, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
228 pub(crate) bullet_offset: Offset, |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
229 pub(crate) movement_dependant_sprites: Option<(u8, u8, u8, u8)>, |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
230 pub(crate) screen_box: Option<(f32, f32, f32, f32)>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 // Callbacks. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 death_callback: Option<Callback>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 boss_callback: Option<Callback>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 low_life_callback: Option<Callback>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 timeout_callback: Option<Callback>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 // Laser. |
683
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
677
diff
changeset
|
239 pub(crate) laser_by_id: HashMap<u32, Laser>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 // Options. |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
242 // TODO: actually a 8 element array. |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 options: Vec<Element>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 // Interpolators. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
246 pub(crate) interpolator: Option<Interpolator2<f32>>, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
247 pub(crate) speed_interpolator: Option<Interpolator1<f32>>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 // Misc stuff, do we need them? |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
250 pub(crate) anm0: Weak<RefCell<Anm0>>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 process: Rc<RefCell<Process>>, |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
252 pub(crate) game: Weak<RefCell<Game>>, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
253 pub(crate) prng: Weak<RefCell<Prng>>, |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
254 pub(crate) hitbox_half_size: [f32; 2], |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 impl Enemy { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
258 /// Create a new enemy. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
259 pub fn new(pos: Position, life: i32, bonus_dropped: u32, die_score: u32, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<Enemy>> { |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
260 let game_rc = game.upgrade().unwrap(); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
261 let enemy = Enemy { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
262 pos, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
263 anm0, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
264 game, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
265 visible: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
266 bonus_dropped, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
267 die_score, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
268 life: if life < 0 { 1 } else { life as u32 }, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
269 touchable: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
270 collidable: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
271 damageable: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
272 ..Default::default() |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
273 }; |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
274 let enemy = Rc::new(RefCell::new(enemy)); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
275 game_rc.borrow_mut().enemies.push(enemy.clone()); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
276 enemy |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
277 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
278 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
279 /// Sets the animation to the one indexed by index in the current anm0. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
280 pub fn set_anim(&mut self, index: u8) { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
281 let anm0 = self.anm0.upgrade().unwrap(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
282 let game = self.game.upgrade().unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
283 let sprite = Rc::new(RefCell::new(Sprite::new())); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
284 let anmrunner = AnmRunner::new(&*anm0.borrow(), index, sprite, self.prng.clone(), 0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
285 let anmrunner = Rc::new(RefCell::new(anmrunner)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
286 self.anmrunner = Rc::downgrade(&anmrunner); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
287 (*game.borrow_mut()).anmrunners.push(anmrunner); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
288 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
289 |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
290 /// Sets the current position of the enemy. |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
291 pub fn set_pos(&mut self, x: f32, y: f32, z: f32) { |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
292 self.pos.x = x; |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
293 self.pos.y = y; |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
294 self.z = z; |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
295 } |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
296 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
297 /// Sets the hitbox around the enemy. |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
298 pub fn set_hitbox(&mut self, width: f32, height: f32) { |
668
140ee7de6d90
Use the correct half-size of the hitbox.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
667
diff
changeset
|
299 self.hitbox_half_size = [width / 2., height / 2.]; |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
300 } |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
301 |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
302 /// Defines the attributes for the next bullet fired, and fire it if delay_attack isn’t set! |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
303 pub fn set_bullet_attributes(&mut self, opcode: u16, anim: i16, sprite_index_offset: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
304 bullets_per_shot: i16, number_of_shots: i16, speed: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
305 speed2: f32, launch_angle: f32, angle: f32, flags: u32) { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
306 // Get the coeffs for the current difficulty. |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
307 let difficulty = self.get_difficulty() as i16; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
308 let coeff_nb = self.difficulty_coeffs.nb_a + (self.difficulty_coeffs.nb_b - self.difficulty_coeffs.nb_a) * difficulty / 32; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
309 let coeff_shots = self.difficulty_coeffs.shots_a + (self.difficulty_coeffs.shots_b - self.difficulty_coeffs.shots_a) * difficulty / 32; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
310 let coeff_speed = self.difficulty_coeffs.speed_a + (self.difficulty_coeffs.speed_b - self.difficulty_coeffs.speed_a) * difficulty as f32 / 32.; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
311 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
312 let opcode = 67; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
313 let mut bullet = &mut self.bullet_attributes; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
314 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
315 bullet.anim = anim; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
316 bullet.bullet_type = opcode - 67; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
317 bullet.sprite_index_offset = sprite_index_offset; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
318 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
319 bullet.bullets_per_shot = bullets_per_shot + coeff_nb; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
320 if bullet.bullets_per_shot < 1 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
321 bullet.bullets_per_shot = 1; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
322 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
323 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
324 bullet.number_of_shots = number_of_shots + coeff_shots; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
325 if bullet.number_of_shots < 1 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
326 bullet.number_of_shots = 1; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
327 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
328 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
329 bullet.pos = self.pos + self.bullet_offset; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
330 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
331 bullet.speed = speed + coeff_speed; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
332 if bullet.speed < 0.3 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
333 bullet.speed = 0.3; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
334 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
335 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
336 bullet.speed2 = speed2 + coeff_speed / 2.; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
337 if bullet.speed2 < 0.3 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
338 bullet.speed2 = 0.3; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
339 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
340 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
341 bullet.launch_angle = launch_angle.atan2(0.); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
342 bullet.angle = angle; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
343 bullet.flags = flags; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
344 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
345 if !self.delay_attack { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
346 bullet.fire(); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
347 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
348 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
349 |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
350 /// Run all interpolators and such, and update internal variables once per |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
351 /// frame. |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
352 pub fn update(&mut self) { |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
353 let Position { mut x, mut y } = self.pos; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
354 |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
355 let speed = if self.update_mode == 1 { |
667
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
356 let mut speed = 0.; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
357 if let Some(interpolator) = &self.interpolator { |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
358 let values = interpolator.values(self.frame as u16); |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
359 x = values[0]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
360 y = values[1]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
361 } |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
362 if let Some(interpolator) = &self.speed_interpolator { |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
363 let values = interpolator.values(self.frame as u16); |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
364 speed = values[0]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
365 } |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
366 speed |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
367 } else { |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
368 let speed = self.speed; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
369 self.speed += self.acceleration; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
370 self.angle += self.rotation_speed; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
371 speed |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
372 }; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
373 |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
374 let dx = self.angle.cos() * speed; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
375 let dy = self.angle.sin() * speed; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
376 if self.type_ & 2 != 0 { |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
377 x -= dx; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
378 } else { |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
379 x += dx; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
380 } |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
381 y += dy; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
382 |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
383 if let Some((end_left, end_right, left, right)) = self.movement_dependant_sprites { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
384 if x < self.pos.x && self.direction != Direction::Left { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
385 self.set_anim(left); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
386 self.direction = Direction::Left; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
387 } else if x > self.pos.x && self.direction != Direction::Right { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
388 self.set_anim(right); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
389 self.direction = Direction::Right; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
390 } else if x == self.pos.x && self.direction != Direction::Center { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
391 let anim = if self.direction == Direction::Left { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
392 end_left |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
393 } else { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
394 end_right |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
395 }; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
396 self.set_anim(anim); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
397 self.direction = Direction::Center; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
398 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
399 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
400 |
662
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
401 self.pos = Position { x, y }; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
402 |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
403 self.frame += 1; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
404 } |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
405 |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
406 pub(crate) fn get_rank(&self) -> Rank { |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
407 let game = self.game.upgrade().unwrap(); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
408 let game = game.borrow(); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
409 game.rank |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
410 } |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
411 |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
412 pub(crate) fn get_difficulty(&self) -> i32 { |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
413 let game = self.game.upgrade().unwrap(); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
414 let game = game.borrow(); |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
415 game.difficulty |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
416 } |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
417 } |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
418 |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
419 trait Renderable { |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
420 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>>; |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
421 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
422 |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
423 impl Renderable for Enemy { |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
424 fn get_sprites(&self) -> Vec<Rc<RefCell<Sprite>>> { |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
425 let anmrunner = self.anmrunner.upgrade().unwrap(); |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
426 let anmrunner = anmrunner.borrow(); |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
427 vec![anmrunner.get_sprite()] |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
428 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
429 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
430 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
431 #[cfg(test)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
432 mod tests { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
433 use super::*; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
434 use std::io::{self, Read}; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
435 use std::fs::File; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
436 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
437 #[test] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
438 fn enemy() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
439 let file = File::open("EoSD/ST/stg1enm.anm").unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
440 let mut file = io::BufReader::new(file); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
441 let mut buf = vec![]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
442 file.read_to_end(&mut buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
443 let anm0 = Anm0::from_slice(&buf).unwrap(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
444 let anm0 = Rc::new(RefCell::new(anm0)); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
445 let prng = Rc::new(RefCell::new(Prng::new(0))); |
665
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
446 let game = Game::new(prng, Rank::Easy); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
447 let game = Rc::new(RefCell::new(game)); |
665
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
448 let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
449 let mut enemy = enemy.borrow_mut(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
450 assert!(enemy.anmrunner.upgrade().is_none()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
451 enemy.set_anim(0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
452 assert!(enemy.anmrunner.upgrade().is_some()); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
453 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
454 } |