diff --git a/Cargo.toml b/Cargo.toml index 6db403d..2d9df5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/lib.rs b/src/lib.rs index 48b6bf2..1e552b4 100644 --- a/src/lib.rs +++ b/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 for CatboxError { pub type Result = std::result::Result; +pub struct Sprite { + rect: Rect, + surf: Surface<'static> +} + +impl Sprite { + pub fn new>(path: P, x: i32, y: i32) -> Result { + 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) { + let surface = canvas.window(); + } +} + pub struct Game { pub title: String, pub width: u32,