Commit d32576e3 authored by Grisu's avatar Grisu Committed by Rahix
Browse files

Add some obstacles

parent e84900dd
......@@ -2,6 +2,7 @@ mod edge;
mod matebottledrop;
mod movable;
mod node;
mod obstacle;
mod orbitbody;
mod player;
mod position;
......@@ -14,6 +15,7 @@ pub use matebottledrop::Matebottledrop;
pub use movable::Movable;
pub use node::Node;
pub use node::{draw_nodes_system, update_nodes_system};
pub use obstacle::Obstacle;
pub use orbitbody::{update_gravity_system, update_movement_system};
pub use orbitbody::{Gravity, OrbitBody};
pub use player::Player;
......
#[derive(Clone, Copy)]
pub struct Obstacle {
w: f32,
h: f32,
// TODO replace with angle (we can have rotated colliders now)
pub orientation: bool, // true means horizontal, false vertical
}
impl Obstacle {
pub fn new(orientation: bool) -> Obstacle {
Obstacle {
w: 200.0,
h: 20.0,
orientation: orientation,
}
}
pub fn width(&self) -> f32 {
if self.orientation {
self.w
} else {
self.h
}
}
pub fn height(&self) -> f32 {
if self.orientation {
self.h
} else {
self.w
}
}
}
mod matebottledrop;
mod obstacle;
mod player;
pub use matebottledrop::create_drop_points;
pub use obstacle::create_stationary_obstacles;
pub use player::create_player;
use crate::colliders;
use crate::components;
use crate::svg_loader;
use rand::seq::SliceRandom;
pub fn create_stationary_obstacles(world: &mut legion::World, level: &svg_loader::SvgLevel) {
let spawn_locations = level
.spawnpoints
.get("stationary_obstacle_type_1")
.map_or(&[][..], |x| &x[..]);
for obs in spawn_locations.choose_multiple(&mut rand::thread_rng(), 3) {
let orientation = *[true, false].choose(&mut rand::thread_rng()).unwrap();
let new_obs = components::Obstacle::new(orientation);
world.push((
new_obs,
components::Position::new(obs.x, obs.y),
colliders::Collider::new_static_rect(new_obs.width(), new_obs.height()),
));
}
}
......@@ -39,8 +39,10 @@ impl InGameState {
resources.insert(colliders::CollisionWorld::new());
let player = entities::create_player(&mut world, &resources, &level, player);
let obstacles = entities::create_stationary_obstacles(&mut world, &level);
resources.insert(resources::Player(player));
resources.insert(obstacles);
resources.insert(resources::GameManager::new());
level.apply_colliders(&mut world);
......@@ -64,6 +66,7 @@ impl InGameState {
.add_thread_local(systems::draw_sprites_system())
.add_thread_local(systems::draw_level_layer_system(foreground))
.add_thread_local(systems::draw_tmp_matebottledrop_system())
.add_thread_local(systems::draw_tmp_stationary_obstacles_system())
// .add_thread_local(systems::draw_debug_colliders_system())
;
let schedule = schedule_builder.build();
......
......@@ -5,6 +5,7 @@ mod moving;
mod player;
mod sprite;
mod tmp_matebottledrop;
mod tmp_stationary_obstacles;
pub use camera::camera_system;
pub use draw_colliders::draw_debug_colliders_system;
......@@ -13,3 +14,4 @@ pub use moving::{move_camera_to_player_system, move_movable_system};
pub use player::{sanity_goes_up_and_down_system, update_sanity_bar_system};
pub use sprite::draw_sprites_system;
pub use tmp_matebottledrop::draw_tmp_matebottledrop_system;
pub use tmp_stationary_obstacles::draw_tmp_stationary_obstacles_system;
use crate::colors;
use crate::components;
use crate::resources;
#[legion::system(for_each)]
pub fn draw_tmp_stationary_obstacles(
obstacle: &components::Obstacle,
pos: &components::Position,
#[resource] rendering: &mut resources::Rendering,
) {
rendering.begin_path();
rendering.set_fill_style(&colors::PRIMARY3_SHADE3);
let w = obstacle.width() as f64;
let h = obstacle.height() as f64;
rendering.fill_rect(pos.0.x as f64 - w / 2.0, pos.0.y as f64 - h / 2.0, w, h);
rendering.fill();
}
......@@ -13,7 +13,7 @@
version="1.1"
id="svg8"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"
sodipodi:docname="testlevel.svg">
sodipodi:docname="assembly-hall-1.svg">
<defs
id="defs2">
<marker
......@@ -248,19 +248,19 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.85535064"
inkscape:cx="1372.7661"
inkscape:cy="875.90762"
inkscape:zoom="0.30241212"
inkscape:cx="1623.7449"
inkscape:cy="1146.8181"
inkscape:document-units="px"
inkscape:current-layer="layer2"
inkscape:current-layer="layer4"
inkscape:document-rotation="0"
showgrid="true"
units="px"
inkscape:window-width="2560"
inkscape:window-height="1381"
inkscape:window-x="1920"
inkscape:window-y="0"
inkscape:window-maximized="1">
inkscape:window-width="1276"
inkscape:window-height="685"
inkscape:window-x="0"
inkscape:window-y="16"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid833"
......@@ -809,6 +809,56 @@
id="tspan1158"
x="648.68817"
y="3274.4141">bottledrop</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none"
x="2015.1759"
y="620.71484"
id="text220"><tspan
sodipodi:role="line"
id="tspan218"
x="2015.1759"
y="620.71484">stationary_obstacle_type_1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none"
x="1220.3584"
y="1871.1504"
id="text224"><tspan
sodipodi:role="line"
id="tspan222"
x="1220.3584"
y="1871.1504">stationary_obstacle_type_1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none"
x="596.36469"
y="1307.2789"
id="text228"><tspan
sodipodi:role="line"
id="tspan226"
x="596.36469"
y="1307.2789">stationary_obstacle_type_1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none"
x="1562.1445"
y="2493.1758"
id="text232"><tspan
sodipodi:role="line"
id="tspan230"
x="1562.1445"
y="2493.1758">stationary_obstacle_type_1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:40px;line-height:1.25;font-family:monospace;-inkscape-font-specification:monospace;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none"
x="1513.9751"
y="3281.0415"
id="text240"><tspan
sodipodi:role="line"
id="tspan238"
x="1513.9751"
y="3281.0415">stationary_obstacle_type_1</tspan></text>
</g>
<g
inkscape:label="foreground"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment