MCPcopy Create free account
hub / github.com/TanTanDev/rusty_demon_attack / update

Method update

src/player.rs:58–112  ·  view source on GitHub ↗
(
        &mut self,
        dt: f32,
        bullets: &mut Vec<Bullet>,
        resources: &Resources,
        sound_mixer: &mut SoundMixer,
    )

Source from the content-addressed store, hash-verified

56 }
57
58 pub fn update(
59 &mut self,
60 dt: f32,
61 bullets: &mut Vec<Bullet>,
62 resources: &Resources,
63 sound_mixer: &mut SoundMixer,
64 ) {
65 self.shoot_timer += dt;
66 if is_key_down(KEY_LEFT) {
67 self.pos.x -= PLAYER_SPEED * dt;
68 if self.pos.x < 0f32 {
69 self.pos.x = 0f32;
70 }
71 }
72 if is_key_down(KEY_RIGHT) {
73 self.pos.x += PLAYER_SPEED * dt;
74 if self.pos.x > GAME_SIZE_X as f32 - self.texture.width() {
75 self.pos.x = GAME_SIZE_X as f32 - self.texture.width();
76 }
77 }
78
79 // state specific update
80 let player_command_optional = match &mut self.state {
81 PlayerState::Normal => {
82 if is_key_down(KEY_SHOOT) && self.shoot_timer >= PLAYER_SHOOT_TIME {
83 let spawn_offset = vec2(3f32, -4f32);
84 bullets.push(Bullet::new(
85 self.pos + spawn_offset,
86 BulletHurtType::Enemy,
87 resources,
88 ));
89 resources.play_sound(
90 SoundIdentifier::PlayerShoot,
91 sound_mixer,
92 Volume(1.0f32),
93 );
94 self.shoot_timer = 0f32;
95 }
96 None
97 }
98 PlayerState::Invisible(time_left) => {
99 *time_left -= dt;
100 if *time_left <= 0.0f32 {
101 Some(PlayerCommand::ChangeState(PlayerState::Normal))
102 } else {
103 None
104 }
105 }
106 };
107
108 self.process_command_optional(player_command_optional);
109
110 self.collision_rect.x = self.pos.x;
111 self.collision_rect.y = self.pos.y;
112 }
113
114 pub fn process_command_optional(&mut self, command_optional: Option<PlayerCommand>) {
115 if let Some(player_command) = command_optional {

Callers

nothing calls this directly

Calls 2

play_soundMethod · 0.80

Tested by

no test coverage detected