1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-22 13:42:47 +00:00

Merge pull request #1 from yoroshikun/sprash

feat: add splash
This commit is contained in:
Julia K 2020-09-25 11:23:35 +02:00 committed by GitHub
commit 0636a949ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ use crate::common::{Direction, Rect};
use crate::entity::GameEntity;
use crate::frame::Frame;
use crate::ggez::{Context, GameResult};
use crate::npc::NPCMap;
use crate::shared_game_state::SharedGameState;
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive)]
@ -347,7 +348,36 @@ impl Player {
self.vel_x = clamp(self.vel_x, -max_move, max_move);
self.vel_y = clamp(self.vel_y, -max_move, max_move);
// todo: water splashing
if !self.splash && self.flags.in_water() {
let vertical_splash = !self.flags.hit_bottom_wall() && self.vel_y > 0x200;
let horizontal_splash = self.vel_x > 0x200 || self.vel_x < -0x200;
let should_splash = vertical_splash || horizontal_splash;
if should_splash {
for _ in 0..7 {
let mut droplet = NPCMap::create_npc(73, &state.npc_table);
droplet.cond.set_alive(true);
droplet.direction = if self.flags.water_splash_facing_right() { Direction::Right } else { Direction::Left };
droplet.x = self.x + (state.game_rng.range(-8..8) * 0x200) as isize;
droplet.y = self.y;
droplet.vel_x = if vertical_splash {
(self.vel_x + state.game_rng.range(-0x200..0x200) as isize) - (self.vel_x / 2)
} else if horizontal_splash {
self.vel_x + state.game_rng.range(-0x200..0x200) as isize
} else {
0 as isize
};
droplet.vel_y = state.game_rng.range(-0x200..0x80) as isize;
state.new_npcs.push(droplet);
}
state.sound_manager.play_sfx(56);
}
self.splash = true;
}
if !self.flags.in_water() {
self.splash = false;