some pre-jam reorg
This commit is contained in:
parent
0861a84777
commit
dfcd5c5e99
@ -5,8 +5,6 @@ authors = ["Evan Pratten <ewpratten@gmail.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = ""
|
description = ""
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
raylib = { version = "3.5", git = "https://github.com/ewpratten/raylib-rs", branch = "cross_compile_fixes" }
|
raylib = { version = "3.5", git = "https://github.com/ewpratten/raylib-rs", branch = "master" }
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
pub mod wrapper;
|
|
@ -1 +0,0 @@
|
|||||||
pub mod wrapper;
|
|
@ -1,2 +1 @@
|
|||||||
pub mod audio;
|
pub mod wrappers;
|
||||||
pub mod animation;
|
|
@ -5,6 +5,7 @@ use raylib::{
|
|||||||
texture::Texture2D,
|
texture::Texture2D,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A wrapper around an animation spritesheet
|
||||||
pub struct FrameAnimationWrapper {
|
pub struct FrameAnimationWrapper {
|
||||||
sprite_sheet: Texture2D,
|
sprite_sheet: Texture2D,
|
||||||
size: Vector2,
|
size: Vector2,
|
||||||
@ -14,6 +15,8 @@ pub struct FrameAnimationWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FrameAnimationWrapper {
|
impl FrameAnimationWrapper {
|
||||||
|
|
||||||
|
/// Create a new animation from a texture containing all frames
|
||||||
pub fn new(sprite_sheet: Texture2D, frame_size: Vector2, frame_count: u32, fps: u8) -> Self {
|
pub fn new(sprite_sheet: Texture2D, frame_size: Vector2, frame_count: u32, fps: u8) -> Self {
|
||||||
Self {
|
Self {
|
||||||
sprite_sheet,
|
sprite_sheet,
|
||||||
@ -24,14 +27,17 @@ impl FrameAnimationWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start the animation
|
||||||
pub fn start(&mut self, handle: &RaylibDrawHandle) {
|
pub fn start(&mut self, handle: &RaylibDrawHandle) {
|
||||||
self.start_time_seconds = handle.get_time();
|
self.start_time_seconds = handle.get_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stop (and reset) the animation
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&mut self) {
|
||||||
self.start_time_seconds = 0.0;
|
self.start_time_seconds = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the index of the currently displayed frame
|
||||||
pub fn get_current_frame_id(&self, handle: &RaylibDrawHandle) -> u32 {
|
pub fn get_current_frame_id(&self, handle: &RaylibDrawHandle) -> u32 {
|
||||||
// Get the time since start
|
// Get the time since start
|
||||||
let time_since_start = handle.get_time() - self.start_time_seconds;
|
let time_since_start = handle.get_time() - self.start_time_seconds;
|
||||||
@ -41,11 +47,13 @@ impl FrameAnimationWrapper {
|
|||||||
as u32;
|
as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw the next frame to the screen at `position`
|
||||||
pub fn draw(&mut self, handle: &mut RaylibDrawHandle, position: Vector2) {
|
pub fn draw(&mut self, handle: &mut RaylibDrawHandle, position: Vector2) {
|
||||||
let frame_id = self.get_current_frame_id(handle);
|
let frame_id = self.get_current_frame_id(handle);
|
||||||
self.draw_frame(handle, position, frame_id);
|
self.draw_frame(handle, position, frame_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw a specified frame to the screen at `position`
|
||||||
pub fn draw_frame(
|
pub fn draw_frame(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &mut RaylibDrawHandle,
|
handle: &mut RaylibDrawHandle,
|
||||||
@ -67,7 +75,7 @@ impl FrameAnimationWrapper {
|
|||||||
width: self.size.x,
|
width: self.size.x,
|
||||||
height: self.size.y,
|
height: self.size.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
handle.draw_texture_rec(&mut self.sprite_sheet, frame_box, position, Color::WHITE);
|
handle.draw_texture_rec(&mut self.sprite_sheet, frame_box, position, Color::WHITE);
|
||||||
}
|
}
|
@ -1,30 +1,40 @@
|
|||||||
use raylib::{audio::{Music, RaylibAudio}, prelude::RaylibDrawHandle};
|
use raylib::{
|
||||||
|
audio::{Music, RaylibAudio},
|
||||||
|
prelude::RaylibDrawHandle,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A simple wrapper around a single audio clip.
|
||||||
pub struct AudioWrapper {
|
pub struct AudioWrapper {
|
||||||
music: Music,
|
music: Music,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioWrapper {
|
impl AudioWrapper {
|
||||||
|
/// Create a new AudioWrapper from a `Music` struct
|
||||||
pub fn new(music: Music) -> Self {
|
pub fn new(music: Music) -> Self {
|
||||||
Self { music }
|
Self { music }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Begin playing the audio
|
||||||
pub fn play(&mut self, audio_handle: &mut RaylibAudio) {
|
pub fn play(&mut self, audio_handle: &mut RaylibAudio) {
|
||||||
audio_handle.play_music_stream(&mut self.music);
|
audio_handle.play_music_stream(&mut self.music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stop playing the audio
|
||||||
pub fn stop(&mut self, audio_handle: &mut RaylibAudio) {
|
pub fn stop(&mut self, audio_handle: &mut RaylibAudio) {
|
||||||
audio_handle.stop_music_stream(&mut self.music);
|
audio_handle.stop_music_stream(&mut self.music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pause the audio
|
||||||
pub fn pause(&mut self, audio_handle: &mut RaylibAudio) {
|
pub fn pause(&mut self, audio_handle: &mut RaylibAudio) {
|
||||||
audio_handle.pause_music_stream(&mut self.music);
|
audio_handle.pause_music_stream(&mut self.music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call this every frame
|
||||||
pub fn update(&mut self, audio_handle: &mut RaylibAudio) {
|
pub fn update(&mut self, audio_handle: &mut RaylibAudio) {
|
||||||
audio_handle.update_music_stream(&mut self.music);
|
audio_handle.update_music_stream(&mut self.music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if this audio clip is playing
|
||||||
pub fn is_playing(&mut self, audio_handle: &mut RaylibAudio) -> bool {
|
pub fn is_playing(&mut self, audio_handle: &mut RaylibAudio) -> bool {
|
||||||
return audio_handle.is_music_playing(&mut self.music);
|
return audio_handle.is_music_playing(&mut self.music);
|
||||||
}
|
}
|
2
src/lib/wrappers/mod.rs
Normal file
2
src/lib/wrappers/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod audio;
|
||||||
|
pub mod animation;
|
@ -1,6 +1,6 @@
|
|||||||
mod lib;
|
mod lib;
|
||||||
|
|
||||||
use lib::{animation::wrapper::FrameAnimationWrapper, audio::wrapper::AudioWrapper};
|
use lib::wrappers::{animation::FrameAnimationWrapper, audio::AudioWrapper};
|
||||||
use raylib::prelude::*;
|
use raylib::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Reference in New Issue
Block a user