Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
e6222d82ee | ||
|
686b31e41d | ||
|
ffeb6524ce |
15 changed files with 135 additions and 388 deletions
|
@ -59,11 +59,10 @@ jobs:
|
||||||
target
|
target
|
||||||
key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}}"
|
key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}}"
|
||||||
- run: mkdir .ci-destdir
|
- run: mkdir .ci-destdir
|
||||||
- run: cargo install --path . --locked --root .
|
- run: cargo install --path . --locked --root .ci-destdir
|
||||||
- run: find .ci-destdir
|
- run: find .ci-destdir
|
||||||
- uses: forgejo/upload-artifact@v3
|
- uses: forgejo/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: Powercreep
|
name: Powercreep
|
||||||
path: |
|
path:
|
||||||
bin
|
.ci-destdir/*
|
||||||
assets
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
Before Width: | Height: | Size: 30 KiB |
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
12
build.rs
12
build.rs
|
@ -122,20 +122,16 @@ impl AssetsWriter {
|
||||||
writeln!(file, "{indent}impl Assets {{")?;
|
writeln!(file, "{indent}impl Assets {{")?;
|
||||||
writeln!(
|
writeln!(
|
||||||
file,
|
file,
|
||||||
"{indent}\tpub fn load(_ctx: &mut comfy::EngineContext<'_>) {{"
|
"{indent}\tpub fn load(c: &mut comfy::EngineContext<'_>) {{"
|
||||||
)?;
|
)?;
|
||||||
for asset_const_name in root.assets.values() {
|
for asset_const_name in root.assets.values() {
|
||||||
writeln!(file, "{indent}\t\t_ctx.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?;
|
writeln!(file, "{indent}\t\tc.load_texture_from_bytes({asset_const_name:?}, {asset_const_name});")?;
|
||||||
}
|
}
|
||||||
for asset_const_name in root.sound_assets.values() {
|
for asset_const_name in root.sound_assets.values() {
|
||||||
writeln!(file, "{indent}\t\tcomfy::load_sound_from_bytes({asset_const_name:?}, {asset_const_name},")?;
|
writeln!(file, "{indent}\t\tcomfy::load_sound_from_bytes({asset_const_name:?}, {asset_const_name}, Default::default());")?;
|
||||||
writeln!(
|
|
||||||
file,
|
|
||||||
"{indent}\t\t\tcomfy::StaticSoundSettings::new().loop_region(..));"
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
for group_name in root.groups.keys() {
|
for group_name in root.groups.keys() {
|
||||||
writeln!(file, "{indent}\t\t{group_name}::Assets::load(_ctx);")?;
|
writeln!(file, "{indent}\t\t{group_name}::Assets::load(c);")?;
|
||||||
}
|
}
|
||||||
writeln!(file, "{indent}\t}}")?;
|
writeln!(file, "{indent}\t}}")?;
|
||||||
writeln!(file, "{indent}}}")?;
|
writeln!(file, "{indent}}}")?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use comfy::{error, texture_id, EngineContext, HashSet, Lazy, Mutex, TextureHandle};
|
use comfy::{error, texture_id, EngineContext, HashSet, Lazy, Mutex, TextureHandle};
|
||||||
use std::{fmt::Debug, fs, io, path::PathBuf, sync::Arc};
|
use std::{fmt::Debug, fs, io, sync::Arc};
|
||||||
|
|
||||||
static ASSETS_LOADED: Lazy<Arc<Mutex<HashSet<String>>>> =
|
static ASSETS_LOADED: Lazy<Arc<Mutex<HashSet<String>>>> =
|
||||||
Lazy::new(|| Arc::new(Mutex::new(HashSet::new())));
|
Lazy::new(|| Arc::new(Mutex::new(HashSet::new())));
|
||||||
|
@ -39,13 +39,10 @@ impl FurnitureAsset {
|
||||||
if loaded.contains(&path) {
|
if loaded.contains(&path) {
|
||||||
return Some(texture_id(&path));
|
return Some(texture_id(&path));
|
||||||
}
|
}
|
||||||
|
let bytes = match fs::read(format!(
|
||||||
let mut asset_path = PathBuf::from(format!("assets/furniture/{path}"));
|
"{}/assets/furniture/{path}",
|
||||||
if !asset_path.exists() {
|
env!("CARGO_MANIFEST_DIR")
|
||||||
asset_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(asset_path);
|
)) {
|
||||||
}
|
|
||||||
|
|
||||||
let bytes = match fs::read(asset_path) {
|
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => return None,
|
Err(err) if err.kind() == io::ErrorKind::NotFound => return None,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
7
src/activities/house/magnet-shader.wgsl
Normal file
7
src/activities/house/magnet-shader.wgsl
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@fragment
|
||||||
|
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
|
let global_coord: vec3<f32> = in.world_position;
|
||||||
|
let tex = textureSample(t_diffuse, s_diffuse, in.tex_coords);
|
||||||
|
var final_color: vec4<f32> = tex * in.color;
|
||||||
|
return vec4(global_coord, final_color.a);
|
||||||
|
}
|
|
@ -3,59 +3,36 @@ mod grid;
|
||||||
mod player;
|
mod player;
|
||||||
mod room;
|
mod room;
|
||||||
|
|
||||||
use crate::assets::ASSETS;
|
use comfy::{main_camera_mut, random_i32, vec2, EngineContext, RandomRange as _};
|
||||||
use comfy::{
|
|
||||||
delta, main_camera_mut, play_sound_id, random_i32, stop_sound_id, vec2,
|
|
||||||
EngineContext, RandomRange as _
|
|
||||||
};
|
|
||||||
use grid::Grid;
|
use grid::Grid;
|
||||||
use indexmap::IndexSet;
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use player::Player;
|
use player::Player;
|
||||||
use room::Room;
|
use room::Room;
|
||||||
|
|
||||||
use super::Activity;
|
|
||||||
|
|
||||||
const MAX_ROOMS: i32 = 6;
|
const MAX_ROOMS: i32 = 6;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HouseState {
|
pub struct HouseState {
|
||||||
current_room_id: usize,
|
current_room_id: usize,
|
||||||
room_count: usize,
|
room_count: usize,
|
||||||
human_count: usize,
|
|
||||||
rooms: Vec<Room>,
|
rooms: Vec<Room>,
|
||||||
human_rooms: Vec<usize>,
|
|
||||||
//grid: Grid,
|
//grid: Grid,
|
||||||
player: Player,
|
player: Player,
|
||||||
human_layer: bool, //Human, magnetic, electric
|
human_layer: bool, //Human, magnetic, electric
|
||||||
exit_time: f32,
|
|
||||||
|
|
||||||
/// The energy level remaining in the house. Should decrease by itself, and much
|
/// The energy level remaining in the house. Should decrease by itself, and much
|
||||||
/// faster when inhabited by the ghost.
|
/// faster when inhabited by the ghost.
|
||||||
pub charge: f32,
|
pub charge: f32,
|
||||||
pub max_charge: f32,
|
pub max_charge: f32
|
||||||
|
|
||||||
pub sound_playing: bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HouseState {
|
impl HouseState {
|
||||||
pub fn generate_new_house(ctx: &mut EngineContext<'_>) -> Self {
|
pub fn generate_new_house(ctx: &mut EngineContext<'_>) -> Self {
|
||||||
let room_count = random_i32(2, MAX_ROOMS) as usize;
|
let room_count = random_i32(2, MAX_ROOMS) as usize;
|
||||||
let human_count = random_i32(1, room_count as i32) as usize;
|
|
||||||
|
|
||||||
let mut possible_rooms: IndexSet<usize> = (0 .. room_count).collect();
|
|
||||||
let mut human_rooms = Vec::new();
|
|
||||||
for _ in 0 .. human_count {
|
|
||||||
if !possible_rooms.is_empty() {
|
|
||||||
let random_idx = usize::gen_range(0, possible_rooms.len());
|
|
||||||
|
|
||||||
human_rooms.push(possible_rooms.swap_remove_index(random_idx).unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut rooms = Vec::new();
|
let mut rooms = Vec::new();
|
||||||
for i in 0 .. room_count {
|
for _ in 0 .. room_count {
|
||||||
rooms.push(Room::new(ctx, human_rooms.contains(&i)));
|
rooms.push(Room::new(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
let player = Player::new(rooms.first().unwrap());
|
let player = Player::new(rooms.first().unwrap());
|
||||||
|
@ -63,33 +40,29 @@ impl HouseState {
|
||||||
HouseState {
|
HouseState {
|
||||||
current_room_id: 0,
|
current_room_id: 0,
|
||||||
room_count,
|
room_count,
|
||||||
human_count,
|
|
||||||
rooms,
|
rooms,
|
||||||
human_rooms,
|
|
||||||
player,
|
player,
|
||||||
human_layer: false,
|
human_layer: false,
|
||||||
exit_time: 0.0,
|
|
||||||
// TODO this should be lower depending on the time elapsed
|
// TODO this should be lower depending on the time elapsed
|
||||||
charge: max_charge,
|
charge: max_charge,
|
||||||
max_charge,
|
max_charge
|
||||||
|
|
||||||
sound_playing: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(state: &crate::State, _ctx: &EngineContext<'_>) {
|
pub fn draw(state: &crate::State, _ctx: &mut comfy::EngineContext<'_>) {
|
||||||
let Some(house) = state.house() else {
|
let Some(house) = state.house() else {
|
||||||
error!("How can I render a house when I'm not in one?!?");
|
error!("How can I render a house when I'm not in one?!?");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Draw House
|
//Draw House
|
||||||
house
|
house.rooms.get(house.current_room_id).unwrap().draw(
|
||||||
.rooms
|
house.human_layer,
|
||||||
.get(house.current_room_id)
|
house.player.can_see_metal(0.1),
|
||||||
.unwrap()
|
house.player.get_position(),
|
||||||
.draw(house.human_layer, house.player.can_see_metal(0.1));
|
_ctx
|
||||||
|
);
|
||||||
|
|
||||||
//Draw Grid
|
//Draw Grid
|
||||||
//state.house.grid.draw();
|
//state.house.grid.draw();
|
||||||
|
@ -98,27 +71,13 @@ pub fn draw(state: &crate::State, _ctx: &EngineContext<'_>) {
|
||||||
house.player.draw();
|
house.player.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(state: &mut crate::State, ctx: &mut EngineContext<'_>) {
|
pub fn update(state: &mut crate::State, ctx: &mut comfy::EngineContext<'_>) {
|
||||||
if state.overworld.sound_playing {
|
|
||||||
stop_sound_id(ASSETS.music.galactic_rap_speedup);
|
|
||||||
state.overworld.sound_playing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut camera = main_camera_mut();
|
let mut camera = main_camera_mut();
|
||||||
camera.center = vec2(0.0, 0.0);
|
camera.center = vec2(0.0, 0.0);
|
||||||
drop(camera);
|
|
||||||
|
|
||||||
let Some(house) = state.house_mut(ctx) else {
|
let house = state.house_mut(ctx);
|
||||||
error!("WTF I cannot update a house without a house");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let current_room = house.rooms.get(house.current_room_id).unwrap();
|
let current_room = house.rooms.get(house.current_room_id).unwrap();
|
||||||
house.player.update(¤t_room);
|
house.player.update(¤t_room.grid);
|
||||||
|
|
||||||
if !house.sound_playing {
|
|
||||||
play_sound_id(ASSETS.music.mesmerizing_galaxy_loop);
|
|
||||||
house.sound_playing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if house.player.is_moving_to_right_room(current_room) {
|
if house.player.is_moving_to_right_room(current_room) {
|
||||||
if house.current_room_id < (house.room_count - 1) {
|
if house.current_room_id < (house.room_count - 1) {
|
||||||
|
@ -139,18 +98,4 @@ pub fn update(state: &mut crate::State, ctx: &mut EngineContext<'_>) {
|
||||||
house.player.reset_on_room(current_room, true);
|
house.player.reset_on_room(current_room, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if house.player.successfull_attack {
|
|
||||||
house.human_layer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if house.human_layer {
|
|
||||||
house.exit_time += delta();
|
|
||||||
}
|
|
||||||
|
|
||||||
if house.exit_time >= 2.0 {
|
|
||||||
state.score += 500.0;
|
|
||||||
state.ghost.overworld_pos -= vec2(0.0, 1.0);
|
|
||||||
state.activity = Activity::Overworld;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,7 @@ use super::{
|
||||||
room::{Room, SCALE},
|
room::{Room, SCALE},
|
||||||
Grid
|
Grid
|
||||||
};
|
};
|
||||||
use comfy::{
|
use comfy::{delta, draw_circle, is_key_down, vec2, KeyCode, Vec2, RED};
|
||||||
delta, draw_circle, draw_sprite, is_key_down, is_key_pressed, main_camera_mut,
|
|
||||||
texture_id, vec2, KeyCode, Vec2, RED, WHITE
|
|
||||||
};
|
|
||||||
use log::error;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -17,8 +13,7 @@ pub struct Player {
|
||||||
current_acceleration: f32,
|
current_acceleration: f32,
|
||||||
movement_time: f32,
|
movement_time: f32,
|
||||||
connection: usize,
|
connection: usize,
|
||||||
next_connections: Vec<usize>,
|
next_connections: Vec<usize>
|
||||||
pub successfull_attack: bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
|
@ -33,24 +28,18 @@ impl Player {
|
||||||
current_acceleration: 0.0,
|
current_acceleration: 0.0,
|
||||||
movement_time: 0.0,
|
movement_time: 0.0,
|
||||||
connection: 0,
|
connection: 0,
|
||||||
next_connections: vec![1],
|
next_connections: vec![1]
|
||||||
successfull_attack: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_position(&self) -> Vec2 {
|
||||||
|
self.position
|
||||||
|
}
|
||||||
pub fn draw(&self) {
|
pub fn draw(&self) {
|
||||||
//draw_circle(self.position, 0.5, RED, 0);
|
draw_circle(self.position, 0.5, RED, 0);
|
||||||
draw_sprite(
|
|
||||||
texture_id("ghost_house"),
|
|
||||||
self.position,
|
|
||||||
WHITE,
|
|
||||||
5,
|
|
||||||
vec2(1.25, 1.25)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, room: &Room) {
|
pub fn update(&mut self, grid: &Grid) {
|
||||||
let grid = &room.grid;
|
|
||||||
let allowed_movement = get_allowed_movement(self, grid);
|
let allowed_movement = get_allowed_movement(self, grid);
|
||||||
|
|
||||||
move_player(self, allowed_movement);
|
move_player(self, allowed_movement);
|
||||||
|
@ -58,8 +47,6 @@ impl Player {
|
||||||
if !on_current_connection(self, grid) && !update_connections(self, grid) {
|
if !on_current_connection(self, grid) && !update_connections(self, grid) {
|
||||||
snap_to_closest_node(self, grid);
|
snap_to_closest_node(self, grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
attack_human_routine(self, room);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_moving_to_right_room(&self, room: &Room) -> bool {
|
pub fn is_moving_to_right_room(&self, room: &Room) -> bool {
|
||||||
|
@ -369,42 +356,3 @@ fn snap_to_closest_node(player: &mut Player, grid: &Grid) {
|
||||||
|
|
||||||
player.position = *closest_node;
|
player.position = *closest_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attack_human_routine(player: &mut Player, room: &Room) {
|
|
||||||
let range = 1.0;
|
|
||||||
|
|
||||||
if is_key_pressed(KeyCode::Space) {
|
|
||||||
//In some node range?
|
|
||||||
let mut in_range = false;
|
|
||||||
for node in &room.grid.nodes {
|
|
||||||
if in_node_range(&player.position, node, range) {
|
|
||||||
in_range = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if in_range {
|
|
||||||
let (human_pos, human_nodes) = room.get_human_information();
|
|
||||||
|
|
||||||
let mut human_attacked = false;
|
|
||||||
|
|
||||||
if human_pos.is_some() {
|
|
||||||
for node_index in human_nodes {
|
|
||||||
if in_node_range(
|
|
||||||
&player.position,
|
|
||||||
room.grid.nodes.get(*node_index).unwrap(),
|
|
||||||
range
|
|
||||||
) {
|
|
||||||
human_attacked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if human_attacked {
|
|
||||||
player.successfull_attack = true;
|
|
||||||
} else {
|
|
||||||
main_camera_mut().shake(1.0, 1.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use super::{furniture::Furniture, grid::Grid};
|
use super::{furniture::Furniture, grid::Grid};
|
||||||
use crate::game::{self, ZLayer};
|
use crate::game;
|
||||||
use comfy::{
|
use comfy::{
|
||||||
draw_rect, draw_rect_outline, draw_sprite, error, random_i32, texture_id, vec2,
|
create_reloadable_sprite_shader, draw_rect, draw_rect_outline, draw_sprite, error, hashmap, random_i32, set_uniform_f32, use_default_shader, use_shader, vec2, EngineContext, HashSet, Index, RandomRange as _, ReloadableShaderSource, UniformDef, Vec2, GREEN, PURPLE, RED, WHITE
|
||||||
EngineContext, HashSet, RandomRange as _, Vec2, BLUE, GREEN, PURPLE, RED, WHITE
|
|
||||||
};
|
};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
|
@ -30,9 +29,7 @@ pub struct Room {
|
||||||
_room_type: RoomType,
|
_room_type: RoomType,
|
||||||
pub size: (u8, u8), //(width, height)
|
pub size: (u8, u8), //(width, height)
|
||||||
pub grid: Grid,
|
pub grid: Grid,
|
||||||
furnitures: Vec<Tile>,
|
furnitures: Vec<Tile>
|
||||||
human_pos: Option<Vec2>,
|
|
||||||
human_nodes: Vec<usize>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomType {
|
impl RoomType {
|
||||||
|
@ -49,60 +46,20 @@ impl RoomType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
pub fn new(ctx: &mut EngineContext<'_>, with_human: bool) -> Self {
|
pub fn new(ctx: &mut EngineContext<'_>) -> Self {
|
||||||
let room_type = RoomType::random();
|
let room_type = RoomType::random();
|
||||||
let size = Self::random_size(&room_type);
|
let size = Self::random_size(&room_type);
|
||||||
|
|
||||||
let furnitures = Self::random_room_furniture(&room_type, size, ctx);
|
let furnitures = Self::random_room_furniture(&room_type, size, ctx);
|
||||||
|
|
||||||
let grid = Self::create_grid(size.0, size.1);
|
|
||||||
|
|
||||||
let (human_pos, human_nodes) = if with_human {
|
|
||||||
let mut human_pos = vec2(random_i32(1, size.0 as i32) as f32 + 0.5, 1.0f32);
|
|
||||||
human_pos -= vec2(size.0 as f32 / 2.0, size.1 as f32 / 2.0);
|
|
||||||
human_pos *= SCALE;
|
|
||||||
|
|
||||||
let node_index_left = grid
|
|
||||||
.nodes
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0)
|
|
||||||
.filter(|(_i, &node)| node.x <= (human_pos.x - 0.5 * SCALE))
|
|
||||||
.max_by_key(|(_i, &node)| node.x as i32)
|
|
||||||
.map(|(i, _)| i)
|
|
||||||
.unwrap();
|
|
||||||
let node_index_right = grid
|
|
||||||
.nodes
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(_i, &node)| node.y <= size.1 as f32 / 6.0)
|
|
||||||
.filter(|(_i, &node)| node.x >= (human_pos.x + 0.5 * SCALE))
|
|
||||||
.min_by_key(|(_i, &node)| node.x as i32)
|
|
||||||
.map(|(i, _)| i)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
(
|
|
||||||
Some(human_pos),
|
|
||||||
(node_index_left ..= node_index_right).collect()
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(None, Vec::new())
|
|
||||||
};
|
|
||||||
|
|
||||||
Room {
|
Room {
|
||||||
_room_type: room_type,
|
_room_type: room_type,
|
||||||
size,
|
size,
|
||||||
grid,
|
grid: Self::create_grid(size.0, size.1),
|
||||||
furnitures,
|
furnitures
|
||||||
human_pos,
|
|
||||||
human_nodes
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_human_information(&self) -> (Option<Vec2>, &Vec<usize>) {
|
|
||||||
(self.human_pos, &self.human_nodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn random_size(room_type: &RoomType) -> (u8, u8) {
|
fn random_size(room_type: &RoomType) -> (u8, u8) {
|
||||||
//Kitchen + Living Room 5-8
|
//Kitchen + Living Room 5-8
|
||||||
//Bath + sleepingroom 4-6
|
//Bath + sleepingroom 4-6
|
||||||
|
@ -327,7 +284,8 @@ impl Room {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
RoomType::LivingRoom => {
|
_ => {
|
||||||
|
//RoomType::LivingRoom => {
|
||||||
let has_couch = match u8::gen_range(0, 2) {
|
let has_couch = match u8::gen_range(0, 2) {
|
||||||
0 => false,
|
0 => false,
|
||||||
1 => true,
|
1 => true,
|
||||||
|
@ -361,9 +319,8 @@ impl Room {
|
||||||
z: 0
|
z: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
//_ => {}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
furnitures
|
furnitures
|
||||||
|
@ -419,7 +376,13 @@ impl Room {
|
||||||
Grid::new(nodes, connections)
|
Grid::new(nodes, connections)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&self, human_layer: bool, magnet_layer: bool) {
|
pub fn draw(
|
||||||
|
&self,
|
||||||
|
human_layer: bool,
|
||||||
|
magnet_layer: bool,
|
||||||
|
position: Vec2,
|
||||||
|
_ctx: &mut comfy::EngineContext<'_>
|
||||||
|
) {
|
||||||
let (width, height) = self.size;
|
let (width, height) = self.size;
|
||||||
|
|
||||||
draw_rect(
|
draw_rect(
|
||||||
|
@ -460,16 +423,37 @@ impl Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if magnet_layer {
|
if true {
|
||||||
|
let magnet_shader_id = Some(
|
||||||
|
create_reloadable_sprite_shader(
|
||||||
|
&mut _ctx.renderer.shaders.borrow_mut(),
|
||||||
|
"magnet-shader",
|
||||||
|
ReloadableShaderSource {
|
||||||
|
static_source: include_str!("magnet-shader.wgsl").to_string(),
|
||||||
|
path: "src/activities/house/magnet-shader.wgsl".to_string()
|
||||||
|
},
|
||||||
|
hashmap! {
|
||||||
|
// "px".to_string() => UniformDef::F32(None),
|
||||||
|
// "py".to_string() => UniformDef::F32(None),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
use_shader(magnet_shader_id);
|
||||||
|
// set_uniform_f32("px", position.x);
|
||||||
|
// set_uniform_f32("py", position.y);
|
||||||
|
|
||||||
if let Some(texture) = tile.f.get_magnet_texture_handle() {
|
if let Some(texture) = tile.f.get_magnet_texture_handle() {
|
||||||
draw_sprite(
|
draw_sprite(
|
||||||
texture,
|
texture,
|
||||||
pos * SCALE,
|
pos * SCALE,
|
||||||
BLUE,
|
WHITE,
|
||||||
game::ZLayer::MagneticLayer as i32 + tile.z,
|
game::ZLayer::MagneticLayer as i32 + tile.z,
|
||||||
tile.size * SCALE
|
tile.size * SCALE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
use_default_shader();
|
||||||
}
|
}
|
||||||
|
|
||||||
if tile.f.is_on() {
|
if tile.f.is_on() {
|
||||||
|
@ -485,24 +469,6 @@ impl Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if human_layer {
|
|
||||||
if let Some(human_pos) = self.human_pos {
|
|
||||||
//draw_circle(human_pos, 0.5, RED, 20);
|
|
||||||
draw_sprite(
|
|
||||||
texture_id("human_house"),
|
|
||||||
human_pos,
|
|
||||||
WHITE,
|
|
||||||
ZLayer::Human.into(),
|
|
||||||
vec2(1.0, 2.0) * SCALE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Debug draw
|
|
||||||
for node_index in &self.human_nodes {
|
|
||||||
draw_circle(*self.grid.nodes.get(*node_index).unwrap(), 0.5, GREEN, ZLayer::Human.into());
|
|
||||||
}*/
|
|
||||||
|
|
||||||
self.grid.draw();
|
self.grid.draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,18 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::Activity,
|
activities::Activity,
|
||||||
assets::ASSETS,
|
|
||||||
game::{ZLayer, GHOST_DISCHARGE_RATE, GHOST_DISCHARGE_RATE_MOVEMENT},
|
game::{ZLayer, GHOST_DISCHARGE_RATE, GHOST_DISCHARGE_RATE_MOVEMENT},
|
||||||
State
|
State
|
||||||
};
|
};
|
||||||
use comfy::{
|
use comfy::{
|
||||||
draw_rect_outline, draw_sprite, error, info, is_key_down, main_camera_mut,
|
delta, draw_circle, draw_rect_outline, draw_sprite, error, info, is_key_down,
|
||||||
play_sound_id, stop_sound_id, texture_id, vec2, EngineContext, IVec2, KeyCode, Vec2,
|
main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE
|
||||||
RED, WHITE
|
|
||||||
};
|
};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use worldgen::MovementCost;
|
use worldgen::MovementCost;
|
||||||
|
|
||||||
pub mod worldgen;
|
pub mod worldgen;
|
||||||
|
|
||||||
pub fn setup(_state: &State, ctx: &EngineContext<'_>) {
|
pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
|
||||||
ctx.load_texture_from_bytes(
|
|
||||||
"human_overworld",
|
|
||||||
include_bytes!(concat!(
|
|
||||||
env!("CARGO_MANIFEST_DIR"),
|
|
||||||
"/assets/entities/human_overworld.png"
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw(state: &State, _ctx: &EngineContext<'_>) {
|
|
||||||
for (coords, tile) in state.overworld.iter_tiles() {
|
for (coords, tile) in state.overworld.iter_tiles() {
|
||||||
for (i, texture) in tile.textures().iter().rev().enumerate() {
|
for (i, texture) in tile.textures().iter().rev().enumerate() {
|
||||||
let i = i as i32;
|
let i = i as i32;
|
||||||
|
@ -40,32 +28,12 @@ pub fn draw(state: &State, _ctx: &EngineContext<'_>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
draw_circle(state.ghost.overworld_pos, 0.5, RED, ZLayer::Ghost.into());
|
||||||
let mut ghost_pos = state.ghost.overworld_pos;
|
|
||||||
ghost_pos.y += 0.5;
|
|
||||||
draw_sprite(
|
|
||||||
texture_id("human_overworld"),
|
|
||||||
ghost_pos,
|
|
||||||
WHITE,
|
|
||||||
ZLayer::Ghost.into(),
|
|
||||||
vec2(1.0, 1.25)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_move_player(state: &mut State, ctx: &mut EngineContext<'_>) {
|
fn update_move_player(state: &mut State, _ctx: &mut EngineContext<'_>) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
if !state.overworld.sound_playing {
|
|
||||||
if let Some(house) = state.house_mut(ctx) {
|
|
||||||
if house.sound_playing {
|
|
||||||
stop_sound_id(ASSETS.music.mesmerizing_galaxy_loop);
|
|
||||||
house.sound_playing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
play_sound_id(ASSETS.music.galactic_rap_speedup);
|
|
||||||
state.overworld.sound_playing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Are there any pending position updates? If so, we ignore all user input and execute
|
// Are there any pending position updates? If so, we ignore all user input and execute
|
||||||
// the pending updates.
|
// the pending updates.
|
||||||
if state.ghost.overworld_movement_pending != Vec2::ZERO {
|
if state.ghost.overworld_movement_pending != Vec2::ZERO {
|
||||||
|
@ -173,10 +141,10 @@ fn update_move_player(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||||
},
|
},
|
||||||
|
|
||||||
// we are walking on a path
|
// we are walking on a path
|
||||||
(MovementCost::Path, MovementCost::Path) => 7.0,
|
(MovementCost::Path, MovementCost::Path) => 10.0,
|
||||||
|
|
||||||
// we are walking across an obstacle
|
// we are walking across an obstacle
|
||||||
(MovementCost::Obstacle, _) | (_, MovementCost::Obstacle) => 2.0,
|
(MovementCost::Obstacle, _) | (_, MovementCost::Obstacle) => 1.0,
|
||||||
|
|
||||||
// we are walking on grass
|
// we are walking on grass
|
||||||
_ => 5.0
|
_ => 5.0
|
||||||
|
|
|
@ -422,9 +422,7 @@ impl Chunk {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Overworld {
|
pub struct Overworld {
|
||||||
chunks: HashMap<IVec2, Chunk>,
|
chunks: HashMap<IVec2, Chunk>
|
||||||
|
|
||||||
pub sound_playing: bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn world_to_chunk_and_local_coords(world_coords: IVec2) -> (IVec2, UVec2) {
|
fn world_to_chunk_and_local_coords(world_coords: IVec2) -> (IVec2, UVec2) {
|
||||||
|
|
97
src/game.rs
97
src/game.rs
|
@ -75,8 +75,7 @@ pub enum ZLayer {
|
||||||
MapMax = -1,
|
MapMax = -1,
|
||||||
Human = 0,
|
Human = 0,
|
||||||
Ghost = 1,
|
Ghost = 1,
|
||||||
UI = 100,
|
UI = 100
|
||||||
GameOver = 1000
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ZLayer> for i32 {
|
impl From<ZLayer> for i32 {
|
||||||
|
@ -102,90 +101,66 @@ impl Add<i32> for ZLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(state: &mut State, ctx: &mut EngineContext<'_>) {
|
pub fn setup(_state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||||
Assets::load(ctx);
|
Assets::load(ctx);
|
||||||
|
|
||||||
overworld::setup(state, ctx);
|
|
||||||
//house::setup(state, ctx);
|
//house::setup(state, ctx);
|
||||||
|
|
||||||
ctx.load_texture_from_bytes(
|
|
||||||
"ghost_house",
|
|
||||||
include_bytes!(concat!(
|
|
||||||
env!("CARGO_MANIFEST_DIR"),
|
|
||||||
"/assets/entities/ghost.png"
|
|
||||||
))
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.load_texture_from_bytes(
|
|
||||||
"human_house",
|
|
||||||
include_bytes!(concat!(
|
|
||||||
env!("CARGO_MANIFEST_DIR"),
|
|
||||||
"/assets/entities/human_captured.png"
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The amount of energy a ghost consumes idle.
|
/// The amount of energy a ghost consumes idle.
|
||||||
pub const GHOST_DISCHARGE_RATE: f32 = 40.0;
|
pub const GHOST_DISCHARGE_RATE: f32 = 70.0;
|
||||||
/// The amount of energy additionally consumed by a moving ghost.
|
/// The amount of energy additionally consumed by a moving ghost.
|
||||||
pub const GHOST_DISCHARGE_RATE_MOVEMENT: f32 = 40.0;
|
pub const GHOST_DISCHARGE_RATE_MOVEMENT: f32 = 70.0;
|
||||||
/// The amount of energy a house consumes idle.
|
/// The amount of energy a house consumes idle.
|
||||||
pub const HOUSE_DISCHARGE_RATE: f32 = 30.0;
|
pub const HOUSE_DISCHARGE_RATE: f32 = 30.0;
|
||||||
/// The amount of energy a ghost can charge when inside a house.
|
/// The amount of energy a ghost can charge when inside a house.
|
||||||
pub const GHOST_CHARGE_RATE: f32 = 200.0;
|
pub const GHOST_CHARGE_RATE: f32 = 200.0;
|
||||||
|
|
||||||
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
|
pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
|
||||||
if state.ghost.charge > 0.0 {
|
// Update the score. It's based on time.
|
||||||
// Update the score. It's based on time.
|
state.score += ctx.delta * 10.0;
|
||||||
state.score += ctx.delta * 10.0;
|
|
||||||
|
// Update the currently active activity.
|
||||||
|
match state.activity {
|
||||||
|
Activity::House(_) => house::update(state, ctx),
|
||||||
|
Activity::Overworld => overworld::update(state, ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We update the charge of houses here - the charge will always decrease, even if the
|
||||||
|
// house is not the current activity.
|
||||||
|
for (house_pos, house) in &mut state.houses {
|
||||||
|
house.charge -= ctx.delta * HOUSE_DISCHARGE_RATE;
|
||||||
|
|
||||||
// Update the currently active activity.
|
|
||||||
match state.activity {
|
match state.activity {
|
||||||
Activity::House(_) => house::update(state, ctx),
|
Activity::House(pos) if *house_pos == pos => {
|
||||||
Activity::Overworld => overworld::update(state, ctx)
|
// The ghost is currently inside the house. Increase its discarge rate.
|
||||||
|
house.charge -= ctx.delta * GHOST_DISCHARGE_RATE;
|
||||||
|
if house.charge < 0.0 {
|
||||||
|
state.ghost.charge += house.charge;
|
||||||
|
house.charge = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// And possibly also charge the ghost when inside a house.
|
||||||
|
if state.ghost.charge < state.ghost.max_charge {
|
||||||
|
let charge_transfer = (ctx.delta * GHOST_CHARGE_RATE)
|
||||||
|
.min(state.ghost.max_charge - state.ghost.charge)
|
||||||
|
.min(house.charge);
|
||||||
|
state.ghost.charge += charge_transfer;
|
||||||
|
house.charge -= charge_transfer;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We update the charge of houses here - the charge will always decrease, even if the
|
|
||||||
// house is not the current activity.
|
|
||||||
for (house_pos, house) in &mut state.houses {
|
|
||||||
house.charge -= ctx.delta * HOUSE_DISCHARGE_RATE;
|
|
||||||
|
|
||||||
match state.activity {
|
|
||||||
Activity::House(pos) if *house_pos == pos => {
|
|
||||||
// The ghost is currently inside the house. Increase its discarge rate.
|
|
||||||
house.charge -= ctx.delta * GHOST_DISCHARGE_RATE;
|
|
||||||
if house.charge < 0.0 {
|
|
||||||
state.ghost.charge += house.charge;
|
|
||||||
house.charge = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// And possibly also charge the ghost when inside a house.
|
|
||||||
if state.ghost.charge < state.ghost.max_charge {
|
|
||||||
let charge_transfer = (ctx.delta * GHOST_CHARGE_RATE)
|
|
||||||
.min(state.ghost.max_charge - state.ghost.charge)
|
|
||||||
.min(house.charge);
|
|
||||||
state.ghost.charge += charge_transfer;
|
|
||||||
house.charge -= charge_transfer;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
crate::game_over::update(state, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the ghost's charge never drops below 0.
|
// Make sure the ghost's charge never drops below 0.
|
||||||
state.ghost.charge = state.ghost.charge.max(0.0);
|
state.ghost.charge = state.ghost.charge.max(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(state: &State, engine: &EngineContext<'_>) {
|
pub fn draw(state: &State, engine: &mut EngineContext<'_>) {
|
||||||
match state.activity {
|
match state.activity {
|
||||||
Activity::House(_) => house::draw(state, engine),
|
Activity::House(_) => house::draw(state, engine),
|
||||||
Activity::Overworld => overworld::draw(state, engine)
|
Activity::Overworld => overworld::draw(state, engine)
|
||||||
}
|
}
|
||||||
crate::ui::draw(state, engine);
|
crate::ui::draw(state, engine);
|
||||||
if state.ghost.charge <= 0.0 {
|
|
||||||
crate::game_over::draw(state, engine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
use std::mem::take;
|
|
||||||
|
|
||||||
use crate::{game::ZLayer, State};
|
|
||||||
use comfy::{
|
|
||||||
draw_rect, egui,
|
|
||||||
egui::{Align, Layout},
|
|
||||||
is_key_pressed, main_camera, Color, EngineContext, WHITE
|
|
||||||
};
|
|
||||||
use egui::{Align2, RichText};
|
|
||||||
use log::info;
|
|
||||||
|
|
||||||
pub fn update(state: &mut State, _engine: &mut EngineContext<'_>) {
|
|
||||||
if is_key_pressed(comfy::KeyCode::Return) {
|
|
||||||
info!("Restart game");
|
|
||||||
take(state); //reset to default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn draw(state: &State, _engine: &EngineContext<'_>) {
|
|
||||||
let cam = main_camera();
|
|
||||||
draw_rect(
|
|
||||||
cam.center,
|
|
||||||
cam.world_viewport() * 1.2,
|
|
||||||
Color::new(0.0, 0.0, 0.0, 0.5),
|
|
||||||
ZLayer::GameOver.into()
|
|
||||||
);
|
|
||||||
|
|
||||||
egui::Area::new("game_over")
|
|
||||||
.anchor(Align2::CENTER_CENTER, egui::vec2(0.0, 0.0))
|
|
||||||
.show(egui(), |ui| {
|
|
||||||
ui.with_layout(Layout::top_down_justified(Align::Center), |ui| {
|
|
||||||
ui.heading(
|
|
||||||
RichText::new(
|
|
||||||
"The poor spirit lost all their energy and starved to death"
|
|
||||||
)
|
|
||||||
.color(WHITE)
|
|
||||||
.strong()
|
|
||||||
.size(50.0)
|
|
||||||
);
|
|
||||||
ui.label(
|
|
||||||
RichText::new(format!("\nYour Score:\n{:.0}", state.score))
|
|
||||||
.color(WHITE)
|
|
||||||
.size(30.0)
|
|
||||||
);
|
|
||||||
ui.label(
|
|
||||||
RichText::new("\n\n\npress enter to restart")
|
|
||||||
.color(WHITE)
|
|
||||||
.size(30.0)
|
|
||||||
);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
18
src/main.rs
18
src/main.rs
|
@ -5,9 +5,9 @@
|
||||||
mod assets {
|
mod assets {
|
||||||
include!(env!("ASSETS_RS"));
|
include!(env!("ASSETS_RS"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mod activities;
|
mod activities;
|
||||||
mod game;
|
mod game;
|
||||||
mod game_over;
|
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
|
@ -59,23 +59,23 @@ impl State {
|
||||||
self.houses.get(&self.get_house_pos()?)
|
self.houses.get(&self.get_house_pos()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> Option<&mut HouseState> {
|
fn house_mut(&mut self, ctx: &mut EngineContext<'_>) -> &mut HouseState {
|
||||||
Some(
|
self.houses
|
||||||
self.houses
|
.entry(self.get_house_pos().unwrap())
|
||||||
.entry(self.get_house_pos()?)
|
.or_insert_with(|| HouseState::generate_new_house(ctx))
|
||||||
.or_insert_with(|| HouseState::generate_new_house(ctx))
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameLoop for State {
|
impl GameLoop for State {
|
||||||
fn new(_c: &mut EngineState) -> Self {
|
fn new(_c: &mut EngineState) -> Self {
|
||||||
Default::default()
|
Self {
|
||||||
|
dev: dev_from_env(),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &mut EngineContext<'_>) {
|
fn update(&mut self, ctx: &mut EngineContext<'_>) {
|
||||||
if !self.setup_called {
|
if !self.setup_called {
|
||||||
self.dev = dev_from_env();
|
|
||||||
game::setup(self, ctx);
|
game::setup(self, ctx);
|
||||||
game::setup(self, ctx);
|
game::setup(self, ctx);
|
||||||
self.setup_called = true;
|
self.setup_called = true;
|
||||||
|
|
Loading…
Reference in a new issue