-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove compilation warnings caused by examples (#253)
1 parent
e7197f2
commit d65bd24
Showing
45 changed files
with
1,194 additions
and
1,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::animation_2d::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::anti_aliasing::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::collisions_2d::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::game_of_life::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::gamepad::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::keyboard::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::mouse::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::pong::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::rendering_2d::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::text_2d::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::texture_2d::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![allow(missing_docs)] | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
modor_examples::touch::main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,5 @@ | ||
#![allow(missing_docs)] | ||
|
||
use modor::{systems, App, BuiltEntity, Component, SingleRef}; | ||
use modor_graphics::{ | ||
model_2d, window_target, Color, Material, Model2DMaterial, RenderTarget, Sprite, Texture, | ||
TextureAnimation, WINDOW_CAMERA_2D, | ||
}; | ||
use modor_input::{Key, Keyboard}; | ||
use modor_math::Vec2; | ||
use modor_physics::{Dynamics2D, Transform2D}; | ||
use modor_resources::ResKey; | ||
|
||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] | ||
pub fn main() { | ||
App::new() | ||
.with_entity(modor_text::module()) | ||
.with_entity(window()) | ||
.with_entity(character()) | ||
.run(modor_graphics::runner); | ||
} | ||
|
||
fn window() -> impl BuiltEntity + Sized { | ||
window_target().updated(|r: &mut RenderTarget| r.background_color = Color::DARK_GRAY) | ||
} | ||
|
||
fn character() -> impl BuiltEntity { | ||
let texture_key = ResKey::unique("character"); | ||
let sprites = Direction::Down.stopped_sprites(); | ||
model_2d(WINDOW_CAMERA_2D, Model2DMaterial::Rectangle) | ||
.updated(|t: &mut Transform2D| t.size = Vec2::ONE * 0.15) | ||
.updated(|m: &mut Material| m.texture_key = Some(texture_key)) | ||
.component(Dynamics2D::new()) | ||
.component(Texture::from_path(texture_key, "slime.png")) | ||
.with(|t| t.is_smooth = false) | ||
.component(TextureAnimation::new(5, 9, sprites)) | ||
.component(Character::default()) | ||
} | ||
|
||
#[derive(Component, Default)] | ||
struct Character { | ||
direction: Direction, | ||
} | ||
|
||
#[systems] | ||
impl Character { | ||
#[run] | ||
fn update( | ||
&mut self, | ||
transform: &mut Transform2D, | ||
dynamics: &mut Dynamics2D, | ||
animation: &mut TextureAnimation, | ||
keyboard: SingleRef<'_, '_, Keyboard>, | ||
) { | ||
dynamics.velocity = 0.2 | ||
* keyboard | ||
.get() | ||
.direction(Key::Left, Key::Right, Key::Up, Key::Down); | ||
self.direction = self.direction(dynamics.velocity); | ||
animation.sprites = self.direction.sprites(dynamics.velocity == Vec2::ZERO); | ||
transform.size.x = self.direction.size_x_sign() * transform.size.x.abs(); | ||
} | ||
|
||
fn direction(&self, direction: Vec2) -> Direction { | ||
if direction.x < 0. { | ||
Direction::Left | ||
} else if direction.x > 0. { | ||
Direction::Right | ||
} else if direction.y > 0. { | ||
Direction::Up | ||
} else if direction.y < 0. { | ||
Direction::Down | ||
} else { | ||
self.direction | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, PartialEq, Eq, Default)] | ||
enum Direction { | ||
Left, | ||
Right, | ||
Up, | ||
#[default] | ||
Down, | ||
} | ||
|
||
impl Direction { | ||
fn sprites(self, is_stopped: bool) -> Vec<Sprite> { | ||
if is_stopped { | ||
self.stopped_sprites() | ||
} else { | ||
self.moving_sprites() | ||
} | ||
} | ||
|
||
fn moving_sprites(self) -> Vec<Sprite> { | ||
let texture_y = self.texture_y(); | ||
vec![ | ||
Sprite::new(0, texture_y + 1), | ||
Sprite::new(1, texture_y + 1), | ||
Sprite::new(2, texture_y + 1), | ||
Sprite::new(3, texture_y + 1), | ||
Sprite::new(4, texture_y + 1), | ||
Sprite::new(0, texture_y + 2), | ||
Sprite::new(1, texture_y + 2), | ||
] | ||
} | ||
|
||
fn stopped_sprites(self) -> Vec<Sprite> { | ||
let texture_y = self.texture_y(); | ||
vec![Sprite::new(0, texture_y), Sprite::new(1, texture_y)] | ||
} | ||
|
||
fn texture_y(self) -> u16 { | ||
match self { | ||
Self::Left | Self::Right => 0, | ||
Self::Up => 6, | ||
Self::Down => 3, | ||
} | ||
} | ||
|
||
fn size_x_sign(self) -> f32 { | ||
match self { | ||
Self::Left | Self::Up | Self::Down => 1., | ||
Self::Right => -1., | ||
} | ||
} | ||
modor_examples::animation_2d::main(); | ||
} |
Oops, something went wrong.