Upgraded to latest Piston
This commit is contained in:
parent
d58d71a56f
commit
d889cc44a3
3 changed files with 26 additions and 11 deletions
10
src/app.rs
10
src/app.rs
|
|
@ -80,10 +80,8 @@ impl<'a> App<'a> {
|
|||
settings.text_dark_color[2])
|
||||
.draw(gl);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Game for App<'a> {
|
||||
fn load(&mut self) {
|
||||
pub fn load(&mut self) {
|
||||
let asset_store = AssetStore::from_folder(self.settings.asset_folder.as_slice());
|
||||
self.number_renderer = Some(NumberRenderer::new(&asset_store));
|
||||
|
||||
|
|
@ -92,7 +90,7 @@ impl<'a> Game for App<'a> {
|
|||
self.comment2 = Some(Texture::from_path(&asset_store.path("comment2.png").unwrap()).unwrap());
|
||||
}
|
||||
|
||||
fn render(&mut self, args: &RenderArgs) {
|
||||
pub fn render(&mut self, args: &RenderArgs) {
|
||||
self.gl.viewport(0, 0, args.width as i32, args.height as i32);
|
||||
let ref c = Context::abs(args.width as f64, args.height as f64);
|
||||
c.color(self.window_background_color).draw(&mut self.gl);
|
||||
|
|
@ -101,11 +99,11 @@ impl<'a> Game for App<'a> {
|
|||
self.board.render(self.number_renderer.get_ref(), c, &mut self.gl);
|
||||
}
|
||||
|
||||
fn update(&mut self, args: &UpdateArgs) {
|
||||
pub fn update(&mut self, args: &UpdateArgs) {
|
||||
self.board.update(args.dt);
|
||||
}
|
||||
|
||||
fn key_press(&mut self, args: &KeyPressArgs) {
|
||||
pub fn key_press(&mut self, args: &KeyPressArgs) {
|
||||
if args.key == keyboard::Left {
|
||||
self.board.merge_from_right_to_left();
|
||||
}
|
||||
|
|
|
|||
25
src/main.rs
25
src/main.rs
|
|
@ -20,7 +20,7 @@ mod tile;
|
|||
fn main() {
|
||||
let settings = settings::Settings::load();
|
||||
|
||||
let mut game_window = GameWindowSDL2::new(
|
||||
let mut window = GameWindowSDL2::new(
|
||||
GameWindowSettings {
|
||||
title: "Rust-2048".to_string(),
|
||||
size: settings.window_size,
|
||||
|
|
@ -30,10 +30,27 @@ fn main() {
|
|||
);
|
||||
|
||||
let mut app = app::App::new(&settings);
|
||||
|
||||
app.load();
|
||||
|
||||
let game_iter_settings = GameIteratorSettings {
|
||||
updates_per_second: 120,
|
||||
max_frames_per_second: 60,
|
||||
updates_per_second: 120,
|
||||
max_frames_per_second: 60,
|
||||
};
|
||||
app.run(&mut game_window, &game_iter_settings);
|
||||
|
||||
for e in GameIterator::new(&mut window, &game_iter_settings) {
|
||||
match e {
|
||||
Render(ref args) => {
|
||||
app.render(args);
|
||||
},
|
||||
Update(ref args) => {
|
||||
app.update(args);
|
||||
},
|
||||
KeyPress(ref args) => {
|
||||
app.key_press(args);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ fn number_to_digits(number: u32) -> Vec<u32> {
|
|||
|
||||
let mut n = number;
|
||||
while n != 0 {
|
||||
digits.unshift(n % 10);
|
||||
digits.insert(0, n % 10);
|
||||
n /= 10;
|
||||
}
|
||||
digits
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue