-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a52dfb
commit d30d1b5
Showing
13 changed files
with
553 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Adolfo Ochagavía | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Adolfo Ochagavía | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
Rocket | ||
====== | ||
|
||
[![Travis Build Status][travis-build-status-svg]][travis-build-status] | ||
[![AppVeyor Build Status][appveyor-build-status-svg]][appveyor-build-status] | ||
|
||
> Rocket is a toy game written in Rust, using the Piston library. The code is thoroughly | ||
commented in order to help people to follow it easily. | ||
|
||
## Screenshots | ||
|
||
 | ||
|
||
You can find more screenshots in the [screenshots] directory. | ||
|
||
[screenshots]: screenshots/ | ||
|
||
## How to play | ||
|
||
As you can see in the screenshots below, you are the red rocket and have to save the world from | ||
the yellow invaders. To do so, you can use the following controls: | ||
|
||
Keyboard | Action | ||
----------------------- | ------------ | ||
<kbd>↑</kbd> | Boost | ||
<kbd>←</kbd> | Rotate left | ||
<kbd>→</kbd> | Rotate right | ||
<kbd>Space</kbd> | Shoot | ||
|
||
## Requirements | ||
|
||
Rocket targets the latest stable version of Rust. | ||
|
||
### Running it with Cargo | ||
|
||
As always, it is a real pleasure to work with Cargo. You only need the following: | ||
|
||
``` | ||
cargo run --release | ||
``` | ||
|
||
## Why? | ||
|
||
After having implemented some toy games in C++ using SDL and SFML, I thought it would be a | ||
good idea to try the same in Rust. Additionally, I had written a similar game in Haskell and | ||
wanted to port it to see the similarities and differences between Haskell and Rust. Another | ||
reason to program this game was to have an easy to follow Rust project that could be useful | ||
for people learning the language. | ||
|
||
## License | ||
|
||
MIT | ||
|
||
<!-- Badges --> | ||
[travis-build-status]: https://travis-ci.org/aochagavia/rocket | ||
[travis-build-status-svg]: https://travis-ci.org/aochagavia/rocket.svg | ||
|
||
[appveyor-build-status]: https://ci.appveyor.com/project/aochagavia/rocket | ||
Rocket | ||
====== | ||
|
||
[![Travis Build Status][travis-build-status-svg]][travis-build-status] | ||
[![AppVeyor Build Status][appveyor-build-status-svg]][appveyor-build-status] | ||
|
||
> Rocket is a toy game written in Rust, using the Piston library. The code is thoroughly | ||
commented in order to help people to follow it easily. | ||
|
||
## Screenshots | ||
|
||
 | ||
|
||
You can find more screenshots in the [screenshots] directory. | ||
|
||
[screenshots]: screenshots/ | ||
|
||
## How to play | ||
|
||
As you can see in the screenshots below, you are the red rocket and have to save the world from | ||
the yellow invaders. To do so, you can use the following controls: | ||
|
||
Keyboard | Action | ||
----------------------- | ------------ | ||
<kbd>↑</kbd> | Boost | ||
<kbd>←</kbd> | Rotate left | ||
<kbd>→</kbd> | Rotate right | ||
<kbd>Space</kbd> | Shoot | ||
|
||
## Requirements | ||
|
||
Rocket targets the latest stable version of Rust. | ||
|
||
### Running it with Cargo | ||
|
||
As always, it is a real pleasure to work with Cargo. You only need the following: | ||
|
||
``` | ||
cargo run --release | ||
``` | ||
|
||
## Why? | ||
|
||
After having implemented some toy games in C++ using SDL and SFML, I thought it would be a | ||
good idea to try the same in Rust. Additionally, I had written a similar game in Haskell and | ||
wanted to port it to see the similarities and differences between Haskell and Rust. Another | ||
reason to program this game was to have an easy to follow Rust project that could be useful | ||
for people learning the language. | ||
|
||
## License | ||
|
||
MIT | ||
|
||
<!-- Badges --> | ||
[travis-build-status]: https://travis-ci.org/aochagavia/rocket | ||
[travis-build-status-svg]: https://travis-ci.org/aochagavia/rocket.svg | ||
|
||
[appveyor-build-status]: https://ci.appveyor.com/project/aochagavia/rocket | ||
[appveyor-build-status-svg]: https://ci.appveyor.com/api/projects/status/its182aar6vol45b?svg=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
//! Helper objects and constants | ||
mod point; | ||
mod size; | ||
|
||
pub mod color { | ||
pub const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0]; | ||
pub const BLUE: [f32; 4] = [0.0, 0.0, 1.0, 1.0]; | ||
pub const ORANGE: [f32; 4] = [1.0, 0.5, 0.0, 1.0]; | ||
pub const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0]; | ||
pub const VIOLET: [f32; 4] = [0.6, 0.0, 1.0, 1.0]; | ||
pub const YELLOW: [f32; 4] = [1.0, 1.0, 0.0, 1.0]; | ||
} | ||
|
||
pub use self::point::Point; | ||
pub use self::size::Size; | ||
//! Helper objects and constants | ||
mod point; | ||
mod size; | ||
|
||
pub mod color { | ||
pub const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0]; | ||
pub const BLUE: [f32; 4] = [0.0, 0.0, 1.0, 1.0]; | ||
pub const ORANGE: [f32; 4] = [1.0, 0.5, 0.0, 1.0]; | ||
pub const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0]; | ||
pub const VIOLET: [f32; 4] = [0.6, 0.0, 1.0, 1.0]; | ||
pub const YELLOW: [f32; 4] = [1.0, 1.0, 0.0, 1.0]; | ||
} | ||
|
||
pub use self::point::Point; | ||
pub use self::size::Size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
use rand::Rng; | ||
|
||
use super::Size; | ||
|
||
/// A `Point` represents a position in space | ||
#[derive(Clone, Default)] | ||
pub struct Point { | ||
pub x: f64, | ||
pub y: f64 | ||
} | ||
|
||
impl Point { | ||
/// Returns a new `Point` with the given coordinates | ||
pub fn new(x: f64, y: f64) -> Point { | ||
Point { x: x, y: y } | ||
} | ||
|
||
/// Returns a random `Point` within the given bounds (exclusive) | ||
pub fn random<R: Rng>(rng: &mut R, bounds: Size) -> Point { | ||
Point { | ||
x: rng.gen_range(0.0, bounds.width), | ||
y: rng.gen_range(0.0, bounds.height) | ||
} | ||
} | ||
|
||
/// Returns the squared distance from this point to the given one | ||
pub fn squared_distance_to(&self, target: &Point) -> f64 { | ||
(self.x - target.x) * (self.x - target.x) | ||
+ (self.y - target.y) * (self.y - target.y) | ||
} | ||
|
||
/// Rotates the point through the origin in the given angle (radians) | ||
pub fn rotate(mut self, radians: f64) -> Point { | ||
let radius = (self.x * self.x + self.y * self.y).sqrt(); | ||
let point_angle = (self.y / self.x).atan(); | ||
let final_angle = point_angle + radians; | ||
self.x = final_angle.cos() * radius; | ||
self.y = final_angle.sin() * radius; | ||
self | ||
} | ||
|
||
/// Translates the point by another point | ||
pub fn translate(mut self, other: &Point) -> Point { | ||
self.x += other.x; | ||
self.y += other.y; | ||
self | ||
} | ||
} | ||
use rand::Rng; | ||
|
||
use super::Size; | ||
|
||
/// A `Point` represents a position in space | ||
#[derive(Clone, Default)] | ||
pub struct Point { | ||
pub x: f64, | ||
pub y: f64 | ||
} | ||
|
||
impl Point { | ||
/// Returns a new `Point` with the given coordinates | ||
pub fn new(x: f64, y: f64) -> Point { | ||
Point { x: x, y: y } | ||
} | ||
|
||
/// Returns a random `Point` within the given bounds (exclusive) | ||
pub fn random<R: Rng>(rng: &mut R, bounds: Size) -> Point { | ||
Point { | ||
x: rng.gen_range(0.0, bounds.width), | ||
y: rng.gen_range(0.0, bounds.height) | ||
} | ||
} | ||
|
||
/// Returns the squared distance from this point to the given one | ||
pub fn squared_distance_to(&self, target: &Point) -> f64 { | ||
(self.x - target.x) * (self.x - target.x) | ||
+ (self.y - target.y) * (self.y - target.y) | ||
} | ||
|
||
/// Rotates the point through the origin in the given angle (radians) | ||
pub fn rotate(mut self, radians: f64) -> Point { | ||
let radius = (self.x * self.x + self.y * self.y).sqrt(); | ||
let point_angle = (self.y / self.x).atan(); | ||
let final_angle = point_angle + radians; | ||
self.x = final_angle.cos() * radius; | ||
self.y = final_angle.sin() * radius; | ||
self | ||
} | ||
|
||
/// Translates the point by another point | ||
pub fn translate(mut self, other: &Point) -> Point { | ||
self.x += other.x; | ||
self.y += other.y; | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
use rand::Rng; | ||
|
||
use super::Point; | ||
|
||
/// A `Size` represents a region in space | ||
#[derive(Clone, Copy, Default)] | ||
pub struct Size { | ||
pub width: f64, | ||
pub height: f64 | ||
} | ||
|
||
impl Size { | ||
/// Returns a new `Size` of the given dimensions | ||
pub fn new(width: f64, height: f64) -> Size { | ||
Size { width: width, height: height } | ||
} | ||
|
||
/// Returns true if the `Point` is contained in this `Size` or false otherwise | ||
pub fn contains(&self, point: Point) -> bool { | ||
0.0 <= point.x && point.x <= self.width | ||
&& 0.0 <= point.y && point.y <= self.height | ||
} | ||
|
||
/// Returns a random x coordinate within the bounds of this `Size` | ||
pub fn random_x<R: Rng>(&self, rng: &mut R) -> f64 { | ||
rng.gen_range(0.0, self.width) | ||
} | ||
|
||
/// Returns a random y coordinate within the bounds of this `Size` | ||
pub fn random_y<R: Rng>(&self, rng: &mut R) -> f64 { | ||
rng.gen_range(0.0, self.height) | ||
} | ||
} | ||
use rand::Rng; | ||
|
||
use super::Point; | ||
|
||
/// A `Size` represents a region in space | ||
#[derive(Clone, Copy, Default)] | ||
pub struct Size { | ||
pub width: f64, | ||
pub height: f64 | ||
} | ||
|
||
impl Size { | ||
/// Returns a new `Size` of the given dimensions | ||
pub fn new(width: f64, height: f64) -> Size { | ||
Size { width: width, height: height } | ||
} | ||
|
||
/// Returns true if the `Point` is contained in this `Size` or false otherwise | ||
pub fn contains(&self, point: Point) -> bool { | ||
0.0 <= point.x && point.x <= self.width | ||
&& 0.0 <= point.y && point.y <= self.height | ||
} | ||
|
||
/// Returns a random x coordinate within the bounds of this `Size` | ||
pub fn random_x<R: Rng>(&self, rng: &mut R) -> f64 { | ||
rng.gen_range(0.0, self.width) | ||
} | ||
|
||
/// Returns a random y coordinate within the bounds of this `Size` | ||
pub fn random_y<R: Rng>(&self, rng: &mut R) -> f64 { | ||
rng.gen_range(0.0, self.height) | ||
} | ||
} |
Oops, something went wrong.