Commit 026dffc2 authored by Rahix's avatar Rahix 🦀

DiVOC Session Initial Implementation!

parent 75ac1b11
use crate::entities;
use crate::svg_loader;
pub struct ChaosPostShift {
hours: usize,
level: String,
}
impl ChaosPostShift {
pub fn generate(rng: &mut impl rand::Rng) -> anyhow::Result<ChaosPostShift> {
use rand::seq::SliceRandom;
let compatible_levels = ["ccl-ground-level.svg"];
Ok(ChaosPostShift {
hours: rng.gen_range(4, 8),
level: compatible_levels.choose(rng).unwrap().to_string(),
})
}
}
impl super::AngelShiftImpl for ChaosPostShift {
fn metadata(&self) -> anyhow::Result<super::ShiftMetadata> {
Ok(super::ShiftMetadata {
title: "Chaos Post".to_owned(),
description: "TODO".to_owned(),
hours: self.hours,
})
}
fn level_name(&self) -> &str {
&self.level
}
fn init_gameworld(
&self,
world: &mut legion::World,
resources: &mut legion::Resources,
schedule_builder: &mut legion::systems::Builder,
level: &svg_loader::SvgLevel,
) -> anyhow::Result<()> {
entities::create_hackers(world, level);
Ok(())
}
}
pub mod bottle_angel;
pub mod chaospost;
mod definitions;
pub mod network_switch;
......@@ -7,9 +8,10 @@ pub use definitions::AngelShiftImpl;
pub use definitions::ShiftMetadata;
pub fn generate_random_shift(rng: &mut impl rand::Rng) -> anyhow::Result<AngelShift> {
Ok(AngelShift(match rng.gen_range(0usize, 2) {
Ok(AngelShift(match rng.gen_range(0usize, 3) {
0 => Box::new(bottle_angel::BottleAngelShift::generate(rng)?),
1 => Box::new(network_switch::NetworkSwitchShift::generate(rng)?),
2 => Box::new(chaospost::ChaosPostShift::generate(rng)?),
_ => unreachable!(),
}))
}
pub struct Hacker {
pub name: String,
pub has_mail_to_send: bool,
}
impl Hacker {
pub fn new(name: String) -> Self {
Hacker {
name,
has_mail_to_send: false,
}
}
}
mod edge;
mod hacker;
mod matebottledrop;
mod movable;
mod network_switch;
......@@ -12,6 +13,7 @@ mod thesun;
pub use edge::draw_edges_system;
pub use edge::Edge;
pub use hacker::Hacker;
pub use matebottledrop::Matebottledrop;
pub use movable::Movable;
pub use network_switch::NetworkSwitch;
......
use crate::colliders;
use crate::components;
use crate::sprites;
use crate::svg_loader;
use rand::seq::SliceRandom;
const HACKER_NAMES: [&str; 30] = [
"r3v3r53",
"qu4k3",
"p4n7h3r",
"4w3",
"c0wb0y",
"fluk3",
"d0pp3l64n63r",
"7w157",
"l364cy",
"fury",
"6r1ff1n",
"5qu1r7",
"c0wb0y",
"5l1v3r",
"7r1x",
"duckl1n6",
"470m",
"ch453",
"d4663r",
"1d0l",
"74l15m4n",
"4w3",
"570rm",
"bl155",
"5pl1n73r",
"l16h7n1n6",
"bull37",
"v31l",
"m47r14rch",
"7r41l",
];
pub fn create_hackers(world: &mut legion::World, level: &svg_loader::SvgLevel) {
let spawn_locations = level
.spawnpoints
.get("hacker")
.expect("no hacker spawn in this map");
if spawn_locations.len() < 6 {
panic!("to few hacker spawns");
}
let positions = spawn_locations.choose_multiple(&mut rand::thread_rng(), 6);
let names = HACKER_NAMES.choose_multiple(&mut rand::thread_rng(), 6);
for (pos, name) in positions.zip(names) {
world.push((
components::Hacker::new(name.to_string()),
components::Position::new(pos.x, pos.y),
colliders::Collider::new_sensor_circle(250.0),
components::Sprite::new(sprites::Sprite::Hacker),
));
}
}
mod hacker;
mod matebottledrop;
mod network_switch;
mod obstacle;
mod player;
pub use hacker::create_hackers;
pub use matebottledrop::create_drop_points;
pub use network_switch::create_network_switches;
pub use obstacle::create_stationary_obstacles;
......
......@@ -278,4 +278,10 @@ impl Rendering {
) -> anyhow::Result<()> {
self.ctx.set_transform(a, b, c, d, e, f).to_anyhow()
}
pub fn fill_text(&self, x: f64, y: f64, text: &str, font_size: f64) -> anyhow::Result<()> {
self.ctx.set_text_align("center");
self.ctx.set_font(&format!("{}px Montserrat", font_size));
self.ctx.fill_text(text, x, y).to_anyhow()
}
}
......@@ -9,6 +9,8 @@ pub enum Sprite {
TrojanHorse,
NetworkSwitchConnected,
NetworkSwitchDisconnected,
Hacker,
HackerHighlighted,
}
impl Sprite {
......@@ -20,6 +22,8 @@ impl Sprite {
Sprite::TrojanHorse => "trojan-horse.svg",
Sprite::NetworkSwitchConnected => "switch-connected.svg",
Sprite::NetworkSwitchDisconnected => "switch-disconnected.svg",
Sprite::Hacker => "hacker.svg",
Sprite::HackerHighlighted => "hacker-highlighted.svg",
}
}
......@@ -48,6 +52,8 @@ impl Sprite {
Sprite::TrojanHorse,
Sprite::NetworkSwitchConnected,
Sprite::NetworkSwitchDisconnected,
Sprite::Hacker,
Sprite::HackerHighlighted,
] {
sprite.load_and_register(renderer).await.unwrap();
}
......
......@@ -70,8 +70,9 @@ impl InGameState {
.add_thread_local(systems::update_sanity_bar_system(sanity_bar))
.add_thread_local(systems::draw_level_layer_system(background))
.add_thread_local(systems::draw_sprites_system())
.add_thread_local(systems::draw_level_layer_system(foreground))
.add_thread_local(systems::draw_tmp_stationary_obstacles_barrier_system())
.add_thread_local(systems::draw_level_layer_system(foreground))
.add_thread_local(systems::draw_hacker_name_system())
// .add_thread_local(systems::draw_debug_colliders_system())
;
let schedule = schedule_builder.build();
......
use crate::colliders;
use crate::components;
use crate::resources;
use anyhow::Context;
use legion::IntoQuery;
#[macro_impl::angel_system]
#[read_component(components::Position)]
#[read_component(components::Hacker)]
#[read_component(colliders::Collider)]
pub fn draw_hacker_name(
world: &legion::world::SubWorld,
#[resource] rendering: &resources::Rendering,
#[resource] player: &resources::Player,
#[resource] collision_world: &colliders::CollisionWorld,
) -> anyhow::Result<()> {
let player_collider = <&colliders::Collider>::query()
.get(world, player.0)
.context("Couldn't find player")?;
rendering.set_fill_style(&resources::Color::with_rgb(1.0, 1.0, 1.0));
let mut hackers = <(&components::Position, &components::Hacker)>::query();
for pair in collision_world
.world
.proximities_with(
player_collider.handle.context("No collider handler")?,
false,
)
.context("Proximities not found")?
{
if pair.3 != ncollide2d::query::Proximity::Intersecting {
continue;
}
let entity = *collision_world
.world
.objects
.get(pair.1)
.context("Couldn't find counterpart")?
.data();
if let Ok((position, hacker)) = hackers.get(world, entity) {
rendering.fill_text(position.0.x as f64, position.0.y as f64, &hacker.name, 50.0)?;
}
}
Ok(())
}
mod camera;
mod draw_colliders;
mod game_manager;
mod hacker;
mod level;
mod moving;
mod player;
......@@ -10,6 +11,7 @@ mod tmp_stationary_obstacles;
pub use camera::camera_system;
pub use draw_colliders::draw_debug_colliders_system;
pub use game_manager::update_game_manager_system;
pub use hacker::draw_hacker_name_system;
pub use level::draw_level_layer_system;
pub use moving::{move_camera_to_player_system, move_movable_system};
pub use player::{
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100"
height="100"
viewBox="0 0 100 100"
version="1.1"
id="svg8"
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
sodipodi:docname="hacker-highlighted.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7.9195959"
inkscape:cx="62.006341"
inkscape:cy="49.136944"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
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:grid
type="xygrid"
id="grid833"
spacingx="2.5"
spacingy="2.5"
empspacing="10" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#0076a9;fill-opacity:0.999176;stroke:#05b9ec;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 13.985267,46.363484 24.269396,36.079355 H 34.553525 L 44.837654,46.363484 V 87.5 L 34.553525,97.784128 Z"
id="path835" />
<circle
style="fill:#0076a9;fill-opacity:0.999176;stroke:#05b9ec;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path839"
cx="49.979717"
cy="20.653164"
r="14.39778" />
<path
style="fill:#0076a9;fill-opacity:0.999176;stroke:#05b9ec;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 85.97417,46.363484 75.690041,36.079355 H 65.405912 L 55.121784,46.363484 V 87.5 l 10.284128,10.284128 z"
id="path901" />
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100"
height="100"
viewBox="0 0 100 100"
version="1.1"
id="svg8"
inkscape:version="1.0.2 (e86c870879, 2021-01-15)"
sodipodi:docname="hacker.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="7.9195959"
inkscape:cx="62.006341"
inkscape:cy="49.136944"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
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:grid
type="xygrid"
id="grid833"
spacingx="2.5"
spacingy="2.5"
empspacing="10" />
</sodipodi:namedview>
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#002a3a;fill-opacity:0.999176;stroke:#025d84;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 13.985267,46.363484 24.269396,36.079355 H 34.553525 L 44.837654,46.363484 V 87.5 L 34.553525,97.784128 Z"
id="path835" />
<circle
style="fill:#002a3a;fill-opacity:0.999176;stroke:#025d84;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path839"
cx="49.979717"
cy="20.653164"
r="14.39778" />
<path
style="fill:#002a3a;fill-opacity:0.999176;stroke:#025d84;stroke-width:3.08523;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 85.97417,46.363484 75.690041,36.079355 H 65.405912 L 55.121784,46.363484 V 87.5 l 10.284128,10.284128 z"
id="path901" />
</g>
</svg>
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