first commit

This commit is contained in:
brad stein 2018-10-28 21:14:05 -05:00
commit c73dd7a7d0
48700 changed files with 1230727 additions and 0 deletions

1072
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "snake_game"
version = "0.1.0"
authors = ["brad stein <brad.stein@gmail.com>"]
[dependencies]
piston = "0.37.0"
piston2d-graphics = "0.26.0"
pistoncore-glutin_window = "0.48.0"
piston2d-opengl_graphics = "0.54.0"

130
src/main.rs Normal file
View File

@ -0,0 +1,130 @@
extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;
use piston::window::WindowSettings;
use piston::event_loop::*;
use piston::input::*;
use glutin_window::GlutinWindow;
use opengl_graphics::{GlGraphics, OpenGL};
use std::collections::LinkedList;
use std::iter::FromIterator;
#[derive(Clone, PartialEq)]
enum Direction{
Right, Left, Up, Down
}
struct Game{
gl:GlGraphics,
snek: Snek,
}
impl Game{
fn render(&mut self, arg: &RenderArgs){
use graphics;
let blue: [f32; 4] = [0.0, 0.0, 1.0, 1.0];
self.gl.draw(arg.viewport(), |_c, gl|{
graphics::clear(blue, gl);
});
self.snek.render(&mut self.gl, arg);
}
fn update(&mut self){
self.snek.update();
}
fn pressed(&mut self, btn: &Button){
let last_face = self.snek.facing.clone();
self.snek.facing = match btn{
&Button::Keyboard(Key::Up)
if last_face != Direction::Down => Direction::Up,
&Button::Keyboard(Key::Down)
if last_face != Direction::Up => Direction::Down,
&Button::Keyboard(Key::Right)
if last_face != Direction::Left => Direction::Right,
&Button::Keyboard(Key::Left)
if last_face != Direction::Right => Direction::Left,
_ => last_face
};
}
}
struct Snek{
body: LinkedList<(i32,i32)>,
facing: Direction,
}
impl Snek{
fn render(&self, gl: &mut GlGraphics, args: &RenderArgs){
use graphics;
let red: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
let squares: Vec<graphics::types::Rectangle> = self.body
.iter()
.map(|&(x, y)|{
graphics::rectangle::square(
(x * 16) as f64,
(y * 16) as f64,
16_f64);
})
.collect();
gl.draw(args.viewport(), |c, gl|{
let transform = c.transform;
squares.into_iter()
.for_each(|square|graphics::rectangle(red, square, transform, gl));
});
}
fn update(&self){
let mut new_head = (*self.body.front().expect("Snek has no body")).clone();
match self.facing{
Direction::Left => new_head.0 -= 1,
Direction::Right => new_head.0 += 1,
Direction::Up => new_head.1 -= 1,
Direction::Down => new_head.1 += 1,
}
self.body.push_front(new_head);
self.body.pop_back().unwrap();
}
}
fn main() {
let opengl = OpenGL::V3_2;
let mut window: GlutinWindow = WindowSettings::new(
"Rusty Snek Gaem",
[512, 512]
).opengl(opengl)
.exit_on_esc(true)
.build()
.unwrap();
let mut game = Game{
gl: GlGraphics::new(opengl),
snek: Snek {
body: LinkedList::from_iter((vec![(0,0), (0,1)]).into_iter()),
facing: Direction::Right
},
};
let mut events = Events::new(EventSettings::new()).ups(16);
while let Some(e) = events.next(&mut window) {
if let Some(r) = e.render_args() {
game.render(&r);
}
if let Some(u) = e.update_args(){
game.update();
}
}
}

1
target/.rustc_info.json Normal file
View File

@ -0,0 +1 @@
{"rustc_fingerprint":7989369656352726626,"outputs":{"1164083562126845933":["rustc 1.29.1 (b801ae664 2018-09-20)\nbinary: rustc\ncommit-hash: b801ae66425cf7c3c71052b19ef8f145b0d0513d\ncommit-date: 2018-09-20\nhost: x86_64-unknown-linux-gnu\nrelease: 1.29.1\nLLVM version: 7.0\n",""],"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brad/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brad/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""]}}

0
target/debug/.cargo-lock Normal file
View File

View File

@ -0,0 +1 @@
e88a8abf85ce3a44

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":15597955527593234463,"profile":4001630919207402289,"path":1186404918984528324,"deps":[],"local":[{"Precalculated":"1.0.3"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
271807e5788e7978

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":15597955527593234463,"profile":14245719688690734572,"path":1186404918984528324,"deps":[],"local":[{"Precalculated":"1.0.3"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
d11fa760b0edf065

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":15597955527593234463,"profile":7990393541957723157,"path":1186404918984528324,"deps":[],"local":[{"Precalculated":"1.0.3"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
d6a0bf90fee18000

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":14450151327924579543,"profile":4001630919207402289,"path":12008749811918788239,"deps":[["nodrop v0.1.12","nodrop",1205785218737658678],["nodrop v0.1.12","nodrop",16408363113285354298]],"local":[{"Precalculated":"0.4.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
128fef901096cd76

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":14450151327924579543,"profile":14245719688690734572,"path":12008749811918788239,"deps":[["nodrop v0.1.12","nodrop",1205785218737658678]],"local":[{"Precalculated":"0.4.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
06f3fe40fb7dbe3b

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":14450151327924579543,"profile":7990393541957723157,"path":12008749811918788239,"deps":[["nodrop v0.1.12","nodrop",15450110609541191106]],"local":[{"Precalculated":"0.4.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
6773bba30395525f

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\"]","target":6279408803383612735,"profile":14245719688690734572,"path":15656925301660818016,"deps":[],"local":[{"Precalculated":"1.0.4"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
adffbe474c8f3a92

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\"]","target":6279408803383612735,"profile":7282077418741342047,"path":15656925301660818016,"deps":[],"local":[{"Precalculated":"1.0.4"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
b09fc859e4ef8633

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\"]","target":6279408803383612735,"profile":4001630919207402289,"path":15656925301660818016,"deps":[],"local":[{"Precalculated":"1.0.4"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
10371e335f968d7c

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":3379401082915848265,"profile":14245719688690734572,"path":4658920986291991828,"deps":[],"local":[{"Precalculated":"1.2.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":3379401082915848265,"profile":4001630919207402289,"path":4658920986291991828,"deps":[],"local":[{"Precalculated":"1.2.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
ad8900035baf1482

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"std\"]","target":3379401082915848265,"profile":7990393541957723157,"path":4658920986291991828,"deps":[],"local":[{"Precalculated":"1.2.7"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
9528f855d6127286

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":15621764916589621265,"profile":7282077418741342047,"path":8416787706971242842,"deps":[],"local":[{"Precalculated":"1.0.25"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
bebb801e622ffd5e

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":1132199316714279215,"profile":14245719688690734572,"path":4232272493249450669,"deps":[],"local":[{"Precalculated":"0.1.6"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
c7c19b35b448a172

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":1132199316714279215,"profile":4001630919207402289,"path":4232272493249450669,"deps":[],"local":[{"Precalculated":"0.1.6"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
647ed8e4b82ea12a

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":1132199316714279215,"profile":7282077418741342047,"path":4232272493249450669,"deps":[],"local":[{"Precalculated":"0.1.6"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":2981395198686337906,"profile":4001630919207402289,"path":1618488659211233480,"deps":[],"local":[{"Precalculated":"1.0.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":2981395198686337906,"profile":7990393541957723157,"path":1618488659211233480,"deps":[],"local":[{"Precalculated":"1.0.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":2981395198686337906,"profile":14245719688690734572,"path":1618488659211233480,"deps":[],"local":[{"Precalculated":"1.0.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":13411202063249802626,"profile":7990393541957723157,"path":18372123278102400671,"deps":[["crossbeam-epoch v0.3.1","crossbeam_epoch",6058550670715417053],["crossbeam-utils v0.2.2","crossbeam_utils",9664961016177657837]],"local":[{"Precalculated":"0.2.0"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":13411202063249802626,"profile":4001630919207402289,"path":18372123278102400671,"deps":[["crossbeam-epoch v0.3.1","crossbeam_epoch",9729000190844903416],["crossbeam-epoch v0.3.1","crossbeam_epoch",12496055850235443198],["crossbeam-utils v0.2.2","crossbeam_utils",16426929655563435700],["crossbeam-utils v0.2.2","crossbeam_utils",13727977015363145247]],"local":[{"Precalculated":"0.2.0"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":13411202063249802626,"profile":14245719688690734572,"path":18372123278102400671,"deps":[["crossbeam-epoch v0.3.1","crossbeam_epoch",12496055850235443198],["crossbeam-utils v0.2.2","crossbeam_utils",13727977015363145247]],"local":[{"Precalculated":"0.2.0"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"crossbeam-utils\", \"default\", \"lazy_static\", \"use_std\"]","target":13076516933213485900,"profile":14245719688690734572,"path":7675737547800880992,"deps":[["arrayvec v0.4.7","arrayvec",8560663464596442898],["cfg-if v0.1.6","cfg_if",6844679107138075582],["crossbeam-utils v0.2.2","crossbeam_utils",13727977015363145247],["lazy_static v1.1.0","lazy_static",6969537022938300596],["memoffset v0.2.1","memoffset",16653237122455405765],["nodrop v0.1.12","nodrop",1205785218737658678],["scopeguard v0.3.3","scopeguard",9997904105612660919]],"local":[{"Precalculated":"0.3.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"crossbeam-utils\", \"default\", \"lazy_static\", \"use_std\"]","target":13076516933213485900,"profile":7990393541957723157,"path":7675737547800880992,"deps":[["arrayvec v0.4.7","arrayvec",4305016811893486342],["cfg-if v0.1.6","cfg_if",3071787792491642468],["crossbeam-utils v0.2.2","crossbeam_utils",9664961016177657837],["lazy_static v1.1.0","lazy_static",14612575113516012609],["memoffset v0.2.1","memoffset",15233850918509156780],["nodrop v0.1.12","nodrop",15450110609541191106],["scopeguard v0.3.3","scopeguard",13167604621765880964]],"local":[{"Precalculated":"0.3.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"crossbeam-utils\", \"default\", \"lazy_static\", \"use_std\"]","target":13076516933213485900,"profile":4001630919207402289,"path":7675737547800880992,"deps":[["arrayvec v0.4.7","arrayvec",8560663464596442898],["arrayvec v0.4.7","arrayvec",36277280485384406],["cfg-if v0.1.6","cfg_if",8259963130404913607],["cfg-if v0.1.6","cfg_if",6844679107138075582],["crossbeam-utils v0.2.2","crossbeam_utils",16426929655563435700],["crossbeam-utils v0.2.2","crossbeam_utils",13727977015363145247],["lazy_static v1.1.0","lazy_static",6969537022938300596],["lazy_static v1.1.0","lazy_static",16315008813981930639],["memoffset v0.2.1","memoffset",10997941179928536678],["memoffset v0.2.1","memoffset",16653237122455405765],["nodrop v0.1.12","nodrop",1205785218737658678],["nodrop v0.1.12","nodrop",16408363113285354298],["scopeguard v0.3.3","scopeguard",9997904105612660919],["scopeguard v0.3.3","scopeguard",1722941357779641069]],"local":[{"Precalculated":"0.3.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"use_std\"]","target":6254487563143855663,"profile":7990393541957723157,"path":8812282829811828856,"deps":[["cfg-if v0.1.6","cfg_if",3071787792491642468]],"local":[{"Precalculated":"0.2.2"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"use_std\"]","target":6254487563143855663,"profile":4001630919207402289,"path":8812282829811828856,"deps":[["cfg-if v0.1.6","cfg_if",8259963130404913607],["cfg-if v0.1.6","cfg_if",6844679107138075582]],"local":[{"Precalculated":"0.2.2"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"default\", \"use_std\"]","target":6254487563143855663,"profile":14245719688690734572,"path":8812282829811828856,"deps":[["cfg-if v0.1.6","cfg_if",6844679107138075582]],"local":[{"Precalculated":"0.2.2"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
55b476d04fd3fea3

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":860365623039325023,"profile":14245719688690734572,"path":11138557167647327,"deps":[["adler32 v1.0.3","adler32",8681126406623008807],["byteorder v1.2.7","byteorder",8974994968042944272]],"local":[{"Precalculated":"0.7.19"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
9d530dbf07a02995

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":860365623039325023,"profile":4001630919207402289,"path":11138557167647327,"deps":[["adler32 v1.0.3","adler32",4916469017067817704],["adler32 v1.0.3","adler32",8681126406623008807],["byteorder v1.2.7","byteorder",3083999558310160901],["byteorder v1.2.7","byteorder",8974994968042944272]],"local":[{"Precalculated":"0.7.19"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
cfc4b4f404fbeeec

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":860365623039325023,"profile":7990393541957723157,"path":11138557167647327,"deps":[["adler32 v1.0.3","adler32",7345632334032871377],["byteorder v1.2.7","byteorder",9373309529892096429]],"local":[{"Precalculated":"0.7.19"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
19e2b2b48bfc4213

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"dlopen\"]","target":16693501533753997218,"profile":4001630919207402289,"path":3169860846614462637,"deps":[["libloading v0.5.0","libloading",12028069831798175364],["libloading v0.5.0","libloading",728395211582384261]],"local":[{"Precalculated":"0.4.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
30501508ac47fde0

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"dlopen\"]","target":16693501533753997218,"profile":7990393541957723157,"path":3169860846614462637,"deps":[["libloading v0.5.0","libloading",9732763378146996204]],"local":[{"Precalculated":"0.4.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
39c45422d38b8d2b

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[\"dlopen\"]","target":16693501533753997218,"profile":14245719688690734572,"path":3169860846614462637,"deps":[["libloading v0.5.0","libloading",728395211582384261]],"local":[{"Precalculated":"0.4.1"}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":443796734116236010,"features":"[]","target":10519635337842235797,"profile":14245719688690734572,"path":7582914830110019949,"deps":[],"local":[{"Precalculated":"1.0.3"}],"rustflags":[],"edition":"Edition2015"}

Some files were not shown because too many files have changed in this diff Show More