parent
01f6f3e4ba
commit
0113f04457
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,6 @@
|
||||
(
|
||||
axes: {},
|
||||
actions: {
|
||||
"flap": [[Key(Space)]],
|
||||
},
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
(
|
||||
title: "amethyst-cli-starter-2d",
|
||||
dimensions: Some((800, 600)),
|
||||
title: "test",
|
||||
dimensions: Some((432, 768)),
|
||||
)
|
||||
|
After Width: | Height: | Size: 29 KiB |
@ -0,0 +1,42 @@
|
||||
(
|
||||
texture_width: 512,
|
||||
texture_height: 512,
|
||||
sprites: [
|
||||
( // Daytime background
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 144,
|
||||
height: 256,
|
||||
),
|
||||
( // Nighttime background
|
||||
x: 146,
|
||||
y: 0,
|
||||
width: 144,
|
||||
height: 256,
|
||||
),
|
||||
( // Down Pipe
|
||||
x: 56,
|
||||
y: 323,
|
||||
width: 26,
|
||||
height: 160,
|
||||
),
|
||||
( // Up Pipe
|
||||
x: 84,
|
||||
y: 323,
|
||||
width: 26,
|
||||
height: 160,
|
||||
),
|
||||
( // Ground
|
||||
x: 292,
|
||||
y: 0,
|
||||
width: 168,
|
||||
height: 56,
|
||||
),
|
||||
( // Floppy
|
||||
x: 3,
|
||||
y: 490,
|
||||
width: 17,
|
||||
height: 13,
|
||||
)
|
||||
]
|
||||
)
|
@ -0,0 +1,38 @@
|
||||
use amethyst::{
|
||||
core::transform::TransformBundle,
|
||||
core::transform::Transform,
|
||||
prelude::*,
|
||||
renderer::{
|
||||
plugins::{RenderFlat2D, RenderToWindow},
|
||||
types::DefaultBackend,
|
||||
RenderingBundle,
|
||||
},
|
||||
utils::application_root_dir,
|
||||
core::SystemDesc,
|
||||
derive::SystemDesc,
|
||||
ecs::prelude::{Component, DenseVecStorage, Entity},
|
||||
ecs::prelude::{Join, ReadStorage, System, SystemData, WriteStorage},
|
||||
};
|
||||
|
||||
|
||||
// Falling object component to bucket us into something the system can manipulate
|
||||
#[derive(Clone)]
|
||||
pub struct TiledScroller {
|
||||
pub speed: f32,
|
||||
pub width: f32,
|
||||
pub height: f32,
|
||||
pub position: f32,
|
||||
}
|
||||
impl Component for TiledScroller {
|
||||
type Storage = DenseVecStorage<Self>;
|
||||
}
|
||||
|
||||
// Falling object component to bucket us into something the system can manipulate
|
||||
pub struct Birb {
|
||||
pub vertical_speed: f32,
|
||||
pub starting_height: f32,
|
||||
pub position: f32,
|
||||
}
|
||||
impl Component for Birb {
|
||||
type Storage = DenseVecStorage<Self>;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
use amethyst::{
|
||||
core::SystemDesc,
|
||||
core::timing::Time,
|
||||
core::transform::{Transform, TransformBundle},
|
||||
derive::SystemDesc,
|
||||
ecs::prelude::{},
|
||||
ecs::prelude::{
|
||||
Component, DenseVecStorage, Entity, Join, Read,
|
||||
ReadStorage, System, SystemData, WriteStorage
|
||||
},
|
||||
input::{InputHandler, StringBindings},
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use crate::components::*;
|
||||
|
||||
pub struct ScrollScrollables;
|
||||
|
||||
// This system iterates all the objects with transform (and falling object) component
|
||||
impl<'a> System<'a> for ScrollScrollables {
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Transform>,
|
||||
WriteStorage<'a, TiledScroller>,
|
||||
Read<'a, Time>,
|
||||
);
|
||||
|
||||
fn run(&mut self, (mut transforms, mut scrolling, time): Self::SystemData) {
|
||||
for (mut transform, mut object) in (&mut transforms, &mut scrolling).join() {
|
||||
|
||||
// I need to tile it by it's width
|
||||
transform.prepend_translation_x(object.speed * time.delta_seconds());
|
||||
if transform.translation().x+144.0*1.5 < 0.0 {
|
||||
transform.set_translation_x(144.0*3.0/2.0*3.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BirbGravity {
|
||||
pub fired: bool,
|
||||
}
|
||||
|
||||
// This system iterates all the objects with transform (and falling object) component
|
||||
impl<'a> System<'a> for BirbGravity {
|
||||
type SystemData = (
|
||||
WriteStorage<'a, Transform>,
|
||||
WriteStorage<'a, Birb>,
|
||||
Read<'a, Time>,
|
||||
Read<'a, InputHandler<StringBindings>>,
|
||||
);
|
||||
|
||||
fn run(&mut self, (mut transforms, mut scrolling, time, input): Self::SystemData) {
|
||||
for (mut transform, mut object) in (&mut transforms, &mut scrolling).join() {
|
||||
|
||||
if input.action_is_down("flap").expect("No action") {
|
||||
object.vertical_speed = 500.0;
|
||||
}
|
||||
object.vertical_speed -= 1000.0 * time.delta_seconds();
|
||||
transform.prepend_translation_y(object.vertical_speed * time.delta_seconds());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue