Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Last active August 29, 2015 13:57
Show Gist options
  • Save shadowmint/9382878 to your computer and use it in GitHub Desktop.
Save shadowmint/9382878 to your computer and use it in GitHub Desktop.
Rusts stuff
use game_state::GameState;
mod game_state;
pub struct GameWindow {
window: ~int,
state: ~GameState,
}
impl GameWindow {
pub fn new(default_state: ~GameState) -> GameWindow {
let mut window = ~10;
GameWindow {
window: window,
state: default_state,
}
}
pub fn set_game_state<T: GameState>(&mut self, state: ~T) {
//self.state = state;
}
}
pub trait GameState {
fn update();
fn draw();
fn delegate_input() {}
fn call_delegated_input() {}
}
rustc -L../../rust-sfml/lib/ --out-dir bin src/main.rs
src/game_window.rs:24:14: 24:28 error: failed to find an implementation of trait game_state::GameState for ~game_state::GameState:Send
src/game_window.rs:24 state: ~default_state,
^~~~~~~~~~~~~~
make: *** [demo] Error 101
extern crate native;
use menu::{Menu};
use game_state::{GameState};
use std::io::timer;
mod game_menu;
mod game_state;
mod menu;
#[cfg(target_os="macos")]
#[start]
fn start(argc: int, argv: **u8) -> int {
native::start(argc, argv, main)
}
fn main() {
// Game Window
let menu = Menu::new(~"Line Dodge");
let game_window = game_menu::GameWindow::new(~menu);
//game_window.set_game_state(~menu);
//
// Player
// let mut circle = match CircleShape::new() {
// Some(circle) => circle,
// None => fail!("Could not render circle.")
// };
// circle.set_fill_color(&Color::green());
// circle.set_radius(50.);
//
// while window.is_open() {
// handle_input(&mut window, &mut circle);
// window.clear(&Color::new_RGB(0,0,0));
// window.display();
// }
}
use game_state::GameState;
mod game_state;
pub struct Menu {
text: ~str
}
impl Menu {
pub fn new(text: ~str) -> Menu {
Menu {
text: text,
}
}
pub fn text<'a>(&'a self) -> &'a str {
self.text.as_slice()
}
}
impl GameState for Menu {
fn update() {}
fn draw() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment