Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juicing musket #179

Merged
merged 9 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/Whale/Bullet(15x15).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/fxses/bullet_smoke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"local_coords":false,"emission_shape":"Point","one_shot":true,"lifetime":0.3,"lifetime_randomness":0,"explosiveness":1,"amount":20,"shape":{"Circle":{"subdivisions":12}},"emitting":false,"initial_direction":{"x":0,"y":-1},"initial_direction_spread":6.2831855,"initial_velocity":54.3,"initial_velocity_randomness":0.2,"linear_accel":0,"size":5.6000004,"size_randomness":0.2,"size_curve":{"points":[[0,1.6],[1,0]],"interpolation":"Linear","resolution":30},"blend_mode":"Alpha","colors_curve":{"start":{"r":0.47727272,"g":0.47727272,"b":0.47727272,"a":1},"mid":{"r":0.59090906,"g":0.59090906,"b":0.59090906,"a":1},"end":{"r":0.9,"g":0.9,"b":0.9,"a":1}},"gravity":{"x":0,"y":0},"post_processing":{}}
1 change: 1 addition & 0 deletions assets/fxses/gun_smoke.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"local_coords":false,"emission_shape":"Point","one_shot":true,"lifetime":0.7999999,"lifetime_randomness":0,"explosiveness":1,"amount":1,"shape":{"Circle":{"subdivisions":16}},"emitting":false,"initial_direction":{"x":0,"y":-1},"initial_direction_spread":0.3,"initial_velocity":54.300003,"initial_velocity_randomness":0.4,"linear_accel":-0.89999986,"size":2.9,"size_randomness":0,"size_curve":{"points":[[0,0.88],[0.49,1.88],[1,0]],"interpolation":"Linear","resolution":30},"blend_mode":"Alpha","colors_curve":{"start":{"r":0.6818182,"g":0.6818182,"b":0.6818182,"a":1},"mid":{"r":0.70454544,"g":0.70454544,"b":0.70454544,"a":1},"end":{"r":0.84090906,"g":0.84090906,"b":0.84090906,"a":1}},"gravity":{"x":0,"y":-54.1},"post_processing":{}}
5 changes: 4 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ pub const ITEMS: &[Item] = &[
tiled_name: "musket",
constructor: gun::Gun::spawn_musket,
tiled_offset: (-35., -25.),
textures: &[("gun", "assets/Whale/Gun(92x32).png")],
textures: &[
("gun", "assets/Whale/Gun(92x32).png"),
("bullet", "assets/Whale/Bullet(15x15).png"),
],
sounds: &[],
fxses: &[],
network_ready: true,
Expand Down
89 changes: 78 additions & 11 deletions src/items/gun.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use macroquad::{
audio::play_sound_once,
color,
experimental::{
animation::{AnimatedSprite, Animation},
collections::storage,
coroutines::{start_coroutine, wait_seconds, Coroutine},
scene::{self, Handle, HandleUntyped, RefMut},
Expand All @@ -20,6 +22,9 @@ pub struct Gun {
pub gun_fx_sprite: GunlikeAnimation,
pub gun_fx: bool,

pub smoke_fx_counter: i8,
pub smoke_fx_timer: f32,

pub max_bullets: i32,
pub bullets: i32,
pub bullet_speed: f32,
Expand Down Expand Up @@ -79,9 +84,8 @@ impl Gun {

scene::add_node(GunBullet::new(
node.body.pos + vec2(16.0, 15.0) + node.body.facing_dir() * 32.0,
node.body.facing,
4.,
node.bullet_speed,
node.body.facing,
));
player.body.speed.x = -node.recoil * player.body.facing_dir().x;
}
Expand Down Expand Up @@ -239,6 +243,28 @@ impl scene::Node for Gun {
fn fixed_update(mut node: RefMut<Self>) {
let node = &mut *node;

if !node.throwable.thrown() {
if !node.gun_fx {
if node.smoke_fx_counter < 5 {
if node.smoke_fx_timer > 0.15 {
node.smoke_fx_timer = 0.1;
node.smoke_fx_counter += 1;
{
let mut resources = storage::get_mut::<Resources>();

resources.fx_gun_smoke.spawn(
node.body.pos + vec2(16.0, 15.0) + node.body.facing_dir() * 32.0,
);
}
}
node.smoke_fx_timer += get_frame_time()
}
} else {
node.smoke_fx_timer = 0.0;
node.smoke_fx_counter = 0;
}
}

node.gun_sprite.update();
node.gun_fx_sprite.update();
node.throwable.update(&mut node.body, true);
Expand All @@ -247,14 +273,17 @@ impl scene::Node for Gun {

pub struct GunBullet {
bullet: Bullet,
size: f32,
sprite: AnimatedSprite,
angle: f32,
facing: bool,
smoke_fx_timer: f32,
}

impl GunBullet {
pub const BULLET_LIFETIME: f32 = 0.9;
pub const BULLET_SPREAD: f32 = 0.0;

pub fn new(pos: Vec2, facing: bool, size: f32, speed: f32) -> GunBullet {
pub fn new(pos: Vec2, speed: f32, facing: bool) -> GunBullet {
GunBullet {
bullet: Bullet::new(
pos,
Expand All @@ -263,7 +292,20 @@ impl GunBullet {
speed,
Self::BULLET_SPREAD,
),
size,
sprite: AnimatedSprite::new(
15,
15,
&[Animation {
name: "idle".to_string(),
row: 0,
frames: 1,
fps: 1,
}],
true,
),
angle: rand::gen_range(0.0, 6.28),
facing,
smoke_fx_timer: 0.0,
}
}
}
Expand Down Expand Up @@ -292,12 +334,37 @@ impl scene::Node for GunBullet {
node.provides(Self::network_capabilities());
}

fn draw(node: RefMut<Self>) {
draw_circle(
node.bullet.pos.x,
node.bullet.pos.y,
node.size,
Color::new(1.0, 1.0, 0.8, 1.0),
fn draw(mut node: RefMut<Self>) {
node.sprite.update();

let resources = storage::get::<Resources>();

let frame = node.sprite.frame();
draw_texture_ex(
resources.items_textures["musket/bullet"],
node.bullet.pos.x - frame.source_rect.h / 2.0,
node.bullet.pos.y - frame.source_rect.w / 2.0,
color::WHITE,
DrawTextureParams {
source: Some(frame.source_rect),
dest_size: Some(frame.dest_size),
flip_x: !node.facing,
rotation: node.angle,
..Default::default()
},
);
}

fn fixed_update(mut node: RefMut<Self>) {
if node.smoke_fx_timer > 0.075 {
node.smoke_fx_timer = 0.0;
{
let mut resources = storage::get_mut::<Resources>();
resources.fx_bullet_smoke.spawn(node.bullet.pos);
}
}
node.smoke_fx_timer += get_frame_time();

node.angle += 0.1;
}
}
4 changes: 3 additions & 1 deletion src/items/musket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl Gun {
scene::add_node(Gun {
gun_sprite,
gun_fx_sprite,
gun_fx: false,
gun_fx: true,
smoke_fx_counter: 0,
smoke_fx_timer: 0.0,
body: PhysicsBody::new(
&mut world.collision_world,
pos,
Expand Down
4 changes: 3 additions & 1 deletion src/items/sniper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl Gun {
scene::add_node(Gun {
gun_sprite,
gun_fx_sprite,
gun_fx: false,
gun_fx: true,
smoke_fx_counter: 0,
smoke_fx_timer: 0.0,
body: PhysicsBody::new(
&mut world.collision_world,
pos,
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ struct Resources {
fx_explosion_fire: Emitter,
fx_explosion_particles: EmittersCache,
fx_smoke: Emitter,
fx_bullet_smoke: EmittersCache,
fx_gun_smoke: EmittersCache,
whale_green: Texture2D,
whale_blue: Texture2D,
whale_boots_blue: Texture2D,
Expand Down Expand Up @@ -228,6 +230,8 @@ impl Resources {
const CANNONBALL_HIT_FX: &str = include_str!("../assets/fxses/canonball_hit.json");
const EXPLOSION_PARTICLES: &str = include_str!("../assets/fxses/explosion_particles.json");
const SMOKE_FX: &str = include_str!("../assets/fxses/smoke.json");
const BULLET_SMOKE_FX: &str = include_str!("../assets/fxses/bullet_smoke.json");
const GUN_SMOKE_FX: &str = include_str!("../assets/fxses/gun_smoke.json");
let hit_fxses = EmittersCache::new(nanoserde::DeJson::deserialize_json(HIT_FX).unwrap());
let explosion_fxses =
EmittersCache::new(nanoserde::DeJson::deserialize_json(EXPLOSION_FX).unwrap());
Expand All @@ -238,6 +242,10 @@ impl Resources {
let fx_explosion_particles =
EmittersCache::new(nanoserde::DeJson::deserialize_json(EXPLOSION_PARTICLES).unwrap());
let fx_smoke = Emitter::new(nanoserde::DeJson::deserialize_json(SMOKE_FX).unwrap());
let fx_bullet_smoke =
EmittersCache::new(nanoserde::DeJson::deserialize_json(BULLET_SMOKE_FX).unwrap());
let fx_gun_smoke =
EmittersCache::new(nanoserde::DeJson::deserialize_json(GUN_SMOKE_FX).unwrap());

let mut items_textures = HashMap::new();
let mut items_fxses = HashMap::new();
Expand Down Expand Up @@ -298,6 +306,8 @@ impl Resources {
textures,
fx_explosion_fire,
fx_explosion_particles,
fx_bullet_smoke,
fx_gun_smoke,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/nodes/fxses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ impl scene::Node for Fxses {
resources.explosion_fxses.draw();
resources.fx_explosion_fire.draw(Vec2::new(0., 0.));
resources.fx_explosion_particles.draw();
resources.fx_bullet_smoke.draw();
resources.fx_gun_smoke.draw();

for fx in resources.items_fxses.values_mut() {
fx.draw();
Expand Down