Skip to content

Miscellaneous fixes and improvements #3

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/constantes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub const TIME_BLINK: f32 = 0.4;
pub const TIME_AUTO_STEP: f32 = 0.2;
pub const TIME_VISUAL_LERP: f32 = 1.0 / 0.2 * 2.0;

pub const GAME_SCALE: f32 = 5.0;
// pub const GAME_SCALE: f32 = 5.0;

pub const TOUCH_MIN_DELTA: f32 = 10.0;
pub const TEXT_PADDING_SIZE: f32 = 0.3; // fits all text inside screen with this padding in procentage
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions src/entities/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Player {
if is_grounded && !self.prev_grounded {
self.sprite.texture_index = 0;
self.prev_grounded = true;
sound_collection.play(8);
let _ = sound_collection.play(8);

let mut land_particles = particle_collection.get_mut(*land_id).unwrap();
land_particles.scale = screen_size.x / 16.0;
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn system(
.any(|s| s.transform.position == pos_below);

if player.prev_grounded && !is_grounded {
sound_collection.play(7);
let _ = sound_collection.play(7);
player.sprite.texture_index = 13;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ pub fn system(
occupied_by_grass || occupied_by_skeleton || occupied_by_skeleton_block;
if !is_occupied {
player.transform.position = new_position;
sound_collection.play(0);
let _ = sound_collection.play(0);

particle_system::emit_step_particle(
particle_collection,
Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn system(
occupied_by_grass || occupied_by_skeleton || occupied_by_skeleton_block;
if !is_occupied {
player.transform.position = new_position;
sound_collection.play(0);
let _ = sound_collection.play(0);
particle_system::emit_step_particle(
particle_collection,
step_id,
Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn system(
.unwrap();
if let Some(other_teleporter) = other_teleporter_option {
player.transform.position = other_teleporter.transform.position;
sound_collection.play(3);
let _ = sound_collection.play(3);
player.sprite.blink_timer = constantes::TIME_BLINK;
other_teleporter.sprite.blink_timer = constantes::TIME_BLINK;
}
Expand All @@ -257,9 +257,9 @@ pub fn system(
if is_on_exit {
if all_skeletons_freed {
should_exit = true;
sound_collection.play(4);
let _ = sound_collection.play(4);
} else {
sound_collection.play(6);
let _ = sound_collection.play(6);
for skeleton_block in game_state.skeleton_blocks.iter_mut() {
skeleton_block.sprite.blink_timer = constantes::TIME_BLINK;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn system(
grass_particle_system.position = pos_particle;
grass_particle_system.emit(20);

sound_collection.play(1);
let _ = sound_collection.play(1);
player.sprite.texture_index = 8;

// Foilage fly!
Expand Down
6 changes: 3 additions & 3 deletions src/entities/skeleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn block_system(game_state: &mut GameState, sound_collection: &mut SoundColl
new_skeleton.sprite.is_flipped = true;
}
game_state.skeletons.push(new_skeleton);
sound_collection.play(5);
let _ = sound_collection.play(5);
}
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn walk(
let mut is_occupied = pos_skele == pos_player;
if is_occupied {
wants_attack.push(index);
sound_collection.play(5);
let _ = sound_collection.play(5);
continue;
}
is_occupied |= game_state
Expand Down Expand Up @@ -240,7 +240,7 @@ pub fn attack(
player.sprite.texture_index = 9;
skeleton.ai.state = AiState::Walk;
skeleton.sprite.texture_index = 4;
sound_collection.play(2);
let _ = sound_collection.play(2);

let blood_particles = particle_collection.get_mut(*blood_id).unwrap();
blood_particles.scale = screen_size.x / 16.0;
Expand Down
1 change: 0 additions & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub fn load_map(
..Default::default()
});
}

}
'4' => {
game_state.exit = Exit {
Expand Down
25 changes: 16 additions & 9 deletions src/particle_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::transform_compontent::TransformComponent;
// use crate::transform_compontent::TransformComponent;
use ggez::graphics::spritebatch::SpriteBatch;
use ggez::graphics::{DrawParam, Image};
use ggez::Context;
Expand Down Expand Up @@ -29,6 +29,7 @@ fn lerp(from: f32, to: f32, delta: f32) -> f32 {
(1.0 - delta) * from + delta * to
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum TransformSpace {
Local,
Expand Down Expand Up @@ -317,6 +318,7 @@ impl ParticleSystem {
}
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum EmitShape {
Point, // The position of the particle system
Expand All @@ -326,32 +328,37 @@ pub enum EmitShape {
Circle(CircleData),
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
struct RectData {
size: Vector2<f32>,
spawn_type: SpawnType,
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
struct ConeData {
radius: f32,
angle: f32,
spawn_type: SpawnType,
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
struct CircleData {
pub struct CircleData {
radius: f32,
spawn_type: SpawnType,
}

#[allow(dead_code)]
#[derive(Clone, Copy)]
enum SpawnType {
Volume,
Edge,
}

// decides how velocity should be calculated
#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum VelocityType {
//AlignToDirection(AlignToDirectionData),
Expand Down Expand Up @@ -497,13 +504,13 @@ impl ParticleSystemCollection {
}

// returns if system is still valid
pub fn emit(&mut self, system_identifier: u32, amount: i32) -> bool {
if let Some(system) = self.particle_systems.get_mut(&system_identifier) {
system.emit(amount);
return true;
}
false
}
// pub fn emit(&mut self, system_identifier: u32, amount: i32) -> bool {
// if let Some(system) = self.particle_systems.get_mut(&system_identifier) {
// system.emit(amount);
// return true;
// }
// false
// }

pub fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
for (_id, system) in self.particle_systems.iter_mut() {
Expand Down
10 changes: 5 additions & 5 deletions src/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub struct SpriteCollection {
pub images: [graphics::Image; 21],
}

impl SpriteCollection {
pub fn get_sprite<'a, 'b: 'a>(&'a self, index: usize) -> Option<&'a graphics::Image> {
self.images.get(index)
}
}
// impl SpriteCollection {
// pub fn get_sprite<'a, 'b: 'a>(&'a self, index: usize) -> Option<&'a graphics::Image> {
// self.images.get(index)
// }
// }

pub fn render(
sprite_collection: &SpriteCollection,
Expand Down
25 changes: 16 additions & 9 deletions src/states/main_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
};
use event::KeyCode;
use ggez::{audio, event, graphics, Context, GameResult};
use graphics::{DrawParam, FilterMode, draw};
use graphics::{draw, DrawParam, FilterMode};
use gwg as ggez;
use gwg::input::keyboard::KeyMods;
use nalgebra as na;
Expand Down Expand Up @@ -204,7 +204,7 @@ impl MainState {
self.current_map,
&self.screen_size,
);
self.sound_collection.play(9);
let _ = self.sound_collection.play(9);
}
}

Expand Down Expand Up @@ -319,7 +319,8 @@ impl event::EventHandler for MainState {
graphics::set_screen_coordinates(
ctx,
ggez::graphics::Rect::new(-offset_x, -offset_y, w, h),
).unwrap();
)
.unwrap();
util::force_visual_positions(&mut self.game_state, &self.screen_size);

let border_width = (w - (map_w * sprite_scale)) * 0.5;
Expand Down Expand Up @@ -408,15 +409,17 @@ fn render_game(
&game_state.exit.transform,
&mut game_state.exit.sprite,
screen_size,
).unwrap();
)
.unwrap();
for grass in &mut game_state.grasses {
sprite::render(
sprite_collection,
ctx,
&grass.transform,
&mut grass.sprite,
screen_size,
).unwrap();
)
.unwrap();
}
for skeleton_block in &mut game_state.skeleton_blocks {
sprite::render(
Expand All @@ -425,7 +428,8 @@ fn render_game(
&skeleton_block.transform,
&mut skeleton_block.sprite,
screen_size,
).unwrap();
)
.unwrap();
}
for teleporter_option in game_state.teleporters.iter_mut().map(|t| t.as_mut()) {
if let Some(teleporter) = teleporter_option {
Expand All @@ -435,7 +439,8 @@ fn render_game(
&teleporter.transform,
&mut teleporter.sprite,
screen_size,
).unwrap();
)
.unwrap();
}
}
for skeleton in game_state.skeletons.iter_mut() {
Expand All @@ -445,15 +450,17 @@ fn render_game(
&skeleton.transform,
&mut skeleton.sprite,
screen_size,
).unwrap();
)
.unwrap();
}
sprite::render(
sprite_collection,
ctx,
&game_state.player.transform,
&mut game_state.player.sprite,
screen_size,
).unwrap();
)
.unwrap();
foilage::render(game_state, sprite_collection, ctx, screen_size).unwrap();
}

Expand Down
File renamed without changes.