Skip to content

Commit

Permalink
chore: prepare 0.6 (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
suspistew authored Feb 19, 2022
1 parent d267f12 commit d750d4d
Show file tree
Hide file tree
Showing 68 changed files with 1,242 additions and 810 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scion"
version = "0.5.0"
version = "0.6.0"
authors = ["grzi <jeremy.thulliez@gmail.com>"]
edition = "2018"
description = "Game making library on top of wgpu, winit, legion"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ cargo run --example bomberman --release

## Showcase

| <img src="./examples/taquin/taquin.gif" alt="Taquin" style="width:300px"/> | <img src="./examples/tetris/tetris.gif" alt="Tetris" style="width:300px" /> | <img src="./examples/mario/mario.gif" alt="Mario" style="width:300px" /> |
| ------------- | ------------- | ------------- |
| <img src="./examples/bomberman/bomberman.gif" alt="Bomberman" style="width:300px" /> | <img src="./examples/jezzball/jezzball.gif" alt="Jezzball" style="width:300px" /> | |
| <img src="./examples/taquin/taquin.gif" alt="Taquin" style="width:300px"/> | <img src="./examples/tetris/tetris.gif" alt="Tetris" style="width:300px" /> | <img src="./examples/mario/mario.gif" alt="Mario" style="width:300px" /> |
| ------------- | ------------- |--------------------------------------------------------------------------------------------------|
| <img src="./examples/bomberman/bomberman.gif" alt="Bomberman" style="width:300px" /> | <img src="./examples/jezzball/jezzball.gif" alt="Jezzball" style="width:300px" /> | <img src="./examples/new-bark-town/new-bark-town.gif" alt="New bark town" style="width:300px" /> |



Expand Down
6 changes: 3 additions & 3 deletions examples/bomberman/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;


use legion::{Entity, Resources, World};

Expand All @@ -21,8 +21,8 @@ use scion::{
resources::asset_manager::AssetRef,
scene::Scene,
},
Scion,
utils::{file::app_base_path, maths::Dimensions},
Scion,
};

use crate::level_reader::Level;
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Scene for MainScene {
app_base_path().join("examples/bomberman/assets/sokoban_tilesheet.png").get(),
13,
9,
64
64,
));

let level = level_reader::read_level("examples/bomberman/assets/test_map.json");
Expand Down
12 changes: 6 additions & 6 deletions examples/jezzball/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use log::LevelFilter;

use crate::main_scene::MainScene;
use scion::{
config::{
logger_config::LoggerConfig, scion_config::ScionConfigBuilder,
window_config::WindowConfigBuilder,
},
core::{components::color::Color},
core::components::color::Color,
Scion,
};
use crate::main_scene::MainScene;

mod main_scene;
mod systems;
Expand All @@ -28,8 +28,8 @@ fn main() {
)
.get(),
)
.with_scene::<MainScene>()
.with_system(systems::ball::ball_control_system())
.with_system(systems::lines::line_update_system())
.run();
.with_scene::<MainScene>()
.with_system(systems::ball::ball_control_system())
.with_system(systems::lines::line_update_system())
.run();
}
51 changes: 28 additions & 23 deletions examples/jezzball/main_scene.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use legion::{Entity, EntityStore, IntoQuery};
use legion::world::SubWorld;
use legion::{Entity, EntityStore, IntoQuery};

use std::fmt::{Display, Formatter};

use rand::{thread_rng, Rng};
use scion::core::components::color::Color;
use scion::core::components::shapes::rectangle::Rectangle;
use scion::core::components::tiles::tilemap::{TileInfos, Tilemap, TilemapInfo};
use scion::core::resources::events::topic::TopicConfiguration;
use scion::core::resources::events::{PollConfiguration, SubscriberId};
use scion::core::scene::SceneController;
use scion::{
core::{
components::{
Expand All @@ -14,24 +20,15 @@ use scion::{
},
tiles::{sprite::Sprite, tileset::Tileset},
},
scene::Scene,
legion_ext::{ScionResourcesExtension, ScionWorldExtension},
resources::{
asset_manager::AssetRef,
audio::{Sound},
},
resources::{asset_manager::AssetRef},
scene::Scene,
},
legion::{Resources, World},
};
use winit::window::CursorIcon;
use scion::core::components::color::Color;
use scion::core::components::shapes::rectangle::Rectangle;
use scion::core::components::tiles::tilemap::{TileInfos, Tilemap, TilemapInfo};
use scion::core::scene::SceneController;
use scion::core::resources::events::{PollConfiguration, SubscriberId};
use scion::core::resources::events::topic::TopicConfiguration;

use crate::utils::{ball_animations, ball_asset, ball_bounce_effect, cases_asset};
use crate::utils::{ball_animations, ball_asset, cases_asset};
use scion::utils::maths::{Dimensions, Position, Vector};

#[derive(Debug)]
Expand Down Expand Up @@ -61,7 +58,9 @@ pub enum CursorState {
}

impl Display for BallDirection {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self) }
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

#[derive(Default)]
Expand All @@ -77,15 +76,22 @@ pub struct Line {
pub direction: LineDirection,
}

pub struct MainScene{
pub struct MainScene {
tilemap: Option<Entity>,
subscriber_id: Option<SubscriberId>,
mouse_state: CursorState,
state_before_border: Option<CursorState>,
}

impl Default for MainScene {
fn default() -> Self { Self { tilemap: None, subscriber_id: None, mouse_state: CursorState::ROW, state_before_border: None } }
fn default() -> Self {
Self {
tilemap: None,
subscriber_id: None,
mouse_state: CursorState::ROW,
state_before_border: None,
}
}
}

impl Scene for MainScene {
Expand All @@ -97,7 +103,6 @@ impl Scene for MainScene {

// Creating the level


init_balls(world, &assets);

add_border(world);
Expand Down Expand Up @@ -273,7 +278,7 @@ impl Scene for MainScene {
});
}

fn on_stop(&mut self, world: &mut World, resources: &mut Resources) {
fn on_stop(&mut self, world: &mut World, _resources: &mut Resources) {
world.remove(self.tilemap.unwrap());
let mut to_delete: Vec<Entity> =
<(Entity, &Line)>::query().iter(world).map(|(e, _)| *e).collect();
Expand All @@ -283,7 +288,7 @@ impl Scene for MainScene {
}
}

impl MainScene{
impl MainScene {
fn compute_mouse_on_border(
&mut self,
mouse_pos: (f64, f64),
Expand Down Expand Up @@ -364,7 +369,8 @@ pub fn init_balls(world: &mut World, assets: &JezzBallAssets) {
ColliderMask::Custom("BORDER_RIGHT".to_string()),
],
ColliderType::Square(38),
).with_offset(Vector::new(-5., -5.)),
)
.with_offset(Vector::new(-5., -5.)),
ball_animations(),
));
}
Expand Down Expand Up @@ -407,7 +413,6 @@ fn add_border(world: &mut World) {
));
}


fn pathfind_from(
pos: (usize, usize),
world: &SubWorld,
Expand Down
104 changes: 50 additions & 54 deletions examples/jezzball/systems/ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,70 +43,66 @@ pub fn ball_control(
("BORDER_TOP", BallDirection::TopLeft) => Some(BallDirection::BottomLeft),
("BORDER_BOTTOM", BallDirection::BottomRight) => Some(BallDirection::TopRight),
("BORDER_BOTTOM", BallDirection::BottomLeft) => Some(BallDirection::TopLeft),
("BORDER_CUSTOM_VERTICAL", e) => {
match e {
BallDirection::TopLeft => {
if collision.coordinates().x() + 8. <= transform.translation().x() {
Some(BallDirection::TopRight)
} else {
None
}
("BORDER_CUSTOM_VERTICAL", e) => match e {
BallDirection::TopLeft => {
if collision.coordinates().x() + 8. <= transform.translation().x() {
Some(BallDirection::TopRight)
} else {
None
}
BallDirection::TopRight => {
if collision.coordinates().x() > transform.translation().x() {
Some(BallDirection::TopLeft)
} else {
None
}
}
BallDirection::TopRight => {
if collision.coordinates().x() > transform.translation().x() {
Some(BallDirection::TopLeft)
} else {
None
}
BallDirection::BottomLeft => {
if collision.coordinates().x() + 8. <= transform.translation().x() {
Some(BallDirection::BottomRight)
} else {
None
}
}
BallDirection::BottomLeft => {
if collision.coordinates().x() + 8. <= transform.translation().x() {
Some(BallDirection::BottomRight)
} else {
None
}
BallDirection::BottomRight => {
if collision.coordinates().x() > transform.translation().x() {
Some(BallDirection::BottomLeft)
} else {
None
}
}
BallDirection::BottomRight => {
if collision.coordinates().x() > transform.translation().x() {
Some(BallDirection::BottomLeft)
} else {
None
}
}
}
("BORDER_CUSTOM_HORIZONTAL", e) => {
match e {
BallDirection::TopLeft => {
if collision.coordinates().y() + 8. <= transform.translation().y() {
Some(BallDirection::BottomLeft)
} else {
None
}
},
("BORDER_CUSTOM_HORIZONTAL", e) => match e {
BallDirection::TopLeft => {
if collision.coordinates().y() + 8. <= transform.translation().y() {
Some(BallDirection::BottomLeft)
} else {
None
}
BallDirection::TopRight => {
if collision.coordinates().y() + 8. <= transform.translation().y() {
Some(BallDirection::BottomRight)
} else {
None
}
}
BallDirection::TopRight => {
if collision.coordinates().y() + 8. <= transform.translation().y() {
Some(BallDirection::BottomRight)
} else {
None
}
BallDirection::BottomLeft => {
if collision.coordinates().y() > transform.translation().y() {
Some(BallDirection::TopLeft)
} else {
None
}
}
BallDirection::BottomLeft => {
if collision.coordinates().y() > transform.translation().y() {
Some(BallDirection::TopLeft)
} else {
None
}
BallDirection::BottomRight => {
if collision.coordinates().y() > transform.translation().y() {
Some(BallDirection::TopRight)
} else {
None
}
}
BallDirection::BottomRight => {
if collision.coordinates().y() > transform.translation().y() {
Some(BallDirection::TopRight)
} else {
None
}
}
}
},
(_a, _b) => None,
};

Expand Down
2 changes: 1 addition & 1 deletion examples/jezzball/systems/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use scion::core::{
},
};

use crate::{main_scene::LineDirection};
use crate::main_scene::Line;
use crate::main_scene::LineDirection;

const LINE_SPEED: f32 = 4.;

Expand Down
8 changes: 6 additions & 2 deletions examples/jezzball/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use scion::{
const ANIMATION_DURATION: Duration = Duration::from_millis(300);
const BALL_SPEED: f32 = 30.;

pub fn ball_asset() -> String { app_base_path().join("examples/jezzball/assets/ball.png").get() }
pub fn ball_asset() -> String {
app_base_path().join("examples/jezzball/assets/ball.png").get()
}

pub fn cases_asset() -> String { app_base_path().join("examples/jezzball/assets/cases.png").get() }
pub fn cases_asset() -> String {
app_base_path().join("examples/jezzball/assets/cases.png").get()
}

pub fn ball_bounce_effect() -> String {
app_base_path().join("examples/jezzball/assets/bounce.ogg").get()
Expand Down
2 changes: 1 addition & 1 deletion examples/mario/character_control_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use scion::{
resources::{
inputs::{
inputs_controller::InputsController,
types::{InputState, KeyCode},
types::{KeyCode},
},
time::{TimerType, Timers},
},
Expand Down
14 changes: 6 additions & 8 deletions examples/mario/collisions_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ pub(crate) fn collider(
transform: &Transform,
) {
if let Material::Color(_c) = material {
collider.collisions().iter().for_each(|collision| {
match collision.mask() {
ColliderMask::Death => std::process::exit(0),
ColliderMask::Landscape => {
if collision.coordinates().y() > transform.global_translation().y() {
hero.landed = true;
}
collider.collisions().iter().for_each(|collision| match collision.mask() {
ColliderMask::Death => std::process::exit(0),
ColliderMask::Landscape => {
if collision.coordinates().y() > transform.global_translation().y() {
hero.landed = true;
}
_ => {}
}
_ => {}
});
}
}
Loading

0 comments on commit d750d4d

Please # to comment.