setup for platform logic
This commit is contained in:
parent
54ab3f7ee2
commit
be9397089e
|
@ -187,6 +187,7 @@ pub struct Sprite {
|
|||
pub rect: Rect,
|
||||
surf: Surface<'static>,
|
||||
angle: f64,
|
||||
is_platform: bool,
|
||||
}
|
||||
|
||||
impl Sprite {
|
||||
|
@ -197,7 +198,7 @@ impl Sprite {
|
|||
/// # use cat_box::*;
|
||||
/// let s = Sprite::new("duck.png", 500, 400).unwrap();
|
||||
/// ```
|
||||
pub fn new<P: AsRef<Path>>(path: P, x: i32, y: i32) -> Result<Self> {
|
||||
pub fn new<P: AsRef<Path>>(path: P, x: i32, y: i32, plat: bool) -> Result<Self> {
|
||||
let ops = RWops::from_file(path, "r")?;
|
||||
let surf = ops.load()?;
|
||||
|
||||
|
@ -208,6 +209,7 @@ impl Sprite {
|
|||
rect: dest_rect,
|
||||
surf,
|
||||
angle: 0.0,
|
||||
is_platform: plat,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -219,7 +221,7 @@ impl Sprite {
|
|||
/// let bytes = include_bytes!("../duck.png");
|
||||
/// let s = Sprite::from_bytes(bytes, 500, 400).unwrap();
|
||||
/// ```
|
||||
pub fn from_bytes<B: AsRef<[u8]>>(bytes: B, x: i32, y: i32) -> Result<Self> {
|
||||
pub fn from_bytes<B: AsRef<[u8]>>(bytes: B, x: i32, y: i32, plat: bool) -> Result<Self> {
|
||||
let ops = RWops::from_bytes(bytes.as_ref())?;
|
||||
let surf = ops.load()?;
|
||||
|
||||
|
@ -230,6 +232,7 @@ impl Sprite {
|
|||
rect: dest_rect,
|
||||
surf,
|
||||
angle: 0.0,
|
||||
is_platform: plat,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,15 @@ fn main() {
|
|||
let game = Game::new("catbox demo", 1000, 800);
|
||||
|
||||
let mut i = 0u8;
|
||||
let mut s = Sprite::new("duck.png", 500, 400).unwrap();
|
||||
let mut s2 = Sprite::new("duck.png", 400, 500).unwrap();
|
||||
let mut s = Sprite::new("duck.png", 500, 400, false).unwrap();
|
||||
let mut s2 = Sprite::new("duck.png", 400, 500, false).unwrap();
|
||||
|
||||
let bytes = include_bytes!("../duck.png");
|
||||
|
||||
let mut coll = SpriteCollection::new();
|
||||
for n in 0..10 {
|
||||
for o in 0..8 {
|
||||
let x = Sprite::from_bytes(bytes, n * 100, o * 100).unwrap();
|
||||
let x = Sprite::from_bytes(bytes, n * 100, o * 100, false).unwrap();
|
||||
coll.push(x);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue