Initial Commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
1295
Cargo.lock
generated
Normal file
1295
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
Normal file
13
Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "snake-rs"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Marco Thomas <mthomas@marcmk.de>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
piston = "0.52.0"
|
||||||
|
piston2d-graphics = "0.36.0"
|
||||||
|
pistoncore-glutin_window = "0.66.0"
|
||||||
|
piston2d-opengl_graphics = "0.73.0"
|
||||||
82
src/main.rs
Normal file
82
src/main.rs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
extern crate glutin_window;
|
||||||
|
extern crate graphics;
|
||||||
|
extern crate opengl_graphics;
|
||||||
|
extern crate piston;
|
||||||
|
|
||||||
|
use piston::window::WindowSettings;
|
||||||
|
use piston::input::*;
|
||||||
|
use piston::event_loop::*;
|
||||||
|
use glutin_window::GlutinWindow;
|
||||||
|
use opengl_graphics::{GlGraphics, OpenGL};
|
||||||
|
|
||||||
|
struct Game {
|
||||||
|
gl: GlGraphics,
|
||||||
|
snake: Snake,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Game {
|
||||||
|
fn render(&mut self, args: &RenderArgs) {
|
||||||
|
use graphics;
|
||||||
|
|
||||||
|
const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
|
||||||
|
|
||||||
|
self.gl.draw(args.viewport(), |_c, gl| {
|
||||||
|
graphics::clear(BLACK, gl);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.snake.render(&mut self.gl, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Snake {
|
||||||
|
x_pos: i32,
|
||||||
|
y_pos: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Snake {
|
||||||
|
fn render(&self, gl: &mut GlGraphics, args: &RenderArgs) {
|
||||||
|
use graphics;
|
||||||
|
|
||||||
|
const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
|
||||||
|
|
||||||
|
let square = graphics::rectangle::square(
|
||||||
|
self.x_pos as f64,
|
||||||
|
self.y_pos as f64,
|
||||||
|
20.0);
|
||||||
|
|
||||||
|
gl.draw(args.viewport(), |c, gl| {
|
||||||
|
let transform = c.transform;
|
||||||
|
|
||||||
|
graphics::rectangle(GREEN, square, transform, gl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let opengl = OpenGL::V3_2;
|
||||||
|
|
||||||
|
let mut window: GlutinWindow = WindowSettings::new(
|
||||||
|
"snake-rs",
|
||||||
|
[200, 200])
|
||||||
|
.graphics_api(opengl)
|
||||||
|
.exit_on_esc(true)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut game = Game {
|
||||||
|
gl: GlGraphics::new(opengl),
|
||||||
|
snake: Snake {
|
||||||
|
x_pos: 50,
|
||||||
|
y_pos: 50
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let mut events = Events::new(EventSettings::new());
|
||||||
|
while let Some(e) = events.next(&mut window) {
|
||||||
|
if let Some(args) = e.render_args() {
|
||||||
|
game.render(&args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user