commit
b954e79287
122
src/items.rs
122
src/items.rs
@ -1,4 +1,9 @@
|
|||||||
use raylib::{math::Rectangle, prelude::RaylibDrawHandle, texture::Texture2D};
|
use raylib::{
|
||||||
|
color::Color,
|
||||||
|
math::{Rectangle, Vector2},
|
||||||
|
prelude::{RaylibDraw, RaylibDrawHandle},
|
||||||
|
texture::Texture2D,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::resources::GlobalResources;
|
use crate::resources::GlobalResources;
|
||||||
@ -8,7 +13,12 @@ pub trait ItemBase {
|
|||||||
fn get_level(&self) -> u8;
|
fn get_level(&self) -> u8;
|
||||||
fn get_name(&self) -> String;
|
fn get_name(&self) -> String;
|
||||||
fn get_description(&self) -> String;
|
fn get_description(&self) -> String;
|
||||||
fn get_texture(&self, draw_handle: &RaylibDrawHandle, resources: &GlobalResources, dest: Rectangle);
|
fn get_texture(
|
||||||
|
&self,
|
||||||
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
|
resources: &GlobalResources,
|
||||||
|
dest: Rectangle,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
@ -59,8 +69,31 @@ impl ItemBase for StunGun {
|
|||||||
return "Stun your enemies!\nJust don't point it at yourself.".to_string();
|
return "Stun your enemies!\nJust don't point it at yourself.".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_texture(&self, draw_handle: &RaylibDrawHandle, resources: &GlobalResources, dest: Rectangle) {
|
fn get_texture(
|
||||||
todo!()
|
&self,
|
||||||
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
|
resources: &GlobalResources,
|
||||||
|
dest: Rectangle,
|
||||||
|
) {
|
||||||
|
let texture = match self.get_level() {
|
||||||
|
1 => (&resources.stun_gun_one),
|
||||||
|
2 => (&resources.stun_gun_two),
|
||||||
|
3 | _ => (&resources.stun_gun_three),
|
||||||
|
};
|
||||||
|
|
||||||
|
draw_handle.draw_texture_pro(
|
||||||
|
texture,
|
||||||
|
Rectangle {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
width: texture.width as f32,
|
||||||
|
height: texture.height as f32,
|
||||||
|
},
|
||||||
|
dest,
|
||||||
|
Vector2 { x: 0.0, y: 0.0 },
|
||||||
|
0.0,
|
||||||
|
Color::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn get_level(&self) -> u8 {
|
fn get_level(&self) -> u8 {
|
||||||
self.level
|
self.level
|
||||||
@ -111,8 +144,31 @@ impl ItemBase for AirBag {
|
|||||||
return "Its.. a bag.\nFilled with air. Duh".to_string();
|
return "Its.. a bag.\nFilled with air. Duh".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_texture(&self, draw_handle: &RaylibDrawHandle, resources: &GlobalResources, dest: Rectangle) {
|
fn get_texture(
|
||||||
todo!()
|
&self,
|
||||||
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
|
resources: &GlobalResources,
|
||||||
|
dest: Rectangle,
|
||||||
|
) {
|
||||||
|
let texture = match self.get_level() {
|
||||||
|
1 => (&resources.air_one),
|
||||||
|
2 => (&resources.air_two),
|
||||||
|
3 | _ => (&resources.air_three),
|
||||||
|
};
|
||||||
|
|
||||||
|
draw_handle.draw_texture_pro(
|
||||||
|
texture,
|
||||||
|
Rectangle {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
width: texture.width as f32,
|
||||||
|
height: texture.height as f32,
|
||||||
|
},
|
||||||
|
dest,
|
||||||
|
Vector2 { x: 0.0, y: 0.0 },
|
||||||
|
0.0,
|
||||||
|
Color::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn get_level(&self) -> u8 {
|
fn get_level(&self) -> u8 {
|
||||||
self.level
|
self.level
|
||||||
@ -163,8 +219,31 @@ impl ItemBase for Flashlight {
|
|||||||
return "See better for longer".to_string();
|
return "See better for longer".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_texture(&self, draw_handle: &RaylibDrawHandle, resources: &GlobalResources, dest: Rectangle) {
|
fn get_texture(
|
||||||
todo!()
|
&self,
|
||||||
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
|
resources: &GlobalResources,
|
||||||
|
dest: Rectangle,
|
||||||
|
) {
|
||||||
|
let texture = match self.get_level() {
|
||||||
|
1 => (&resources.flashlight_one),
|
||||||
|
2 => (&resources.flashlight_two),
|
||||||
|
3 | _ => (&resources.flashlight_three),
|
||||||
|
};
|
||||||
|
|
||||||
|
draw_handle.draw_texture_pro(
|
||||||
|
texture,
|
||||||
|
Rectangle {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
width: texture.width as f32,
|
||||||
|
height: texture.height as f32,
|
||||||
|
},
|
||||||
|
dest,
|
||||||
|
Vector2 { x: 0.0, y: 0.0 },
|
||||||
|
0.0,
|
||||||
|
Color::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn get_level(&self) -> u8 {
|
fn get_level(&self) -> u8 {
|
||||||
self.level
|
self.level
|
||||||
@ -215,8 +294,31 @@ impl ItemBase for Flippers {
|
|||||||
return "Swim faster, and look stupid\nat the same time!".to_string();
|
return "Swim faster, and look stupid\nat the same time!".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_texture(&self, draw_handle: &RaylibDrawHandle, resources: &GlobalResources, dest: Rectangle) {
|
fn get_texture(
|
||||||
todo!()
|
&self,
|
||||||
|
draw_handle: &mut RaylibDrawHandle,
|
||||||
|
resources: &GlobalResources,
|
||||||
|
dest: Rectangle,
|
||||||
|
) {
|
||||||
|
let texture = match self.get_level() {
|
||||||
|
1 => (&resources.flippers_one),
|
||||||
|
2 => (&resources.flippers_two),
|
||||||
|
3 | _ => (&resources.flippers_three),
|
||||||
|
};
|
||||||
|
|
||||||
|
draw_handle.draw_texture_pro(
|
||||||
|
texture,
|
||||||
|
Rectangle {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
width: texture.width as f32,
|
||||||
|
height: texture.height as f32,
|
||||||
|
},
|
||||||
|
dest,
|
||||||
|
Vector2 { x: 0.0, y: 0.0 },
|
||||||
|
0.0,
|
||||||
|
Color::WHITE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn get_level(&self) -> u8 {
|
fn get_level(&self) -> u8 {
|
||||||
self.level
|
self.level
|
||||||
|
@ -151,15 +151,18 @@ pub fn render_shop(
|
|||||||
draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE);
|
draw_handle.draw_rectangle_rec(box_bounds, Color::WHITE);
|
||||||
draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK);
|
draw_handle.draw_rectangle_lines_ex(box_bounds, 3, Color::BLACK);
|
||||||
|
|
||||||
// TODO: draw item sprite
|
|
||||||
draw_handle.draw_rectangle_v(
|
hovered_item.get_texture(
|
||||||
Vector2 {
|
draw_handle,
|
||||||
|
&game_core.resources,
|
||||||
|
Rectangle {
|
||||||
x: box_bounds.x + (box_bounds.width / 2.0) - 40.0,
|
x: box_bounds.x + (box_bounds.width / 2.0) - 40.0,
|
||||||
y: box_bounds.y + 10.0,
|
y: box_bounds.y + 10.0,
|
||||||
},
|
width: (80.0),
|
||||||
Vector2 { x: 80.0, y: 80.0 },
|
height: (80.0),
|
||||||
Color::BLACK,
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Render item description
|
// Render item description
|
||||||
draw_handle.draw_text(
|
draw_handle.draw_text(
|
||||||
|
@ -35,6 +35,25 @@ pub struct GlobalResources {
|
|||||||
// Shop & items
|
// Shop & items
|
||||||
pub shop_background: Texture2D,
|
pub shop_background: Texture2D,
|
||||||
|
|
||||||
|
pub flashlight_one: Texture2D,
|
||||||
|
pub flashlight_two: Texture2D,
|
||||||
|
pub flashlight_three: Texture2D,
|
||||||
|
|
||||||
|
pub stun_gun_one: Texture2D,
|
||||||
|
pub stun_gun_two: Texture2D,
|
||||||
|
pub stun_gun_three: Texture2D,
|
||||||
|
|
||||||
|
pub air_one: Texture2D,
|
||||||
|
pub air_two: Texture2D,
|
||||||
|
pub air_three: Texture2D,
|
||||||
|
|
||||||
|
pub flippers_one: Texture2D,
|
||||||
|
pub flippers_two: Texture2D,
|
||||||
|
pub flippers_three: Texture2D,
|
||||||
|
|
||||||
|
// Treasure
|
||||||
|
pub transponder: FrameAnimationWrapper,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlobalResources {
|
impl GlobalResources {
|
||||||
@ -152,6 +171,64 @@ impl GlobalResources {
|
|||||||
&thread,
|
&thread,
|
||||||
&Image::load_image("./assets/img/map/shopHighRes.png")?,
|
&Image::load_image("./assets/img/map/shopHighRes.png")?,
|
||||||
)?,
|
)?,
|
||||||
|
flashlight_one: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flashlight1.png")?,
|
||||||
|
)?),
|
||||||
|
flashlight_two: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flashlight2.png")?,
|
||||||
|
)?),
|
||||||
|
flashlight_three: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flashlight3.png")?,
|
||||||
|
)?),
|
||||||
|
stun_gun_one: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/stun1.png")?,
|
||||||
|
)?),
|
||||||
|
stun_gun_two: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/stun2.png")?,
|
||||||
|
)?),
|
||||||
|
stun_gun_three: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/stun3.png")?,
|
||||||
|
)?),
|
||||||
|
air_one: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/air1.png")?,
|
||||||
|
)?),
|
||||||
|
air_two: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/air2.png")?,
|
||||||
|
)?),
|
||||||
|
air_three: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/air3.png")?,
|
||||||
|
)?),
|
||||||
|
flippers_one: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flippers1.png")?,
|
||||||
|
)?),
|
||||||
|
flippers_two: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flippers2.png")?,
|
||||||
|
)?),
|
||||||
|
flippers_three: (raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/items/flippers3.png")?,
|
||||||
|
)?),
|
||||||
|
transponder: FrameAnimationWrapper::new(
|
||||||
|
raylib.load_texture_from_image(
|
||||||
|
&thread,
|
||||||
|
&Image::load_image("./assets/img/map/transponder.png")?,
|
||||||
|
)?,
|
||||||
|
Vector2 { x: 10.0, y: 20.0 },
|
||||||
|
6,
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user