This commit is contained in:
Evan Pratten 2021-10-01 20:26:57 -04:00
parent 28ea07bed9
commit 9c2d636703
15 changed files with 104 additions and 52 deletions

View File

@ -31,6 +31,7 @@ pkg-version = "1.0"
cfg-if = "1.0"
num-derive = "0.3"
num = "0.4"
tiled = { version ="0.9.5", default-features = false }
[dev-dependencies]
puffin_viewer = "0.6"

View File

@ -1,5 +1,46 @@
{
"name": "Unnamed game",
"base_window_size": [1080, 720],
"sentry_dsn": "https://d5d94e75f08841388287fa0c23606ac7@o398481.ingest.sentry.io/5985679"
"base_window_size": [
1080,
720
],
"sentry_dsn": "https://d5d94e75f08841388287fa0c23606ac7@o398481.ingest.sentry.io/5985679",
"colors": {
"red": [
240,
70,
53,
255
],
"blue": [
101,
75,
250,
255
],
"green": [
61,
227,
161,
255
],
"yellow": [
250,
235,
55,
255
],
"pink": [
240,
246,
227,
255
],
"background": [
20,
20,
20,
255
]
}
}

View File

@ -1,5 +1,5 @@
{
"pixel_scale": 1.0,
"warp_factor": 0.5,
"scanline_darkness": 0.5
"warp_factor": 0.65,
"scanline_darkness": 0.55
}

View File

@ -1,19 +1,19 @@
use std::cell::RefCell;
use crate::utilities::non_ref_raylib::HackedRaylibHandle;
use crate::{GameConfig, utilities::non_ref_raylib::HackedRaylibHandle};
#[derive(Debug)]
pub struct GameContext {
pub renderer: RefCell<HackedRaylibHandle>
pub renderer: RefCell<HackedRaylibHandle>,
pub config: GameConfig
}
impl GameContext {
/// Construct a new game context.
pub fn new(raylib: RefCell<HackedRaylibHandle>) -> Self {
Self {
renderer: raylib
}
}
}
// impl GameContext {
// /// Construct a new game context.
// pub fn new(raylib: RefCell<HackedRaylibHandle>) -> Self {
// Self {
// renderer: raylib
// }
// }
// }

View File

@ -158,7 +158,10 @@ pub async fn game_begin(game_config: &GameConfig) -> Result<(), Box<dyn std::err
raylib_thread = thread;
// Build the game context
context = Box::new(GameContext::new(RefCell::new(rl.into())));
context = Box::new(GameContext {
renderer: RefCell::new(rl.into()),
config: game_config.clone(),
});
}
// Get the main state machine

View File

@ -1,5 +1,3 @@
use dirty_fsm::{Action, ActionFlag};
use raylib::{color::Color, prelude::RaylibDraw};
use tracing::{debug, trace};
@ -7,6 +5,7 @@ use tracing::{debug, trace};
use crate::{
context::GameContext,
utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::ScreenSpaceRender},
GameConfig,
};
use super::{Scenes, ScreenError};
@ -38,7 +37,7 @@ impl Action<Scenes, ScreenError, GameContext> for FsmErrorScreen {
context: &GameContext,
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
trace!("execute() called on FsmErrorScreen");
self.render_screen_space(&mut context.renderer.borrow_mut());
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
Ok(ActionFlag::Continue)
}
@ -49,7 +48,7 @@ impl Action<Scenes, ScreenError, GameContext> for FsmErrorScreen {
}
impl ScreenSpaceRender for FsmErrorScreen {
fn render_screen_space(&self, raylib: &mut HackedRaylibHandle) {
fn render_screen_space(&self, raylib: &mut HackedRaylibHandle, config: &GameConfig) {
raylib.clear_background(Color::RED);
// Render a warning message

View File

@ -1,4 +1,4 @@
use crate::utilities::render_layer::ScreenSpaceRender;
use crate::{GameConfig, utilities::render_layer::ScreenSpaceRender};
use raylib::prelude::*;
use super::InGameScreen;
@ -6,6 +6,7 @@ impl ScreenSpaceRender for InGameScreen {
fn render_screen_space(
&self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig
) {
// Calculate the logo position
let screen_size = raylib.get_screen_size();

View File

@ -58,10 +58,10 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
let mut renderer = context.renderer.borrow_mut();
// Update the inputs and checking logic
self.update(&mut renderer, delta);
self.update(&mut renderer, delta, &context.config);
// Wipe the background
renderer.clear_background(Color::BLACK);
renderer.clear_background(context.config.colors.background);
// Render the world
{
@ -69,11 +69,11 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
let mut raylib_camera_space = renderer.begin_mode2D(self.camera);
// Render in world space
self.render_world_space(&mut raylib_camera_space);
self.render_world_space(&mut raylib_camera_space, &context.config);
}
// Render the HUD
self.render_screen_space(&mut renderer);
self.render_screen_space(&mut renderer, &context.config);
Ok(ActionFlag::Continue)
}

View File

@ -1,12 +1,13 @@
use std::ops::Div;
use super::InGameScreen;
use crate::utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::FrameUpdate};
use crate::{GameConfig, utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::FrameUpdate}};
use chrono::Duration;
use raylib::prelude::*;
impl FrameUpdate for InGameScreen {
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &Duration) {
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &Duration,
config: &GameConfig) {
// Set the camera's offset based on screen size
self.camera.offset = raylib.get_screen_size().div(Vector2::new(2.0, 1.25));
self.camera.target = Vector2::new(

View File

@ -1,14 +1,12 @@
use std::ops::Mul;
use super::InGameScreen;
use crate::{
character::render::render_character_in_camera_space,
utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::WorldSpaceRender},
};
use crate::{GameConfig, character::render::render_character_in_camera_space, utilities::{non_ref_raylib::HackedRaylibHandle, render_layer::WorldSpaceRender}};
use raylib::prelude::*;
impl WorldSpaceRender for InGameScreen {
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>) {
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>,
config: &GameConfig) {
// Render the player
render_character_in_camera_space(raylib, &self.player);

View File

@ -5,15 +5,12 @@ use chrono::{DateTime, Utc};
use dirty_fsm::{Action, ActionFlag};
use raylib::prelude::*;
use crate::{
context::GameContext,
utilities::{
use crate::{GameConfig, context::GameContext, utilities::{
datastore::{load_texture_from_internal_data, ResourceLoadError},
math::interpolate_exp,
non_ref_raylib::HackedRaylibHandle,
render_layer::ScreenSpaceRender,
},
};
}};
use super::{Scenes, ScreenError};
use tracing::{debug, info, trace};
@ -67,7 +64,7 @@ impl Action<Scenes, ScreenError, GameContext> for LoadingScreen {
context: &GameContext,
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
trace!("execute() called on LoadingScreen");
self.render_screen_space(&mut context.renderer.borrow_mut());
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
// Check for a quick skip button in debug builds
cfg_if! {
@ -107,6 +104,7 @@ impl ScreenSpaceRender for LoadingScreen {
fn render_screen_space(
&self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig
) {
// Calculate the loading screen fade in/out value
// This makes the loading screen fade in/out over the duration of the loading screen

View File

@ -5,16 +5,13 @@ use dirty_fsm::{Action, ActionFlag};
use pkg_version::pkg_version_major;
use raylib::prelude::*;
use crate::{
context::GameContext,
utilities::{
use crate::{GameConfig, context::GameContext, utilities::{
datastore::{load_texture_from_internal_data, ResourceLoadError},
game_version::get_version_string,
math::interpolate_exp,
non_ref_raylib::HackedRaylibHandle,
render_layer::ScreenSpaceRender,
},
};
}};
use super::{Scenes, ScreenError};
use tracing::{debug, info, trace};
@ -47,7 +44,7 @@ impl Action<Scenes, ScreenError, GameContext> for MainMenuScreen {
context: &GameContext,
) -> Result<dirty_fsm::ActionFlag<Scenes>, ScreenError> {
trace!("execute() called on MainMenuScreen");
self.render_screen_space(&mut context.renderer.borrow_mut());
self.render_screen_space(&mut context.renderer.borrow_mut(), &context.config);
// TODO: TEMP
if context.renderer.borrow_mut().is_key_pressed(KeyboardKey::KEY_SPACE) {
@ -67,6 +64,7 @@ impl ScreenSpaceRender for MainMenuScreen {
fn render_screen_space(
&self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig
) {
// Render the background
raylib.clear_background(Color::BLACK);

View File

@ -1,6 +1,7 @@
//! Contains the general configuration data for the game
//! This data is immutable, and should only be edited by hand
use raylib::color::Color;
use rust_embed::EmbeddedFile;
/// Defines one of the game's authors
@ -11,12 +12,22 @@ pub struct Author {
pub roles: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColorTheme {
pub red: Color,
pub blue: Color,
pub green: Color,
pub yellow: Color,
pub pink: Color,
pub background: Color,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GameConfig {
pub name: String,
// pub authors: Vec<Author>,
pub base_window_size: (i32, i32),
pub sentry_dsn: String,
pub colors: ColorTheme,
}
impl GameConfig {

View File

@ -1,8 +1,9 @@
pub mod discord;
pub mod datastore;
pub mod discord;
pub mod game_config;
pub mod game_version;
pub mod math;
pub mod shaders;
pub mod non_ref_raylib;
pub mod render_layer;
pub mod game_version;
pub mod shaders;
pub mod map_loader;

View File

@ -1,15 +1,15 @@
use raylib::{prelude::RaylibMode2D, RaylibHandle};
use crate::utilities::non_ref_raylib::HackedRaylibHandle;
use crate::{GameConfig, context::GameContext, utilities::non_ref_raylib::HackedRaylibHandle};
pub trait FrameUpdate {
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &chrono::Duration);
fn update(&mut self, raylib: &HackedRaylibHandle, delta_seconds: &chrono::Duration, config: &GameConfig);
}
pub trait ScreenSpaceRender {
fn render_screen_space(&self, raylib: &mut HackedRaylibHandle);
fn render_screen_space(&self, raylib: &mut HackedRaylibHandle, config: &GameConfig);
}
pub trait WorldSpaceRender {
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>);
fn render_world_space(&self, raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>, config: &GameConfig);
}