Load textures
This commit is contained in:
parent
c955f2370b
commit
22f50bbd03
@ -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()
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,18 @@ 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();
|
||||||
|
|
||||||
|
// Load the player
|
||||||
|
let player = Player::new(
|
||||||
|
raylib_handle,
|
||||||
|
thread,
|
||||||
|
player_start_position,
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
has_updated_discord_rpc: false,
|
has_updated_discord_rpc: false,
|
||||||
player_start_position,
|
player_start_position,
|
||||||
player: Player::new(player_start_position),
|
|
||||||
world_map: map_renderer,
|
world_map: map_renderer,
|
||||||
|
player,
|
||||||
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 },
|
||||||
offset: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
offset: raylib::math::Vector2 { x: 0.0, y: 0.0 },
|
||||||
@ -347,7 +354,7 @@ impl PlayableScene {
|
|||||||
player.velocity.y = 0.0;
|
player.velocity.y = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.size -= 0.001;
|
player.size -= 0.001;
|
||||||
|
|
||||||
self.update_camera(raylib);
|
self.update_camera(raylib);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user