Git Product home page Git Product logo

rocket's Introduction

Rocket

Rocket is a toy game written in Rust, using the ggez library. The code is thoroughly commented in order to help people to follow it easily.

Screenshots

Screenshot

You can find more screenshots in the screenshots directory.

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
Boost
Rotate left
Rotate right
Space Shoot

Running Rocket

Unless you are using Windows, you'll need to install SDL2 on your system. There are detailed instructions here. And 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.

rocket's People

Contributors

acheronfail avatar aochagavia avatar bluebird45 avatar bvssvni avatar byron avatar dtibbs avatar johnthagen avatar johshoff avatar kalabukdima avatar marhel avatar mightypork avatar robert-wallis avatar zarathustra30 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rocket's Issues

Weird commit diff

I just committed (2a52dfb) and the diff is much bigger than I had expected. There seems to be something going on with line endings. Did they get converted from CRLF to LF? Or just the other way around? I cannot check this in a reliable way, since Git performs conversions automatically. @johnthagen could you help me with this?

Limit shooting

It seems worthwhile to add some mechanism to disallow the player from shooting uninterruptedly, as it ruins the game (the best strategy seems to indefinitely shoot in circles). For instance, we could add a progress bar that shows the heating of the guns. Whenever the bar is full, the player cannot shoot for 3 seconds or something like that.

Add powerups every n points/seconds

I've already got a prototype of this going, but I think the idea might work well:

  • have a "powerup" spawn every n points/seconds (maybe every 500points/120sec?)
  • powerups could be:
    • shooting powerups (shoot 3 bullets at once in different directions)
    • speed powerups (go faster, or make enemies slower)
    • shield powers (get an extra life for a limited amount of time)

Only question remains: How should they be rendered? I was thinking of a star-like structure that rotates in place and changes colour/size as time goes on.

Switch to GraphicsTree piston2d backend when it is ready

Each time we draw an entity, Piston executes a draw call to the graphics card. This is incredibly expensive, but it can go unnoticed because the game does not have a big amount of entities. However, if we want others to learn from this project, it would be useful to use a backend that is able to scale. Fortunately, the graphics_tree backend seems to do exactly that, because it batches up the calls to draw and groups them together before sending them to the graphics card.

Crashes when build in release

Building the project in debug works:
'''
cargo run
'''

Then I tried building it in release mode and got a crash:
'''
cargo run --release
Finished release [optimized] target(s) in 0.0 secs
Running target\release\rocket.exe
thread 'main' panicked at 'called Result::unwrap() on an Err value: "CreateWindowEx function failed: Invalid access to memory location. (os error 998)"', ../src/libcore\result.rs:799
note: Run with RUST_BACKTRACE=1 for a backtrace.
error: process didn't exit successfully: target\release\rocket.exe (exit code: 101)
'''

Revise macro usage

There have been some changes in the language around macros, to make them more ergonomic. I don't remember whether that is a nightly only thing or not, but it seems worthwhile to investigate whether we are doing things idiomatically. For instance, is #[macro_use] still necessary? Does the order in which modules are declared influence the availability of a macro for the other modules?

Broken game mechanic

If you keep pressing space and either left or right arrow, it's almost impossible to lose :3

build failed

Fresh install of rust, did not compile, it looks like a problem with a dependency (nalgebra-0.14.4)?

Compiling specs v0.14.3
error[E0502]: cannot borrow *self as immutable because it is also borrowed as mutable
--> C:\Users\44779.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.14.4\src\core\cg.rs:292:44
|
292 | self[(j, i)] += shift[j] * self[(D::dim() - 1, i)];
| ---------------------------^^^^-------------------
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| mutable borrow later used here

error: aborting due to previous error

For more information about this error, try rustc --explain E0502.
error: could not compile nalgebra.
warning: build failed, waiting for other jobs to finish...
error: build failed

Work towards a single codebase for both ggez and wasm

Note: this is all on a separate wasm branch.

Things that need to happen:

  • Extract ggez business logic to its own crate (ggez_backend)
  • Add wasm backend, with extern functions to drive execution of the game
  • Figure out if we can come up with an abstraction layer for the view, so we can share more code
  • Document every method in the root library

Wayland dependencies

Hi again,

Any chance of updating wayland dependencies to work around this issue?

The version from Cargo.toml is affected whereas master seems to compile cleanly on ARM.

errors running `cargo run --release`

Hi there, I'm attempting to run cargo run --release and I'm running into 19 errors which are all similar to:

error: type `private::ffi::CGSRegionObject` is private
  --> /Users/<user>/.cargo/registry/src/github.com-1ecc6299db9ec823/core-graphics-0.3.2/src/private.rs:81:21
   |
81 |             assert!(ffi::CGSSetSurfaceShape(self.context_id,
   |

I'm running rustc 1.22.1 and I'm on macOS 10.12.6. Any idea what could be causing this issue?

Find a better way to implement timers

Right now, when we want to trigger an event regularly, we manually check whether enough time has elapsed. I am not convinced by this approach, as it leads to some code repetition (we use the same pattern in many places). See below for an example:

if !state.world.player.is_dead
   && self.current_time - self.last_tail_particle > TRAIL_PARTICLE_RATE {
    self.last_tail_particle = self.current_time;
    state.world.particles.push(Particle::new(state.world.player.vector.clone().invert(), 0.5));
}

I am toying with a design to change this, so we don't need to reimplement the timer logic every time. The example below already works in one of my branches, though I wonder whether it is worth it. Maybe the introduced complexity outweights the DRY improvement.

// Init the timer in the constructor of the TimeController
tail_particle_timer: Timer::new(TRAIL_PARTICLE_RATE)

// ...

// Use it in the update function
if !state.world.player.is_dead {
    self.tail_particle_timer.update(self.current_time, || {
        state.world.particles.push(Particle::new(state.world.player.vector.clone().invert(),
                                                 0.5));
    });
}

@acheronfail what do you think?

Tracking issue for 1.0 release

MVC:

  • Introduce view (#62)
  • Introduce controllers

Cleanup:

  • Use optimized version of Vec::retain
  • Split the drawing module in two: Point and Size should go to a geometry module, while color should remain in drawing.
  • Rename the traits module to physics or move its contents into the geometry module.
  • Run clippy (and maybe rustfmt) on the codebase

Build error: thread '<main>' panicked

Well, I was curious, tried to build it.

Here's what I got:

   Compiling pistoncore-event v0.3.0
   Compiling piston v0.3.0
   Compiling piston2d-opengl_graphics v0.4.0
   Compiling pistoncore-glutin_window v0.4.0
     Running `target/release/rocket`
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: OsError("glx::ChooseFBConfig failed")', src/libcore/result.rs:731
An unknown error occurred

To learn more, run the command again with --verbose.

No idea if it's in your code or somewhere in Rust, just thought you might like to have a look. I've just started learning Rust, so can't make much sense of anything here :P

Explore the possibility of using custom derive

Right now, we use the derive_position_direction! macro to derive the Position and Direction traits. This is from a time when you were not able to write derive implementations for you own traits... But now you can. This means we could use #[derive(Position, Direction)], which is "the proper way" to do it.

There is a chance that such a change would introduce lots of complexity... In that case we should keep the current macro.

Switch from f64 to f32 for geometry

Since ggez uses f32 when drawing, it seems sensible to move our geometry to f32 as well. We don't need f64 precision.

As a consequence of this change, we could remove 25 as f32 occurrences in view.rs, so itseems worthwhile.

Panic if run from anywhere but project root.

On Windows, game::Game::new() panics if Rocket was called from anywhere but the project's root directory, because it looks for "resources/FiraMono-Bold.ttf" relative to the working directory Rocket was called from, not relative to Rocket nor the project root.

(I'm not sure if you're accepting issues or pull requests or anything. I just thought you ought to know.)

OsError("glx::ChooseFBConfig failed")

Hi
I have a problem while launching your game (wow, such stack trace !) :

     Running `target/release/rocket`
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: OsError("glx::ChooseFBConfig failed")', /build/rust/src/rustc-1.1.0/src/libcore/result.rs:729
Process didn't exit successfully: `target/release/rocket` (exit code: 101)

glxinfo : http://0bin.net/paste/HKQrvHowf258NjzW#toozRH4d1ONFtB3NvxszDY5D6-CsdHkSgrMQktr1us3
graphic card : intel HD3000

cargo run crashes

I am getting the error below while trying to run, i.e. cargo run --release

Running target/release/rocket
[glutin] x error code=42 major=0 minor=0!
thread '

' panicked at 'called Result::unwrap() on an Err value: OsError("GL context creation failed")', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:729
An unknown error occurred

Is there any lib that I am missing? I am using stable rust.

Document UPS and BULLET_RATE

I think having a short doc comment for game::{UPS, BULLET_RATE} would help new readers better understand the update process.

Update to latest piston / piston_window

New versions of piston / piston_window do not require freetype as a dependency and instead use a pure rust alternative rusttype. This makes it easier to run by removing a dependency.

I tried to update the dependencies of rocket and get it to run, but was unsuccessful so far. See #19

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.