From f53daafa09286a1e97ec5c2b2216b6b1290a34c7 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 2 Oct 2021 09:51:22 -0400 Subject: [PATCH] basic bg texturing --- game/src/scenes/ingame_scene/mod.rs | 6 ++++-- game/src/scenes/ingame_scene/world.rs | 9 +++++++-- game/src/scenes/mod.rs | 4 +++- game/src/utilities/world_paint_texture.rs | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index dc5ee72..8622e6a 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -1,7 +1,7 @@ use dirty_fsm::{Action, ActionFlag}; use raylib::prelude::*; -use crate::{character::{CharacterState, MainCharacter}, context::GameContext, utilities::render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender}}; +use crate::{character::{CharacterState, MainCharacter}, context::GameContext, utilities::{render_layer::{FrameUpdate, ScreenSpaceRender, WorldSpaceRender}, world_paint_texture::WorldPaintTexture}}; use super::{Scenes, ScreenError}; use tracing::{debug, trace}; @@ -14,11 +14,12 @@ mod world; pub struct InGameScreen { camera: Camera2D, player: MainCharacter, + world_background: WorldPaintTexture } impl InGameScreen { /// Construct a new `InGameScreen` - pub fn new(player_sprite_sheet: Texture2D) -> Self { + pub fn new(player_sprite_sheet: Texture2D, background_texture: Texture2D) -> Self { Self { camera: Camera2D { offset: Vector2::zero(), @@ -27,6 +28,7 @@ impl InGameScreen { zoom: 1.0, }, player: MainCharacter::new(Vector2::new(0.0, -80.0), player_sprite_sheet), + world_background: WorldPaintTexture::new(background_texture) } } } diff --git a/game/src/scenes/ingame_scene/world.rs b/game/src/scenes/ingame_scene/world.rs index 67e4ab5..cf5afdf 100644 --- a/game/src/scenes/ingame_scene/world.rs +++ b/game/src/scenes/ingame_scene/world.rs @@ -15,8 +15,9 @@ impl WorldSpaceRender for InGameScreen { config: &GameConfig, ) { puffin::profile_function!(); - // Render the player - render_character_in_camera_space(raylib, &self.player, &config); + + // Render the world background + self.world_background.render(raylib, Vector2::new(0.0, -1080.0), &self.camera); // Render the floor as a line let screen_world_zero = raylib.get_screen_to_world2D(Vector2::zero(), self.camera); @@ -30,5 +31,9 @@ impl WorldSpaceRender for InGameScreen { 5, config.colors.white, ); + + + // Render the player + render_character_in_camera_space(raylib, &self.player, &config); } } diff --git a/game/src/scenes/mod.rs b/game/src/scenes/mod.rs index d9ec17b..7951f15 100644 --- a/game/src/scenes/mod.rs +++ b/game/src/scenes/mod.rs @@ -46,6 +46,8 @@ pub fn build_screen_state_machine( // Load the various textures needed by the states let player_sprite_sheet = load_texture_from_internal_data(raylib_handle, thread, "character/player_run.png").unwrap(); + let world_background = + load_texture_from_internal_data(raylib_handle, thread, "default-texture.png").unwrap(); // Set up the state machine let mut machine = StateMachine::new(); @@ -55,6 +57,6 @@ pub fn build_screen_state_machine( LoadingScreen::new(raylib_handle, thread)?, )?; machine.add_action(Scenes::MainMenuScreen, MainMenuScreen::new())?; - machine.add_action(Scenes::InGameScene, InGameScreen::new(player_sprite_sheet))?; + machine.add_action(Scenes::InGameScene, InGameScreen::new(player_sprite_sheet, world_background))?; Ok(machine) } diff --git a/game/src/utilities/world_paint_texture.rs b/game/src/utilities/world_paint_texture.rs index 0ca83fc..407124b 100644 --- a/game/src/utilities/world_paint_texture.rs +++ b/game/src/utilities/world_paint_texture.rs @@ -11,6 +11,7 @@ use raylib::{ use super::non_ref_raylib::HackedRaylibHandle; +#[derive(Debug)] pub struct WorldPaintTexture { texture: Texture2D, } @@ -39,7 +40,7 @@ impl WorldPaintTexture { let left_tile_x = (left_edge_distance / self.texture.width as f32).floor() * self.texture.width as f32; let right_tile_x = - (right_edge_distance / self.texture.width as f32).ceil() * self.texture.width as f32; + left_tile_x + self.texture.width as f32; // Render the tiles raylib.draw_texture_v(