Update dependencies, fix clippy warnings
parent
ed3f393b81
commit
4fea9f23f8
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
use piston_window::math::*;
|
||||
|
||||
const BULLET_POLY: &'static [[Scalar; 2]] = &[
|
||||
const BULLET_POLY: &[[Scalar; 2]] = &[
|
||||
[-1.5, -1.5],
|
||||
[-1.5, 1.5],
|
||||
[1.5, 1.5],
|
||||
|
@ -16,11 +16,11 @@ pub struct Bullet {
|
|||
}
|
||||
|
||||
impl Bullet {
|
||||
pub fn new(loc: Vec2d, velocity: Vec2d, ttl: Scalar) -> Self {
|
||||
pub fn new(position: Vec2d, velocity: Vec2d, ttl: Scalar) -> Self {
|
||||
Bullet {
|
||||
position: loc,
|
||||
velocity: velocity,
|
||||
ttl: ttl,
|
||||
position,
|
||||
velocity,
|
||||
ttl,
|
||||
geometry: BULLET_POLY
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ pub struct Camera {
|
|||
}
|
||||
|
||||
impl Camera {
|
||||
pub fn new(pos: Vec2d, width: Scalar, height: Scalar) -> Self {
|
||||
pub fn new(position: Vec2d, width: Scalar, height: Scalar) -> Self {
|
||||
Camera {
|
||||
position: pos,
|
||||
width: width,
|
||||
height: height
|
||||
position,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ pub struct Map {
|
|||
|
||||
impl Map {
|
||||
pub fn new(width: Scalar, height: Scalar) -> Self {
|
||||
Map { width: width, height: height }
|
||||
Map { width, height }
|
||||
}
|
||||
|
||||
pub fn center(&self) -> Vec2d {
|
||||
|
@ -47,7 +47,7 @@ impl Map {
|
|||
|
||||
/* Draw vertical grid lines */
|
||||
for x in 0..xcount {
|
||||
let line_x = first_x + (GRID_SIZE * x as Scalar);
|
||||
let line_x = first_x + (GRID_SIZE * Scalar::from(x));
|
||||
let p1 = [line_x, min[1]];
|
||||
let p2 = [line_x, max[1]];
|
||||
Line::new(GREEN, 1.0)
|
||||
|
@ -56,7 +56,7 @@ impl Map {
|
|||
|
||||
/* Draw horizontal grid lines */
|
||||
for y in 0..ycount {
|
||||
let line_y = first_y + (GRID_SIZE * y as Scalar);
|
||||
let line_y = first_y + (GRID_SIZE * Scalar::from(y));
|
||||
let p1 = [min[0], line_y];
|
||||
let p2 = [max[0], line_y];
|
||||
Line::new(GREEN, 1.0)
|
||||
|
|
|
@ -70,8 +70,8 @@ impl Game {
|
|||
let ds = context.draw_state.blend(Blend::Alpha);
|
||||
|
||||
/* Make the camera coordinate origin the center of the window */
|
||||
let ct = context.transform.trans((args.width / 2) as Scalar,
|
||||
(args.height / 2) as Scalar);
|
||||
let ct = context.transform.trans(Scalar::from(args.width / 2),
|
||||
Scalar::from(args.height / 2));
|
||||
|
||||
let cam_pos = self.camera.position;
|
||||
let cam_size= [self.camera.width, self.camera.height];
|
||||
|
@ -81,7 +81,7 @@ impl Game {
|
|||
|
||||
self.map.draw_grid(cam_pos, cam_size, &ds, cam_trans, gl);
|
||||
|
||||
for bullet in self.bullets.iter() {
|
||||
for bullet in &self.bullets {
|
||||
draw_bullet(&bullet, &ds, cam_trans, gl);
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,8 @@ impl Game {
|
|||
|
||||
self.player.update(thr, rot, args.dt, &self.map);
|
||||
|
||||
for bullet in self.bullets.iter_mut() { bullet.update(args.dt); }
|
||||
self.bullets.retain(|&ref bullet| bullet.ttl > 0.0);
|
||||
for bullet in &mut self.bullets { bullet.update(args.dt); }
|
||||
self.bullets.retain(|bullet| bullet.ttl > 0.0);
|
||||
if firing {
|
||||
let (nose, dir, vel) = self.player.trajectory();
|
||||
let bul = Bullet::new(nose, add(vel, mul_scalar(dir, 3.0)), 2.0);
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use piston_window::math::*;
|
||||
use std::f64::consts::*;
|
||||
use std::f64::EPSILON;
|
||||
|
||||
use super::map::Map;
|
||||
|
||||
static TURN_RATE: Scalar = 4.0;
|
||||
static THRUST_RATE: Scalar = 4.0;
|
||||
|
||||
const SHIP_POLY: &'static [[Scalar; 2]] = &[
|
||||
const SHIP_POLY: &[[Scalar; 2]] = &[
|
||||
[-10.0, -8.0],
|
||||
[10.0, 0.0],
|
||||
[-10.0, 8.0]
|
||||
|
@ -41,8 +42,8 @@ impl Ship {
|
|||
let oldpos = self.position;
|
||||
self.position = map.clamp(oldpos);
|
||||
|
||||
if self.position[0] != oldpos[0] { self.velocity[0] = 0.0; }
|
||||
if self.position[1] != oldpos[1] { self.velocity[1] = 0.0; }
|
||||
if (self.position[0] - oldpos[0]).abs() >= EPSILON { self.velocity[0] = 0.0; }
|
||||
if (self.position[1] - oldpos[1]).abs() >= EPSILON { self.velocity[1] = 0.0; }
|
||||
}
|
||||
|
||||
pub fn trajectory(&self) -> (Vec2d, Vec2d, Vec2d) {
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
.unwrap();
|
||||
|
||||
// Create a new game and run it.
|
||||
let mut game = Game::new(XDIM as Scalar, YDIM as Scalar);
|
||||
let mut game = Game::new(Scalar::from(XDIM), Scalar::from(YDIM));
|
||||
while let Some(e) = window.next() {
|
||||
match e {
|
||||
Event::Loop(Loop::Update(upd)) => {
|
||||
|
@ -31,9 +31,8 @@ fn main() {
|
|||
game.render(ren, &mut window, &e);
|
||||
}
|
||||
|
||||
Event::Input(inp) => {
|
||||
let ev = Event::Input(inp);
|
||||
game.input(&ev);
|
||||
Event::Input(_) => {
|
||||
game.input(&e);
|
||||
}
|
||||
_ => {
|
||||
|
||||
|
|
Loading…
Reference in New Issue