diff --git a/game/dist/assets/env/env_beachTile/env_beachTile.png b/game/dist/assets/env/env_beachTile/env_beachTile.png
index fafdd41a..30d77e1b 100644
Binary files a/game/dist/assets/env/env_beachTile/env_beachTile.png and b/game/dist/assets/env/env_beachTile/env_beachTile.png differ
diff --git a/game/dist/assets/env/env_beachTile/env_beachTileWet.png b/game/dist/assets/env/env_beachTile/env_beachTileWet.png
new file mode 100644
index 00000000..ce190b53
Binary files /dev/null and b/game/dist/assets/env/env_beachTile/env_beachTileWet.png differ
diff --git a/game/dist/assets/env/env_boardwalkTile/env_boardwalkTile.png b/game/dist/assets/env/env_boardwalkTile/env_boardwalkTile.png
new file mode 100644
index 00000000..78020589
Binary files /dev/null and b/game/dist/assets/env/env_boardwalkTile/env_boardwalkTile.png differ
diff --git a/game/dist/assets/env/env_grassTile/env_grassTile.png b/game/dist/assets/env/env_grassTile/env_grassTile.png
new file mode 100644
index 00000000..41cf27a1
Binary files /dev/null and b/game/dist/assets/env/env_grassTile/env_grassTile.png differ
diff --git a/game/dist/assets/env/env_pavementTile/env_pavementTile.png b/game/dist/assets/env/env_pavementTile/env_pavementTile.png
new file mode 100644
index 00000000..70c509b2
Binary files /dev/null and b/game/dist/assets/env/env_pavementTile/env_pavementTile.png differ
diff --git a/game/dist/assets/env/env_pavementTile/env_pavementTileLine.png b/game/dist/assets/env/env_pavementTile/env_pavementTileLine.png
new file mode 100644
index 00000000..fa014c5c
Binary files /dev/null and b/game/dist/assets/env/env_pavementTile/env_pavementTileLine.png differ
diff --git a/game/dist/assets/env/env_roadTile/env_roadTile.png b/game/dist/assets/env/env_roadTile/env_roadTile.png
new file mode 100644
index 00000000..598e4c56
Binary files /dev/null and b/game/dist/assets/env/env_roadTile/env_roadTile.png differ
diff --git a/game/dist/assets/env/env_sidewalkTile/env_sidewalkTile.png b/game/dist/assets/env/env_sidewalkTile/env_sidewalkTile.png
new file mode 100644
index 00000000..07a592b7
Binary files /dev/null and b/game/dist/assets/env/env_sidewalkTile/env_sidewalkTile.png differ
diff --git a/game/dist/map_gameMap.tmx b/game/dist/map_gameMap.tmx
index f3384c58..a133aa5d 100644
--- a/game/dist/map_gameMap.tmx
+++ b/game/dist/map_gameMap.tmx
@@ -1,42 +1,194 @@
-
-
+
+
diff --git a/game/dist/project-constants.json b/game/dist/project-constants.json
index 3064e0eb..46f8c02e 100644
--- a/game/dist/project-constants.json
+++ b/game/dist/project-constants.json
@@ -5,6 +5,7 @@
720
],
"target_fps": 60,
+ "tile_size": 128,
"discord": {
"app_id": 954413081918857276,
"artwork": {
@@ -15,5 +16,11 @@
"details.sm_failure": "Game went FUBAR",
"details.main_menu": "In the main menu"
}
+ },
+ "player": {
+ "max_velocity": 3,
+ "acceleration": 2,
+ "deceleration": 1,
+ "start_size": 0.8
}
-}
\ No newline at end of file
+}
diff --git a/game/game_logic/src/model/player.rs b/game/game_logic/src/model/player.rs
index 2bb87f3e..69a7fe9f 100644
--- a/game/game_logic/src/model/player.rs
+++ b/game/game_logic/src/model/player.rs
@@ -5,6 +5,7 @@ use nalgebra as na;
pub struct Player {
pub position: na::Vector2,
pub velocity: na::Vector2,
+ pub size: f32,
}
impl Player {
@@ -14,7 +15,8 @@ impl Player {
Self {
position,
velocity: na::Vector2::zeros(),
+ size: 1.0,
}
}
-}
\ No newline at end of file
+}
diff --git a/game/game_logic/src/project_constants.rs b/game/game_logic/src/project_constants.rs
index 4350a297..6df497d3 100644
--- a/game/game_logic/src/project_constants.rs
+++ b/game/game_logic/src/project_constants.rs
@@ -28,6 +28,23 @@ pub struct DiscordConstants {
pub strings: HashMap,
}
+/// Constants relating to the Player
+#[derive(Debug, Deserialize)]
+pub struct PlayerConstants {
+
+ /// Maximum velocity, tiles per second
+ pub max_velocity: u32,
+
+ /// Acceleration, tiles per second per second
+ pub acceleration: u32,
+
+ /// Deceleration, tiles per second per second
+ pub deceleration: u32,
+
+ /// Starting size of player in tiles
+ pub start_size: f32,
+}
+
/// This structure is filled with the contents of `dist/project-constants.json` at runtime
#[derive(Debug, Deserialize)]
pub struct ProjectConstants {
@@ -40,6 +57,12 @@ pub struct ProjectConstants {
/// The Discord constants
pub discord: DiscordConstants,
+ /// The Player constants
+ pub player: PlayerConstants,
+
/// The target framerate of the game
pub target_fps: u32,
+
+ /// The size of the game tiles
+ pub tile_size: u32,
}
diff --git a/game/game_logic/src/scenes/main_menu.rs b/game/game_logic/src/scenes/main_menu.rs
index 2625a2a7..caf82caa 100644
--- a/game/game_logic/src/scenes/main_menu.rs
+++ b/game/game_logic/src/scenes/main_menu.rs
@@ -90,7 +90,7 @@ impl MainMenu {
//Insides while make a lil shade for it to look cool
draw.draw_text("Start Game", 103, 191, 34, Color::GRAY);
draw.draw_text("Start Game", 100, 190, 34, Color::BLACK);
- if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
return MenuStateSignal::StartGame;
}
}
@@ -98,7 +98,7 @@ impl MainMenu {
if mouse_x >= 100 && mouse_y >= 250 && mouse_x <= 222 && mouse_y <= 275 {
draw.draw_text("Options", 103, 251, 34, Color::GRAY);
draw.draw_text("Options", 100, 250, 34, Color::BLACK);
- if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
return MenuStateSignal::DoOptions;
}
}
@@ -106,14 +106,14 @@ impl MainMenu {
if mouse_x >= 100 && mouse_y >= 410 && mouse_x <= 222 && mouse_y <= 437 {
draw.draw_text("Credits", 103, 411, 34, Color::GRAY);
draw.draw_text("Credits", 100, 410, 34, Color::BLACK);
- if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
return MenuStateSignal::DoCredits;
}
}
if mouse_x >= 100 && mouse_y >= 470 && mouse_x <= 316 && mouse_y <= 496 {
draw.draw_text("Leaderboard", 103, 471, 34, Color::GRAY);
draw.draw_text("Leaderboard", 100, 470, 34, Color::BLACK);
- if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
return MenuStateSignal::DoLeaderboard;
}
}
@@ -121,7 +121,7 @@ impl MainMenu {
if mouse_x >= 100 && mouse_y >= 300 && mouse_x <= 215 && mouse_y <= 330 {
draw.draw_text("Volume", 103, 301, 34, Color::GRAY);
draw.draw_text("Volume", 100, 300, 34, Color::BLACK);
- if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
//Function for Volume here
}
}
@@ -130,6 +130,9 @@ impl MainMenu {
if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 162 && mouse_y <= 575 {
draw.draw_text("Exit", 103, 551, 34, Color::GRAY);
draw.draw_text("Exit", 100, 550, 34, Color::BLACK);
+ if draw.is_mouse_button_pressed(MouseButton::MOUSE_LEFT_BUTTON) {
+ return MenuStateSignal::QuitGame;
+ }
}
@@ -161,16 +164,22 @@ impl MainMenu {
//Top Label
draw.draw_text("Options", 25, 30, 55, Color::BLACK);
- //Return Button
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
- if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 {
- draw.draw_text("Return", 103, 551, 34, Color::GRAY);
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
+ //Window size storing variables
+ let window_height = draw.get_screen_height();
+ let window_width = draw.get_screen_width();
+
+ //Return button variables
+ let button_pos_x = 100; //116 Wide
+ let button_pos_y = window_height - (window_height/5); //26 height
+
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
+ if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 {
+ draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY);
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
return MenuStateSignal::DoMainMenu; //Goes back to main menu
}
}
-
return MenuStateSignal::DoOptions;
}
@@ -192,28 +201,31 @@ impl MainMenu {
draw.draw_text(&mouse_y.to_string(), 70, 5, 20, Color::BLACK);
//Screen Size
- // let window_height = draw.get_screen_height();
+ let window_height = draw.get_screen_height();
let window_width = draw.get_screen_width();
draw.draw_text("Credits", (window_width/2) - 100, 30, 55, Color::BLACK);
- draw.draw_text("Carter Tomlenovich", (window_width/2) - 170, 280, 40, Color::DARKBLUE);
- draw.draw_text("Emilia Firas", (window_width/2) - 170, 120, 40, Color::DARKBLUE);
- draw.draw_text("Emmet Logue", (window_width/2) - 170, 320, 40, Color::DARKBLUE);
- draw.draw_text("Evan Pratten", (window_width/2) - 170, 160, 40, Color::DARKBLUE);
- draw.draw_text("James Nickoli", (window_width/2) - 170, 240, 40, Color::DARKBLUE);
- draw.draw_text("Marcelo Geldres", (window_width/2) - 170, 440, 40, Color::DARKBLUE);
- draw.draw_text("Percy", (window_width/2) - 170, 400, 40, Color::DARKBLUE);
- draw.draw_text("Silas Bartha", (window_width/2) - 170, 200, 40, Color::DARKBLUE);
- draw.draw_text("Taya Armstrong", (window_width/2) - 170, 360, 40, Color::DARKBLUE);
+ draw.draw_text("Carter Tomlenovich", (window_width/2) - 170, 120, 40, Color::DARKBLUE);
+ draw.draw_text("Emilia Firas", (window_width/2) - 170, 160, 40, Color::DARKBLUE);
+ draw.draw_text("Emmet Logue", (window_width/2) - 170, 200, 40, Color::DARKBLUE);
+ draw.draw_text("Evan Pratten", (window_width/2) - 170, 240, 40, Color::DARKBLUE);
+ draw.draw_text("James Nickoli", (window_width/2) - 170, 280, 40, Color::DARKBLUE);
+ draw.draw_text("Marcelo Geldres", (window_width/2) - 170, 320, 40, Color::DARKBLUE);
+ draw.draw_text("Percy", (window_width/2) - 170, 360, 40, Color::DARKBLUE);
+ draw.draw_text("Silas Bartha", (window_width/2) - 170, 400, 40, Color::DARKBLUE);
+ draw.draw_text("Taya Armstrong", (window_width/2) - 170, 440, 40, Color::DARKBLUE);
- //Return Button
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
- if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 {
- draw.draw_text("Return", 103, 551, 34, Color::GRAY);
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
+ //Return button variables
+ let button_pos_x = 100; //116 Wide
+ let button_pos_y = window_height - (window_height/5); //26 height
+
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
+ if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 {
+ draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY);
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
- return MenuStateSignal::DoMainMenu;
+ return MenuStateSignal::DoMainMenu; //Goes back to main menu
}
}
@@ -234,6 +246,10 @@ impl MainMenu {
let mouse_x = draw.get_mouse_x();
let mouse_y = draw.get_mouse_y();
+ //Window size storing variables
+ let window_height = draw.get_screen_height();
+ let window_width = draw.get_screen_width();
+
//Show mouse position
draw.draw_text(&mouse_x.to_string(), 20, 5, 20, Color::BLACK);
draw.draw_text(&mouse_y.to_string(), 70, 5, 20, Color::BLACK);
@@ -241,13 +257,16 @@ impl MainMenu {
let window_width = draw.get_screen_width();
draw.draw_text("Leaderboard", (window_width/2) - 176, 30, 55, Color::BLACK);
- //Return Button
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
- if mouse_x >= 100 && mouse_y >= 550 && mouse_x <= 216 && mouse_y <= 576 {
- draw.draw_text("Return", 103, 551, 34, Color::GRAY);
- draw.draw_text("Return", 100, 550, 34, Color::BLACK);
+ //Return button variables
+ let button_pos_x = 100; //116 Wide
+ let button_pos_y = window_height - (window_height/5); //26 height
+
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
+ if mouse_x >= 100 && mouse_y >= button_pos_y && mouse_x <= 216 && mouse_y <= (window_height - (window_height/5)) + 26 {
+ draw.draw_text("Return", button_pos_x + 3, button_pos_y + 1, 34, Color::GRAY);
+ draw.draw_text("Return", button_pos_x, button_pos_y, 34, Color::BLACK);
if draw.is_mouse_button_down(MouseButton::MOUSE_LEFT_BUTTON) {
- return MenuStateSignal::DoMainMenu;
+ return MenuStateSignal::DoMainMenu; //Goes back to main menu
}
}
diff --git a/game/game_logic/src/scenes/mod.rs b/game/game_logic/src/scenes/mod.rs
index e0b4a9d8..9c02ccbb 100644
--- a/game/game_logic/src/scenes/mod.rs
+++ b/game/game_logic/src/scenes/mod.rs
@@ -65,13 +65,11 @@ impl SceneRenderDelegate {
// Render the main menu if in it, otherwise, render the game
match self.menu_control_signal {
MenuStateSignal::StartGame => {
- // self.scene_playable
- // .render_frame(raylib, rl_thread, &discord, global_resources, constants)
- // .await;
-
- // TODO: remove this test scene
- self.scene_test_fox
- .render_frame(raylib, rl_thread, &discord, global_resources)
+ self.scene_playable
+ .render_frame(raylib, rl_thread, &discord, global_resources, constants)
+ .await;
+ self.scene_playable
+ .update_physics(raylib, constants)
.await;
}
MenuStateSignal::QuitGame => unimplemented!(),
diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs
index db34e0bd..32aca9f3 100644
--- a/game/game_logic/src/scenes/player_interaction.rs
+++ b/game/game_logic/src/scenes/player_interaction.rs
@@ -2,39 +2,60 @@
use nalgebra as na;
use raylib::prelude::*;
+use std::time::SystemTime;
use crate::{
discord::{DiscordChannel, DiscordRpcSignal},
global_resource_package::GlobalResources,
model::player::Player,
project_constants::ProjectConstants,
- rendering::utilities::anim_texture::AnimatedTexture,
+ rendering::utilities::{anim_texture::AnimatedTexture, map_render::MapRenderer},
};
#[derive(Debug)]
pub struct PlayableScene {
has_updated_discord_rpc: bool,
player: Player,
+ world_map: MapRenderer,
+ camera: raylib::camera::Camera2D,
+ last_update: SystemTime,
}
impl PlayableScene {
/// Construct a new `PlayableScene`
pub fn new(
- raylib_handle: &mut RaylibHandle,
- thread: &RaylibThread,
+ raylib_handle: &mut raylib::RaylibHandle,
+ thread: & raylib::RaylibThread,
constants: &ProjectConstants,
) -> Self {
+
+ let map_renderer = MapRenderer::new("map_gameMap.tmx", raylib_handle, thread).unwrap();
+
Self {
has_updated_discord_rpc: false,
player: Player::new(na::Vector2::new(10.0, 10.0)),
+ world_map: map_renderer,
+ camera: raylib::camera::Camera2D {
+ target: raylib::math::Vector2 {
+ x: 0.0,
+ y: 0.0,
+ },
+ offset: raylib::math::Vector2 {
+ x: (constants.base_window_size.0 as f32 / 2.0),
+ y: (constants.base_window_size.1 as f32 / 2.0)
+ },
+ rotation: 0.0,
+ zoom: 1.0
+ },
+ last_update: SystemTime::UNIX_EPOCH
}
}
/// Handler for each frame
pub async fn render_frame(
&mut self,
- raylib: &mut RaylibHandle,
- rl_thread: &RaylibThread,
+ raylib: &mut raylib::RaylibHandle,
+ rl_thread: &raylib::RaylibThread,
discord: &DiscordChannel,
global_resources: &GlobalResources,
constants: &ProjectConstants,
@@ -60,8 +81,107 @@ impl PlayableScene {
// Clear the screen
draw.clear_background(Color::WHITE);
+
+ self.draw_world(&mut draw, constants);
- // TODO: Render stuff
- // self.player.
+ self.draw_ui(&mut draw, constants);
+ }
+
+ pub fn draw_world(
+ &mut self,
+ draw: &mut RaylibDrawHandle,
+ constants: &ProjectConstants,
+ ) {
+ // Begin camera mode
+ let mut ctx2d = draw.begin_mode2D(self.camera);
+
+ // Render the map
+ self.world_map.render_map(&mut ctx2d, &self.camera, true);
+
+ let player_size = (constants.tile_size as f32 * constants.player.start_size * self.player.size) as i32;
+
+ ctx2d.draw_rectangle(
+ self.player.position[0] as i32 - player_size / 2,
+ self.player.position[1] as i32 * -1 - player_size / 2,
+ player_size,
+ player_size,
+ Color::LIGHTBLUE
+ );
+ }
+
+ pub fn draw_ui(
+ &mut self,
+ draw: &mut RaylibDrawHandle,
+ constants: &ProjectConstants,
+ ) {
+ draw.draw_rectangle(
+ draw.get_screen_width() / 2 - 225, 0,
+ 450, 40,
+ Color::WHITE
+ );
+ draw.draw_text(
+ "Unregistered HyperCam 2",
+ draw.get_screen_width() / 2 - 215, 0,
+ 32, Color::BLACK
+ );
+ }
+
+ // Physics
+ pub async fn update_physics(
+ &mut self,
+ raylib: & raylib::RaylibHandle,
+ constants: &ProjectConstants,
+ ) {
+
+ // Get time since last physics update
+ let time = SystemTime::now();
+ let elapsed = time.duration_since(self.last_update).expect("Time Appears to Have Moved Backwards!");
+ self.last_update = time;
+ let delta_time = elapsed.as_millis() as f32 / 1000.0; // Physics will be scaled by this value
+
+ let player = &mut self.player;
+
+ // Get input direction components
+ let h_axis = raylib.is_key_down(KeyboardKey::KEY_D) as i8 - raylib.is_key_down(KeyboardKey::KEY_A) as i8;
+ let v_axis = raylib.is_key_down(KeyboardKey::KEY_W) as i8 - raylib.is_key_down(KeyboardKey::KEY_S) as i8;
+ if h_axis != 0 || v_axis != 0 {
+ // Normalize input and accelerate in desired direction
+ let direction = na::Vector2::new(h_axis as f32, v_axis as f32).normalize();
+ player.velocity += &direction.xy()
+ * constants.player.acceleration as f32
+ * constants.tile_size as f32
+ * delta_time;
+ }
+
+ if player.velocity.magnitude() != 0.0 {
+ player.velocity -= player.velocity.normalize()
+ * constants.player.deceleration as f32
+ * constants.tile_size as f32
+ * delta_time;
+ if player.velocity.magnitude() < 1.0 {
+ player.velocity.set_magnitude(0.0);
+ }
+ }
+
+ if ((constants.player.max_velocity * constants.tile_size) as f32)
+ < player.velocity.magnitude() {
+ player.velocity.set_magnitude((constants.player.max_velocity * constants.tile_size) as f32);
+ }
+
+ player.position += &player.velocity * delta_time;
+
+ self.update_camera(raylib);
+ }
+
+ pub fn update_camera(
+ &mut self,
+ raylib: & raylib::RaylibHandle,
+ ) {
+ self.camera.target = self.player.position.into();
+ self.camera.target.y *= -1.0;
+ self.camera.offset.x = raylib.get_screen_width() as f32 / 2.0;
+ self.camera.offset.y = raylib.get_screen_height() as f32 / 2.0;
}
}
+
+