Compare commits

...
This repository has been archived on 2021-10-11. You can view files and clone it, but cannot push or open issues or pull requests.

3 Commits

6 changed files with 82 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.7.2" name="tilemap1" tilewidth="32" tileheight="32" tilecount="864" columns="36">
<image source="../../../../../../Downloads/abwsx3mzcgs21.png" width="1152" height="768"/>
</tileset>

View File

@ -1,14 +1,22 @@
use crate::{GameConfig, utilities::render_layer::ScreenSpaceRender}; use crate::GameConfig;
use crate::utilities::render_layer::ScreenSpaceRender;
use crate::utilities::datastore::*;
use raylib::prelude::*; use raylib::prelude::*;
use super::InGameScreen; use super::InGameScreen;
impl ScreenSpaceRender for InGameScreen { impl ScreenSpaceRender for InGameScreen {
fn render_screen_space( fn render_screen_space(
&self, &self,
raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle, raylib: &mut crate::utilities::non_ref_raylib::HackedRaylibHandle,
config: &GameConfig config: &GameConfig,
) { ) {
// Calculate the logo position
let screen_size = raylib.get_screen_size(); raylib.draw_texture(&self.levels[0].level_texture, 0, 0, Color::WHITE);
} }
} }

View File

@ -1,11 +1,7 @@
use dirty_fsm::{Action, ActionFlag}; use dirty_fsm::{Action, ActionFlag};
use raylib::prelude::*; use raylib::prelude::*;
use crate::{ use crate::{character::MainCharacter, context::GameContext, utilities::{datastore::*, render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender}}};
character::MainCharacter,
context::GameContext,
utilities::render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender},
};
use super::{Scenes, ScreenError}; use super::{Scenes, ScreenError};
use tracing::{debug, trace}; use tracing::{debug, trace};
@ -14,15 +10,17 @@ mod hud;
mod update; mod update;
mod world; mod world;
#[derive(Debug)] #[derive(Debug)]
pub struct InGameScreen { pub struct InGameScreen {
camera: Camera2D, camera: Camera2D,
player: MainCharacter, player: MainCharacter,
levels: Vec<Level>,
} }
impl InGameScreen { impl InGameScreen {
/// Construct a new `InGameScreen` /// Construct a new `InGameScreen`
pub fn new() -> Self { pub fn new(levels: Vec<Level>, ) -> Self {
Self { Self {
camera: Camera2D { camera: Camera2D {
offset: Vector2::zero(), offset: Vector2::zero(),
@ -31,6 +29,9 @@ impl InGameScreen {
zoom: 1.0, zoom: 1.0,
}, },
player: MainCharacter::new(Vector2::new(0.0, -45.0)), player: MainCharacter::new(Vector2::new(0.0, -45.0)),
levels,
} }
} }
} }

View File

@ -2,10 +2,7 @@ use self::{
fsm_error_screen::FsmErrorScreen, ingame_scene::InGameScreen, loading_screen::LoadingScreen, fsm_error_screen::FsmErrorScreen, ingame_scene::InGameScreen, loading_screen::LoadingScreen,
main_menu_screen::MainMenuScreen, main_menu_screen::MainMenuScreen,
}; };
use crate::{ use crate::{context::GameContext, utilities::{datastore::{ResourceLoadError, load_level_from_internal_data}, non_ref_raylib::HackedRaylibHandle}};
context::GameContext,
utilities::{datastore::ResourceLoadError, non_ref_raylib::HackedRaylibHandle},
};
use dirty_fsm::StateMachine; use dirty_fsm::StateMachine;
use raylib::RaylibThread; use raylib::RaylibThread;
@ -40,6 +37,9 @@ pub fn build_screen_state_machine(
StateMachine<Scenes, ScreenError, GameContext>, StateMachine<Scenes, ScreenError, GameContext>,
ScreenError, ScreenError,
> { > {
let levels = vec![load_level_from_internal_data( raylib_handle, &thread, "levels_tmx/test_map.tmx", "levels_tmx/tilemap1.tsx").expect("Could not load test level.")];
let mut machine = StateMachine::new(); let mut machine = StateMachine::new();
machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?; machine.add_action(Scenes::FsmErrorScreen, FsmErrorScreen::new())?;
machine.add_action( machine.add_action(
@ -47,6 +47,6 @@ pub fn build_screen_state_machine(
LoadingScreen::new(raylib_handle, thread)?, LoadingScreen::new(raylib_handle, thread)?,
)?; )?;
machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?; machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?;
machine.add_action(Scenes::InGameScene, InGameScreen::new())?; machine.add_action(Scenes::InGameScene, InGameScreen::new(levels))?;
Ok(machine) Ok(machine)
} }

View File

@ -1,9 +1,9 @@
use std::{io::Write, path::Path}; use std::{io::Write, path::Path};
use raylib::{texture::Texture2D, RaylibHandle, RaylibThread}; use raylib::{RaylibHandle, RaylibThread, math::Rectangle, texture::Texture2D};
use tempfile::{tempdir, NamedTempFile}; use tempfile::{tempdir, NamedTempFile};
use tracing::debug; use tracing::debug;
use tiled::*;
/// Contains all game assets. /// Contains all game assets.
/// ///
/// This uses macro magic to automatically embed the contents of `game/assets/` into the executable /// This uses macro magic to automatically embed the contents of `game/assets/` into the executable
@ -65,3 +65,44 @@ pub fn load_texture_from_internal_data(
Ok(texture) Ok(texture)
} }
// Loading specific to level files.
pub fn load_level_from_internal_data(raylib_handle: &mut RaylibHandle, thread: &RaylibThread ,path: &str, tilemap: &str) -> Result<Level, ResourceLoadError> {
let temp_dir = tempdir()?;
let tmp_path = temp_dir.path().join(Path::new(path).file_name().unwrap());
std::fs::write(&tmp_path,
&StaticGameData::get(tilemap)
.ok_or(ResourceLoadError::AssetNotFound(tilemap.to_string()))?
.data,
)?;
std::fs::write(&tmp_path,
&StaticGameData::get(path)
.ok_or(ResourceLoadError::AssetNotFound(path.to_string()))?
.data,
)?;
let map = parse_file(Path::new(tmp_path.to_str().unwrap())).expect("Map failed to load");
let level_texture = raylib_handle.load_texture(&thread, map.image_.image.as_ref().unwrap()
.source.as_str()).map_err(ResourceLoadError::Generic).expect("Count not convert to texture2d");
let level = Level {
level_texture
// colliders:
};
temp_dir.close();
Ok(level)
}
#[derive(Debug)]
pub struct Level {
pub level_texture: Texture2D,
// pub colliders: Layer,
}