Load textures
This commit is contained in:
parent
3ed57a17e7
commit
c024ee78dd
@ -2,30 +2,52 @@ use nalgebra as na;
|
|||||||
|
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
|
use crate::asset_manager::load_texture_from_internal_data;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub position: na::Vector2<f32>,
|
pub position: na::Vector2<f32>,
|
||||||
pub velocity: na::Vector2<f32>,
|
pub velocity: na::Vector2<f32>,
|
||||||
pub size: f32,
|
pub size: f32,
|
||||||
pub active_texture: i32,
|
pub active_texture: i32,
|
||||||
pub textures: [String; 3],
|
pub textures: Vec<Texture2D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
|
|
||||||
/// Construct a new player.
|
/// Construct a new player.
|
||||||
pub fn new(position: na::Vector2<f32>) -> Self {
|
pub fn new(
|
||||||
|
raylib_handle: &mut raylib::RaylibHandle,
|
||||||
|
thread: &raylib::RaylibThread,
|
||||||
|
position: na::Vector2<f32>,
|
||||||
|
) -> Self {
|
||||||
|
// Load all the textures
|
||||||
|
let textures = vec![
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeLarge.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeMedium.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
load_texture_from_internal_data(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
"assets/chr/chr_cubee/chr_cubeeSmall.png",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
];
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
position,
|
position,
|
||||||
velocity: na::Vector2::zeros(),
|
velocity: na::Vector2::zeros(),
|
||||||
size: 1.0,
|
size: 1.0,
|
||||||
active_texture: 0,
|
active_texture: 0,
|
||||||
textures: [
|
textures,
|
||||||
"assets/chr/chr_cubee/chr_cubeeLarge.png".to_string(),
|
|
||||||
"assets/chr/chr_cubee/chr_cubeeMedium.png".to_string(),
|
|
||||||
"assets/chr/chr_cubee/chr_cubeeSmall.png".to_string()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,19 @@ impl PlayableScene {
|
|||||||
let game_soundtrack =
|
let game_soundtrack =
|
||||||
load_music_from_internal_data(thread, "assets/audio/gameSoundtrack.mp3").unwrap();
|
load_music_from_internal_data(thread, "assets/audio/gameSoundtrack.mp3").unwrap();
|
||||||
|
|
||||||
Self {
|
// Load the player
|
||||||
has_updated_discord_rpc: false,
|
let player = Player::new(
|
||||||
player: Player::new(na::Vector2::new(
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
na::Vector2::new(
|
||||||
10.0 * constants.tile_size as f32,
|
10.0 * constants.tile_size as f32,
|
||||||
-10.0 * constants.tile_size as f32,
|
-10.0 * constants.tile_size as f32,
|
||||||
)),
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
has_updated_discord_rpc: false,
|
||||||
|
player,
|
||||||
world_map: map_renderer,
|
world_map: map_renderer,
|
||||||
camera: raylib::camera::Camera2D {
|
camera: raylib::camera::Camera2D {
|
||||||
target: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
target: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
||||||
@ -197,7 +204,7 @@ impl PlayableScene {
|
|||||||
|
|
||||||
player.position += velocity_modifier;
|
player.position += velocity_modifier;
|
||||||
|
|
||||||
player.size -= 0.001;
|
player.size -= 0.001;
|
||||||
|
|
||||||
self.update_camera(raylib);
|
self.update_camera(raylib);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user