~ntgg/fundies2-game

7257c0c9b7e5c6a4b52f36ccea46e694e97cc229 — Noah 1 year, 9 months ago 5232311
updated spawn rate, readme, bullet speed
4 files changed, 27 insertions(+), 9 deletions(-)

M README.md
M src/components.rs
M src/main.rs
M src/systems.rs
M README.md => README.md +3 -1
@@ 1,3 1,5 @@
# Fundies 2 Game, Written in Rust

For our CS fundamentals class we had to write [this game](https://streamja.com/JwyG) in Java, so I rewrote it in Rust.
\ No newline at end of file
For our CS fundamentals class we had to write [this game](https://streamja.com/JwyG) in Java, so I rewrote it in Rust.

To play just run `cargo run --release`, should work right out of the box
\ No newline at end of file

M src/components.rs => src/components.rs +5 -1
@@ 8,6 8,10 @@ pub struct Vel(pub Vec2);
pub struct Bullet(pub u32);

impl Bullet {
    pub const SPEED: f32 = 400.0;
}

impl Bullet {
    pub fn size(&self) -> f32 {
        10.0_f32.min(self.0 as f32)
    }


@@ 17,6 21,6 @@ pub struct Ship;

impl Ship {
    pub fn size(ctx: &Context) -> f32 {
        ggez::graphics::screen_coordinates(ctx).h / 45.0
        ggez::graphics::screen_coordinates(ctx).h / 35.0
    }
}
\ No newline at end of file

M src/main.rs => src/main.rs +17 -5
@@ 7,9 7,7 @@ use std::time::{Duration, Instant};

mod vec2;
use vec2::Vec2;

mod components;

mod systems;
use systems::*;



@@ 21,7 19,7 @@ struct GameState {
}

impl GameState {
    const SHIP_SPAWN_DURATION: Duration = Duration::from_millis(1250);
    const SHIP_SPAWN_DURATION: Duration = Duration::from_millis(750);
}

impl GameState {


@@ 47,6 45,7 @@ impl ggez::event::EventHandler for GameState {
        self.ships_destroyed += handle_collision(ctx, &mut self.world);

        if self.bullets_left == 0 && bullets_on_screen(&mut self.world) == 0 {
            self.quit_event(ctx);
            ggez::quit(ctx);
        }
        


@@ 77,6 76,7 @@ impl ggez::event::EventHandler for GameState {

    fn key_down_event(&mut self, ctx: &mut Context, keycode: KeyCode, _: KeyMods, repeat: bool) {
        if keycode == KeyCode::Escape {
            self.quit_event(ctx);
            ggez::quit(ctx);
        }



@@ 85,13 85,25 @@ impl ggez::event::EventHandler for GameState {
            self.bullets_left -= 1;
        }
    }

    fn quit_event(&mut self, _ctx: &mut Context) -> bool {
        println!("You destroyed {} ships!", self.ships_destroyed);
        false
    }
}

fn main() {
    let (mut ctx, mut events_loop) = ggez::ContextBuilder::new("fundies 2 game", "Noah Graff")
        .window_setup(ggez::conf::WindowSetup::default().title("Fundies 2 Game"))
        .window_setup(
            ggez::conf::WindowSetup::default()
                .title("Fundies 2 Game")
        )
        .window_mode(
            ggez::conf::WindowMode::default()
                .dimensions(1000.0, 600.0)
        )
        .build()
        .expect("could not create ctx");
        .expect("could not initialize ggez");

    ggez::event::run(&mut ctx, &mut events_loop, &mut GameState::new(10))
        .expect("exited with error");

M src/systems.rs => src/systems.rs +2 -2
@@ 7,7 7,7 @@ use ggez::graphics::{self, Color};
pub fn shoot_bullet(ctx: &mut Context, world: &mut pyro::World) {
    let screen_rect = graphics::screen_coordinates(ctx);
    let pos = Pos(Vec2::new(screen_rect.w / 2.0, screen_rect.bottom()));
    let vel = Vel(Vec2::new(0.0, -300.0));
    let vel = Vel(Vec2::new(0.0, -Bullet::SPEED));
    let mesh = graphics::Mesh::new_circle(
        ctx,
        graphics::DrawMode::Fill,


@@ 78,7 78,7 @@ pub fn handle_collision(ctx: &mut Context, world: &mut pyro::World) -> u32 {
                            
                            let angle = i as f32 * (2.0 * f32::consts::PI / (to_spawn + 1) as f32);

                            spawn.push((*bullet_pos, Vel(Vec2::from_angle(angle, 300.0)), b, mesh));
                            spawn.push((*bullet_pos, Vel(Vec2::from_angle(angle, Bullet::SPEED)), b, mesh));
                        }
                    }
                });