Mercurial > touhou
annotate src/th06/enemy.rs @ 740:8d29dac12219
examples: Make the common functions take AsRef<Path>.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 06 Jan 2020 22:48:09 +0100 |
parents | 817c453b7223 |
children | 3555845f8cf4 |
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 { |
690
eecb8626f472
ecl_vm: implement SetBulletLaunchOffset.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
689
diff
changeset
|
22 pub(crate) dx: f32, |
eecb8626f472
ecl_vm: implement SetBulletLaunchOffset.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
689
diff
changeset
|
23 pub(crate) dy: f32, |
657
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 |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
50 impl std::ops::Sub<Position> for Position { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
51 type Output = Offset; |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
52 fn sub(self, other: Position) -> Offset { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
53 Offset { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
54 dx: other.x - self.x, |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
55 dy: other.y - self.y, |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
56 } |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
57 } |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
58 } |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
59 |
698
05e0425a8bc5
ecl_vm: enable SetDeathCallback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
693
diff
changeset
|
60 type Callback = i32; |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 #[derive(Debug, Clone)] |
684
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
63 /// XXX |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
64 pub struct Laser { |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
65 /// XXX |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
66 pub placeholder: u32 |
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
67 } |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
69 #[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
|
70 struct Process; |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
72 /// Struct representing the player. |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
73 pub struct Player { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
74 pos: Position, |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
75 } |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
76 |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
77 /// Struct representing an enemy bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
78 pub struct Bullet { |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
79 /// Current position of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
80 pub pos: Position, |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
81 |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
82 /// Current speed of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
83 pub speed: f32, |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
84 |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
85 /// Current XXX of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
86 pub dpos: [f32; 3], |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
87 |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
88 /// Current XXX of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
89 pub flags: u32, |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
90 |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
91 /// Current frame of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
92 pub frame: i32, |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
93 |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
94 /// Current attributes of the bullet. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
95 pub attributes: [f32; 2], |
737
0977d479e37d
ecl_vm: Uncomment instruction 121 function 8.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
735
diff
changeset
|
96 |
0977d479e37d
ecl_vm: Uncomment instruction 121 function 8.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
735
diff
changeset
|
97 /// TODO: what are the values? |
0977d479e37d
ecl_vm: Uncomment instruction 121 function 8.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
735
diff
changeset
|
98 pub state: i8, |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
99 } |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
100 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
101 /// 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
|
102 pub struct Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
103 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
|
104 anmrunners: Vec<Rc<RefCell<AnmRunner>>>, |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
105 pub(crate) bullets: Vec<Rc<RefCell<Bullet>>>, |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
106 player: Rc<RefCell<Player>>, |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
107 pub(crate) 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
|
108 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
|
109 difficulty: i32, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
112 impl Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
113 /// 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
|
114 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
|
115 Game { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
116 enemies: Vec::new(), |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
117 anmrunners: Vec::new(), |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
118 bullets: Vec::new(), |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
119 player: Rc::new(RefCell::new(Player { pos: Position { x: 192., y: 384. } })), |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
120 prng, |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
121 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
|
122 difficulty: 0, |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
123 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
124 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
125 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
126 /// 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
|
127 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
|
128 /* |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
129 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
|
130 eclrunner.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
131 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
132 */ |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
133 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
134 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
|
135 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
|
136 anmrunner.run_frame(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
137 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
138 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
139 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
140 /// 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 let anmrunner = anmrunner.borrow(); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
147 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
|
148 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
|
149 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
150 sprites |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
151 } |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
152 |
718
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
153 // TODO: Fix this function so we can stop making Game::bullets pub. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
154 /* |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
155 /// Apply a function on all bullets. |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
156 pub fn iter_bullets(&mut self, mut f: impl FnMut(Bullet)) { |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
157 self.bullets.iter().map(|bullet| { |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
158 let mut bullet = bullet.borrow_mut(); |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
159 f(*bullet) |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
160 }); |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
161 } |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
162 */ |
c187e0a6b751
ecl_vm: Implement 121 functions 0 and 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
709
diff
changeset
|
163 |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
164 pub(crate) fn get_player(&self) -> Rc<RefCell<Player>> { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
165 self.player.clone() |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
166 } |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
167 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
168 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 /// 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
|
170 struct Element { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 pos: Position, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 removed: bool, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 anmrunner: AnmRunner, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
176 #[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
|
177 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
|
178 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
|
179 pub(crate) speed_b: f32, |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
180 pub(crate) nb_a: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
181 pub(crate) nb_b: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
182 pub(crate) shots_a: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
183 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
|
184 } |
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
|
185 |
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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 } |
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
|
196 } |
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
|
197 } |
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
|
198 |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
199 #[derive(Debug, Clone, Default, PartialEq)] |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
200 pub(crate) struct BulletAttributes { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
201 pub(crate) anim: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
202 pub(crate) sprite_index_offset: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
203 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
|
204 pub(crate) launch_angle: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
205 pub(crate) angle: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
206 pub(crate) speed: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
207 pub(crate) speed2: f32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
208 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
|
209 // unknown: x32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
210 pub(crate) bullets_per_shot: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
211 pub(crate) number_of_shots: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
212 pub(crate) bullet_type: i16, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
213 // zero: x32, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
214 pub(crate) flags: u32, |
728
414f8611f344
ecl: Add support for bullet sounds, instruction 84.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
718
diff
changeset
|
215 |
414f8611f344
ecl: Add support for bullet sounds, instruction 84.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
718
diff
changeset
|
216 /// Which sound to play when the bullet gets fired. |
414f8611f344
ecl: Add support for bullet sounds, instruction 84.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
718
diff
changeset
|
217 pub sound: Option<u8>, |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
218 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
219 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
220 impl BulletAttributes { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
221 /// Fire! |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
222 pub fn fire(&mut self) { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
223 println!("PAN!"); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
224 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
225 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
226 |
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
|
227 #[derive(PartialEq)] |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
228 pub(crate) enum Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
229 Left, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
230 Center, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
231 Right, |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
232 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
233 |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
234 impl Default for Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
235 fn default() -> Direction { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
236 Direction::Center |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
237 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
238 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
239 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 /// 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
|
241 #[derive(Default)] |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 pub struct Enemy { |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 // 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
|
244 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
|
245 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
|
246 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
|
247 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 // Specific to enemy. |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 // 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 // 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
|
257 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
|
258 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
|
259 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
|
260 /// 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 pub(crate) remaining_lives: u32, |
688
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
268 bullet_launch_interval: u32, |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
269 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
|
270 pub(crate) death_anim: i32, |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
271 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
|
272 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
|
273 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 // 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 pub(crate) delay_attack: bool, |
738
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
283 // Actually part of type_ atm. |
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
284 pub(crate) mirror: bool, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
286 // 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
|
287 pub(crate) difficulty_coeffs: DifficultyCoeffs, |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
288 pub(crate) bullet_attributes: BulletAttributes, |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
289 pub(crate) bullet_offset: Offset, |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
290 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
|
291 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
|
292 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 // Callbacks. |
698
05e0425a8bc5
ecl_vm: enable SetDeathCallback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
693
diff
changeset
|
294 pub(crate) death_callback: Option<Callback>, |
05e0425a8bc5
ecl_vm: enable SetDeathCallback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
693
diff
changeset
|
295 pub(crate) boss_callback: Option<Callback>, |
05e0425a8bc5
ecl_vm: enable SetDeathCallback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
693
diff
changeset
|
296 pub(crate) low_life_callback: Option<Callback>, |
05e0425a8bc5
ecl_vm: enable SetDeathCallback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
693
diff
changeset
|
297 pub(crate) timeout_callback: Option<Callback>, |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 // Laser. |
683
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
677
diff
changeset
|
300 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
|
301 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 // Options. |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
303 // 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
|
304 options: Vec<Element>, |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 // 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
|
307 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
|
308 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
|
309 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 // 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 } |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
317 |
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 impl Enemy { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
319 /// Create a new enemy. |
738
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
320 pub fn new(pos: Position, life: i16, bonus_dropped: i16, die_score: u32, mirror: bool, anm0: Weak<RefCell<Anm0>>, game: Weak<RefCell<Game>>) -> Rc<RefCell<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
|
321 let game_rc = game.upgrade().unwrap(); |
687
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
322 let mut enemy = Enemy { |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
323 pos, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
324 anm0, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
325 game, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
326 visible: true, |
738
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
327 // XXX: shouldn’t be u32, since that can be -1. |
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
328 bonus_dropped: bonus_dropped as u32, |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
329 die_score, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
330 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
|
331 touchable: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
332 collidable: true, |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
333 damageable: true, |
738
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
334 mirror, |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
335 ..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
|
336 }; |
687
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
337 let mut game = game_rc.borrow_mut(); |
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
338 enemy.prng = Rc::downgrade(&game.prng); |
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
|
339 let enemy = Rc::new(RefCell::new(enemy)); |
687
ac092b70c39a
Fix PRNG not to panic, pass it to Enemy, and initialise it with time in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
340 game.enemies.push(enemy.clone()); |
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
|
341 enemy |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
342 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
343 |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 /// 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 (*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
|
353 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
354 |
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
|
355 /// 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 } |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
361 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
362 /// 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
|
363 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
|
364 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
|
365 } |
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
|
366 |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
367 /// 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
|
368 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
|
369 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
|
370 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
|
371 // Get the coeffs for the current difficulty. |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
372 let difficulty = self.get_difficulty() as i16; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
373 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
|
374 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
|
375 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
|
376 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
377 let opcode = 67; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
378 let mut bullet = &mut self.bullet_attributes; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
379 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
380 bullet.anim = anim; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
381 bullet.bullet_type = opcode - 67; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
382 bullet.sprite_index_offset = sprite_index_offset; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
383 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
384 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
|
385 if bullet.bullets_per_shot < 1 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
386 bullet.bullets_per_shot = 1; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
387 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
388 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
389 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
|
390 if bullet.number_of_shots < 1 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
391 bullet.number_of_shots = 1; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
392 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
393 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
394 bullet.pos = self.pos + self.bullet_offset; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
395 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
396 bullet.speed = speed + coeff_speed; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
397 if bullet.speed < 0.3 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
398 bullet.speed = 0.3; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
399 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
400 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
401 bullet.speed2 = speed2 + coeff_speed / 2.; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
402 if bullet.speed2 < 0.3 { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
403 bullet.speed2 = 0.3; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
404 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
405 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
406 bullet.launch_angle = launch_angle.atan2(0.); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
407 bullet.angle = angle; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
408 bullet.flags = flags; |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
409 |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
410 if !self.delay_attack { |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
411 bullet.fire(); |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
412 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
413 } |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
684
diff
changeset
|
414 |
688
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
415 /// Sets the bullet launch interval. |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
416 pub(crate) fn set_bullet_launch_interval(&mut self, rand_start: u32, interval: i32) { |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
417 let coeff_interval = interval / 5; |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
418 let difficulty_modifier = coeff_interval + (-coeff_interval * 2) * self.get_difficulty() / 32; |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
419 self.bullet_launch_interval = (interval + difficulty_modifier) as u32; |
689
482d81f50a11
ecl_vm: fix panic when bullet_interval is zero (disabled).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
688
diff
changeset
|
420 if self.bullet_launch_interval > 0 { |
482d81f50a11
ecl_vm: fix panic when bullet_interval is zero (disabled).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
688
diff
changeset
|
421 self.bullet_launch_timer = rand_start % self.bullet_launch_interval; |
482d81f50a11
ecl_vm: fix panic when bullet_interval is zero (disabled).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
688
diff
changeset
|
422 } |
688
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
423 } |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
424 |
692
a35df65e0d57
ecl_vm: stub PlaySound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
690
diff
changeset
|
425 /// Stubbed for now. |
a35df65e0d57
ecl_vm: stub PlaySound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
690
diff
changeset
|
426 pub(crate) fn play_sound(&self, sound_index: i32) { |
a35df65e0d57
ecl_vm: stub PlaySound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
690
diff
changeset
|
427 println!("Playing sound {}!", sound_index); |
a35df65e0d57
ecl_vm: stub PlaySound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
690
diff
changeset
|
428 } |
a35df65e0d57
ecl_vm: stub PlaySound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
690
diff
changeset
|
429 |
699
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
430 /// Stubbed for now. |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
431 pub(crate) fn set_boss(&self, enable: bool) { |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
432 match enable { |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
433 true => println!("Enemy is now boss!"), |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
434 false => println!("Enemy is not boss anymore."), |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
435 } |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
436 } |
2a60f12bd5bd
ecl_vm: stub SetBossMode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
698
diff
changeset
|
437 |
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
|
438 /// 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
|
439 /// 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
|
440 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
|
441 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
|
442 |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
443 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
|
444 let mut speed = 0.; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
445 if let Some(interpolator) = &self.interpolator { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
446 let values = interpolator.values(self.frame); |
667
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
447 x = values[0]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
448 y = values[1]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
449 } |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
450 if let Some(interpolator) = &self.speed_interpolator { |
709
6d4802abe134
Make interpolators use u32 instead of u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
451 let values = interpolator.values(self.frame); |
667
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
452 speed = values[0]; |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
453 } |
904849807fd8
Implement update_mode 1 on enemy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
666
diff
changeset
|
454 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
|
455 } 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 }; |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
461 |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
462 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
|
463 let dy = self.angle.sin() * speed; |
738
817c453b7223
stagerunner: Add a binary able to run multiple enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
737
diff
changeset
|
464 if self.mirror { |
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
|
465 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
|
466 } 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
|
467 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
|
468 } |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
469 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
|
470 |
666
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
471 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
|
472 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
|
473 self.set_anim(left); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
474 self.direction = Direction::Left; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
475 } 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
|
476 self.set_anim(right); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
477 self.direction = Direction::Right; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
478 } 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
|
479 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
|
480 end_left |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
481 } else { |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
482 end_right |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
483 }; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
484 self.set_anim(anim); |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
485 self.direction = Direction::Center; |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
486 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
487 } |
838d9402b12f
Implement ECL instruction 98, for directional sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
488 |
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
|
489 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
|
490 |
688
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
491 if self.bullet_launch_interval != 0 { |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
492 if self.bullet_launch_timer == 0 { |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
493 self.bullet_attributes.fire(); |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
494 self.bullet_launch_timer = self.bullet_launch_interval; |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
495 } |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
496 self.bullet_launch_timer += 1; |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
497 self.bullet_launch_timer %= self.bullet_launch_interval; |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
498 } |
1adecaddf442
ecl_vm: implement SetBulletInterval and SetBulletIntervalEx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
687
diff
changeset
|
499 |
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
|
500 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
|
501 } |
107bb5ca5cc8
Implement Enemy::update(), which now renders the first fairy from stage 1 perfectly!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
502 |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
662
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 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
|
507 } |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
508 |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
658
diff
changeset
|
509 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
|
510 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
|
511 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
|
512 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
|
513 } |
693
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
514 |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
515 // TODO: use a trait for positionable entities. |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
516 pub(crate) fn get_angle_to(&self, player: Rc<RefCell<Player>>) -> f32 { |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
517 let player = player.borrow(); |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
518 let offset = self.pos - player.pos; |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
519 offset.dy.atan2(offset.dx) |
14fddc27e6f5
ecl_vm: implement TargetPlayer, and add a dummy Player to Game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
692
diff
changeset
|
520 } |
735
b9928db975e1
ecl: Enable instruction 99.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
521 |
b9928db975e1
ecl: Enable instruction 99.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
522 pub(crate) fn set_aux_anm(&self, number: i32, script: i32) { |
b9928db975e1
ecl: Enable instruction 99.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
523 println!("TODO: Spawn aux anm {} with script {}.", number, script); |
b9928db975e1
ecl: Enable instruction 99.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
524 } |
657
ff7b6355cdf1
Port the Enemy struct from Python, for now without its methods.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
525 } |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
526 |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
527 trait Renderable { |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
528 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
|
529 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
530 |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
531 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
|
532 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
|
533 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
|
534 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
|
535 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
|
536 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
537 } |
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
538 |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
539 #[cfg(test)] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
540 mod tests { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
541 use super::*; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
542 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
|
543 use std::fs::File; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
544 |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
545 #[test] |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
546 fn enemy() { |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
547 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
|
548 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
|
549 let mut buf = vec![]; |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
550 file.read_to_end(&mut buf).unwrap(); |
701
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
699
diff
changeset
|
551 let (_, mut anms) = Anm0::from_slice(&buf).unwrap(); |
b6c351ca0a35
anm0: return the nom IResult and the list of Anm0s.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
699
diff
changeset
|
552 let anm0 = anms.pop().unwrap(); |
658
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
553 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
|
554 let prng = Rc::new(RefCell::new(Prng::new(0))); |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
701
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 enemy.set_anim(0); |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
561 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
|
562 } |
3a9d82a02c88
Add a contructor for enemy, and a new example.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
657
diff
changeset
|
563 } |