jay, working png support
This commit is contained in:
17
Cargo.lock
generated
17
Cargo.lock
generated
@@ -2,7 +2,8 @@
|
||||
name = "super-matte-bros"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"sdl2 0.0.16 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||
"sdl2 0.0.17 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||
"sdl2_image 0.0.1-alpha.1 (git+https://github.com/fgeldenhuys/rust-sdl2_image)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -12,8 +13,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "sdl2"
|
||||
version = "0.0.16"
|
||||
source = "git+https://github.com/AngryLawyer/rust-sdl2#2dd0986162fa48fd930ab59c696c0eabc1ac2344"
|
||||
version = "0.0.17"
|
||||
source = "git+https://github.com/AngryLawyer/rust-sdl2#32b5df94f0e29805b7087d7b49ef9699e85d5640"
|
||||
dependencies = [
|
||||
"sdl2-sys 0.0.16 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||
]
|
||||
@@ -21,8 +22,16 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sdl2-sys"
|
||||
version = "0.0.16"
|
||||
source = "git+https://github.com/AngryLawyer/rust-sdl2#2dd0986162fa48fd930ab59c696c0eabc1ac2344"
|
||||
source = "git+https://github.com/AngryLawyer/rust-sdl2#32b5df94f0e29805b7087d7b49ef9699e85d5640"
|
||||
dependencies = [
|
||||
"pkg-config 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sdl2_image"
|
||||
version = "0.0.1-alpha.1"
|
||||
source = "git+https://github.com/fgeldenhuys/rust-sdl2_image#21bf12fed5d6f6a8ae49fbd20637921f97d17fe6"
|
||||
dependencies = [
|
||||
"sdl2 0.0.17 (git+https://github.com/AngryLawyer/rust-sdl2)",
|
||||
]
|
||||
|
||||
|
||||
@@ -6,5 +6,8 @@ authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
|
||||
[dependencies.sdl2]
|
||||
git = "https://github.com/AngryLawyer/rust-sdl2"
|
||||
|
||||
[dependencies.sdl2_image]
|
||||
git = "https://github.com/fgeldenhuys/rust-sdl2_image"
|
||||
|
||||
[[bin]]
|
||||
name = "super-matte-bros"
|
||||
|
||||
BIN
gfx/floor.png
Normal file
BIN
gfx/floor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
29
src/main.rs
29
src/main.rs
@@ -1,6 +1,7 @@
|
||||
extern crate sdl2;
|
||||
extern crate sdl2_image;
|
||||
|
||||
|
||||
use std::os;
|
||||
use std::num::Float;
|
||||
use std::iter::range_step;
|
||||
|
||||
@@ -34,7 +35,7 @@ const PLAYER_SPEED_X : f32 = 4.0;
|
||||
const PLAYER_THRESHOLD_X : f32 = 0.2;
|
||||
|
||||
const PLAYER_ACCELERATION_X_START : f32 = 0.02;
|
||||
const PLAYER_ACCELERATION_X_STOP : f32 = 0.1;
|
||||
const PLAYER_ACCELERATION_X_STOP : f32 = 0.15;
|
||||
const PLAYER_ACCELERATION_X_CHANGE : f32 = 0.06;
|
||||
|
||||
|
||||
@@ -47,6 +48,7 @@ enum Tile {
|
||||
|
||||
fn main() {
|
||||
sdl2::init(sdl2::INIT_EVERYTHING);
|
||||
sdl2_image::init(sdl2_image::INIT_PNG);
|
||||
|
||||
let window = match Window::new("Super Matte Bros", WindowPos::PosCentered, WindowPos::PosCentered, SCREEN_WIDTH as isize, SCREEN_HEIGHT as isize, OPENGL) {
|
||||
Ok(window) => window,
|
||||
@@ -58,6 +60,18 @@ fn main() {
|
||||
Err(err) => panic!("failed to create renderer: {}", err)
|
||||
};
|
||||
|
||||
let floor = Path::new("gfx/floor.png");
|
||||
|
||||
let surface = match sdl2_image::LoadSurface::from_file(&floor) {
|
||||
Ok(surface) => surface,
|
||||
Err(err) => panic!(format!("failed to load png: {}", err))
|
||||
};
|
||||
|
||||
let texture = match renderer.create_texture_from_surface(&surface) {
|
||||
Ok(texture) => texture,
|
||||
Err(err) => panic!(format!("failed to create surface: {}", err))
|
||||
};
|
||||
|
||||
let mut keyboard = KeyboardHandler::new();
|
||||
|
||||
let mut layer = Layer::new(120, 20, TILE_WIDTH, TILE_HEIGHT, Tile::Empty);
|
||||
@@ -111,7 +125,6 @@ fn main() {
|
||||
break 'main;
|
||||
}
|
||||
|
||||
|
||||
if keyboard.is_held(KeyCode::Right) && (player.dx >= 0.0 || player.on_ground) {
|
||||
let a = if player.dx > 0.0 {
|
||||
PLAYER_ACCELERATION_X_START
|
||||
@@ -120,8 +133,7 @@ fn main() {
|
||||
};
|
||||
|
||||
player.dx = a * PLAYER_SPEED_X + (1.0 - a) * player.dx;
|
||||
}
|
||||
else if keyboard.is_held(KeyCode::Left) && (player.dx <= 0.0 || player.on_ground) {
|
||||
} else if keyboard.is_held(KeyCode::Left) && (player.dx <= 0.0 || player.on_ground) {
|
||||
let a = if player.dx < 0.0 {
|
||||
PLAYER_ACCELERATION_X_START
|
||||
} else {
|
||||
@@ -130,9 +142,7 @@ fn main() {
|
||||
|
||||
player.dx = a * -PLAYER_SPEED_X + (1.0 - a) * player.dx;
|
||||
} else if player.on_ground {
|
||||
let a = PLAYER_ACCELERATION_X_STOP;
|
||||
|
||||
player.dx = (1.0 - a) * player.dx;
|
||||
player.dx = (1.0 - PLAYER_ACCELERATION_X_STOP) * player.dx;
|
||||
|
||||
if player.dx.abs() <= PLAYER_THRESHOLD_X {
|
||||
player.dx = 0.0;
|
||||
@@ -333,11 +343,14 @@ fn main() {
|
||||
let _ = renderer.set_draw_color(Color::RGB(0, 255, 0));
|
||||
let _ = renderer.fill_rect(&player_rect);
|
||||
|
||||
let _ = renderer.copy(&texture, None, Some(Rect::new(0, 0, 32, 32)));
|
||||
|
||||
renderer.present();
|
||||
|
||||
delay(5);
|
||||
}
|
||||
|
||||
sdl2_image::quit();
|
||||
sdl2::quit();
|
||||
}
|
||||
|
||||
|
||||
0
src/util.rs
Normal file
0
src/util.rs
Normal file
Reference in New Issue
Block a user