forked from karx/catbox
Initial Sprite struct
This commit is contained in:
parent
2d8e75acd3
commit
adee07fbc7
|
@ -5,5 +5,6 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sdl2 = "0.35.2"
|
||||
[dependencies.sdl2]
|
||||
version = "0.35.2"
|
||||
features = ["image"]
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -1,9 +1,9 @@
|
|||
use std::cell::Cell;
|
||||
use std::{cell::Cell, path::Path};
|
||||
|
||||
use sdl2::{
|
||||
render::Canvas,
|
||||
video::{Window, WindowBuildError},
|
||||
IntegerOrSdlError,
|
||||
video::{Window, WindowBuildError, WindowSurfaceRef},
|
||||
IntegerOrSdlError, rect::Rect, surface::Surface, rwops::RWops, image::ImageRWops,
|
||||
};
|
||||
|
||||
pub use sdl2::event::Event;
|
||||
|
@ -45,6 +45,30 @@ impl From<IntegerOrSdlError> for CatboxError {
|
|||
|
||||
pub type Result<T> = std::result::Result<T, CatboxError>;
|
||||
|
||||
pub struct Sprite {
|
||||
rect: Rect,
|
||||
surf: Surface<'static>
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
pub fn new<P: AsRef<Path>>(path: P, x: i32, y: i32) -> Result<Self> {
|
||||
let ops = RWops::from_file(path, "r")?;
|
||||
let surf = ops.load()?;
|
||||
|
||||
let srect = surf.rect();
|
||||
let dest_rect: Rect = Rect::new(x, y, srect.width(), srect.height());
|
||||
|
||||
Ok(Self {
|
||||
rect: dest_rect,
|
||||
surf
|
||||
})
|
||||
}
|
||||
|
||||
pub fn draw(&self, canvas: Canvas<Window>) {
|
||||
let surface = canvas.window();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Game {
|
||||
pub title: String,
|
||||
pub width: u32,
|
||||
|
|
Loading…
Reference in a new issue