Working
This commit is contained in:
parent
bc90055639
commit
0b36cebbd2
@ -3,8 +3,8 @@
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::engine::bbox::Bbox;
|
use crate::engine::bbox::Bbox;
|
||||||
use crate::engine::controls::Controls;
|
use crate::engine::controls::{Action, Controls};
|
||||||
use crate::engine::event::Keyboard;
|
use crate::engine::event::{Event, Keyboard};
|
||||||
use crate::engine::math::{clamp, duration_as_f64};
|
use crate::engine::math::{clamp, duration_as_f64};
|
||||||
use crate::engine::physics;
|
use crate::engine::physics;
|
||||||
use crate::engine::scene::Updatable;
|
use crate::engine::scene::Updatable;
|
||||||
@ -188,26 +188,26 @@ impl Updatable for Character {
|
|||||||
self.position += self.speed * duration;
|
self.position += self.speed * duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn manage_event(&mut self, event: &Event) {
|
fn manage_event(&mut self, event: &Event) {
|
||||||
// let action = if let Some(ref controls) = self.controls {
|
let action = if let Some(ref controls) = self.controls {
|
||||||
// controls.convert(event)
|
controls.convert(event)
|
||||||
// } else {
|
} else {
|
||||||
// None
|
None
|
||||||
// };
|
};
|
||||||
|
|
||||||
// match action {
|
match action {
|
||||||
// Some(Action::Jump(true)) => {
|
Some(Action::Jump(true)) => {
|
||||||
// self.jump();
|
self.jump();
|
||||||
// self.can_jump = false;
|
self.can_jump = false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Some(Action::Jump(false)) => {
|
Some(Action::Jump(false)) => {
|
||||||
// self.can_jump = true;
|
self.can_jump = true;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// _ => (),
|
_ => (),
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Drawable for Character {
|
// impl Drawable for Character {
|
||||||
|
@ -18,6 +18,8 @@ use wasm_bindgen::prelude::*;
|
|||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
use crate::engine::event::{Key, Keyboard};
|
use crate::engine::event::{Key, Keyboard};
|
||||||
|
use crate::engine::map::Map;
|
||||||
|
use crate::engine::scene::Scene;
|
||||||
use crate::engine::texture::TextureManager;
|
use crate::engine::texture::TextureManager;
|
||||||
use crate::{error_js, Result};
|
use crate::{error_js, Result};
|
||||||
|
|
||||||
@ -67,6 +69,9 @@ impl Engine {
|
|||||||
let document = Rc::new(document);
|
let document = Rc::new(document);
|
||||||
let context = Rc::new(context);
|
let context = Rc::new(context);
|
||||||
|
|
||||||
|
let map = Map::from_str(include_str!("../../static/levels/level1.lvl")).unwrap();
|
||||||
|
let scene = Scene::from_map(map);
|
||||||
|
|
||||||
Ok(Engine {
|
Ok(Engine {
|
||||||
inner: Rc::new(RefCell::new(inner)),
|
inner: Rc::new(RefCell::new(inner)),
|
||||||
document,
|
document,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::engine::character::Character;
|
use crate::engine::character::Character;
|
||||||
use crate::engine::event::Keyboard;
|
use crate::engine::event::{Event, Keyboard};
|
||||||
use crate::engine::map::Map;
|
use crate::engine::map::Map;
|
||||||
use crate::engine::texture::SPRITE_SIZE;
|
use crate::engine::texture::SPRITE_SIZE;
|
||||||
|
|
||||||
@ -123,12 +123,12 @@ impl Scene {
|
|||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Transfers an event to the elements contained in the scene that should receive events.
|
/// Transfers an event to the elements contained in the scene that should receive events.
|
||||||
// pub fn manage_event(&mut self, event: &Event) {
|
pub fn manage_event(&mut self, event: &Event) {
|
||||||
// for c in &mut self.characters {
|
for c in &mut self.characters {
|
||||||
// c.manage_event(event);
|
c.manage_event(event);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
/// Returns a reference to the characters of the scene.
|
/// Returns a reference to the characters of the scene.
|
||||||
pub fn characters(&self) -> &Vec<Character> {
|
pub fn characters(&self) -> &Vec<Character> {
|
||||||
@ -146,6 +146,6 @@ pub trait Updatable {
|
|||||||
/// Updates the thing depending on the duration since last frame.
|
/// Updates the thing depending on the duration since last frame.
|
||||||
fn update(&mut self, duration: &Duration, keyboard: &Keyboard);
|
fn update(&mut self, duration: &Duration, keyboard: &Keyboard);
|
||||||
|
|
||||||
// /// Called when an event arrives.
|
/// Called when an event arrives.
|
||||||
// fn manage_event(&mut self, event: &Event);
|
fn manage_event(&mut self, event: &Event);
|
||||||
}
|
}
|
||||||
|
BIN
static/image.png
BIN
static/image.png
Binary file not shown.
Before Width: | Height: | Size: 583 KiB |
14
static/levels/level1.lvl
Normal file
14
static/levels/level1.lvl
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
13 24
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||||
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1
|
||||||
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1
|
||||||
|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1
|
Loading…
x
Reference in New Issue
Block a user