Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Invaders Scenario #57

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ path = "examples/scenarios/road_race.rs"
[[example]]
name = "extreme_drivers_ed"
path = "examples/scenarios/extreme_drivers_ed.rs"

[[example]]
name = "invaders"
path = "examples/scenarios/invaders.rs"
14 changes: 14 additions & 0 deletions assets/sprite/space/block_blank_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_blank_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_blank_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_blank_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_bolt_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_bolt_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_bolt_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_bolt_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_shield_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_shield_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_shield_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_shield_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_star_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_star_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/block_star_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-17.0, -11.5),
(-17.0, 11.5),
(-15.0, 14.5),
(-12.0, 16.5),
(11.0, 16.5),
(14.0, 14.5),
(16.0, 11.5),
(16.0, -11.5),
(14.0, -14.5),
(11.0, -16.5),
(-12.0, -16.5),
(-15.0, -14.5),
])
Binary file added assets/sprite/space/block_star_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/enemy_black.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-46.500004, 14.000001),
(-46.500004, 17.0),
(-29.500002, 42.0),
(29.500002, 42.0),
(46.500004, 16.5),
(46.500004, 14.000001),
(25.500002, -41.0),
(-25.500002, -41.0),
])
Binary file added assets/sprite/space/enemy_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/enemy_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-52.0, 8.0),
(-52.0, 14.0),
(-50.0, 16.0),
(-1.0, 42.0),
(1.0, 42.0),
(50.0, 16.0),
(52.0, 14.0),
(52.0, 8.0),
(24.0, -41.0),
(16.0, -42.0),
(-16.0, -42.0),
(-24.0, -41.0),
])
Binary file added assets/sprite/space/enemy_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/sprite/space/enemy_green.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Poly([
(-38.5, -42.0),
(-51.5, 0.0),
(-51.5, 4.0),
(-26.5, 36.0),
(-8.5, 42.0),
(8.5, 42.0),
(25.5, 36.0),
(51.5, 3.0),
(38.5, -42.0),
])
Binary file added assets/sprite/space/enemy_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/enemy_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-41.0, -20.0),
(-41.0, 29.0),
(-20.0, 42.0),
(20.0, 42.0),
(41.0, 29.0),
(41.0, -20.0),
(11.0, -42.0),
(-11.0, -42.0),
])
Binary file added assets/sprite/space/enemy_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions assets/sprite/space/explosion.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Poly([
(-32.0, -1.5),
(-32.0, 1.5),
(-27.0, 26.5),
(-2.0, 31.5),
(2.0, 31.5),
(27.0, 26.5),
(32.0, 2.5),
(32.0, -1.5),
(27.0, -26.5),
(2.0, -31.5),
(-2.0, -31.5),
(-27.0, -26.5),
])
Binary file added assets/sprite/space/explosion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/laser_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-1.5, -27.0),
(-4.5, -13.0),
(-4.5, 25.0),
(-2.5, 27.0),
(2.5, 27.0),
(4.5, 25.0),
(4.5, -13.0),
(1.5, -27.0),
])
Binary file added assets/sprite/space/laser_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/laser_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-1.5, -27.0),
(-4.5, -13.0),
(-4.5, 25.0),
(-2.5, 27.0),
(2.5, 27.0),
(4.5, 25.0),
(4.5, -13.0),
(1.5, -27.0),
])
Binary file added assets/sprite/space/laser_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/sprite/space/life_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Poly([
(-18.5, -4.0),
(-18.5, 0.0),
(-2.5, 13.0),
(1.5, 13.0),
(17.5, -0.0),
(17.5, -4.0),
(11.5, -12.0),
(3.5, -13.0),
(-4.5, -13.0),
(-12.5, -12.0),
])
Binary file added assets/sprite/space/life_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions assets/sprite/space/life_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Poly([
(-18.5, -4.0),
(-18.5, 0.0),
(-2.5, 13.0),
(1.5, 13.0),
(17.5, -0.0),
(17.5, -4.0),
(11.5, -12.0),
(3.5, -13.0),
(-4.5, -13.0),
(-12.5, -12.0),
])
Binary file added assets/sprite/space/life_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/ship_blue.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-49.0, -21.5),
(-4.0, 37.5),
(4.0, 37.5),
(49.0, -22.5),
(49.0, -28.5),
(14.0, -37.5),
(-14.0, -37.5),
(-49.0, -29.5),
])
Binary file added assets/sprite/space/ship_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions assets/sprite/space/ship_red.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Poly([
(-49.0, -21.5),
(-4.0, 37.5),
(4.0, 37.5),
(49.0, -22.5),
(49.0, -28.5),
(14.0, -37.5),
(-14.0, -37.5),
(-49.0, -29.5),
])
Binary file added assets/sprite/space/ship_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions assets/sprite/space/ufo.collider
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Poly([
(46.0, 0.0),
(42.49846, 17.603437),
(32.526913, 32.526913),
(17.603437, 42.49846),
(0.0, 46.0),
(-17.603437, 42.49846),
(-32.526913, 32.526913),
(-42.49846, 17.603437),
(-46.0, 0.0),
(-42.49846, -17.603437),
(-32.526913, -32.526913),
(-17.603437, -42.49846),
(0.0, -46.0),
(17.603437, -42.49846),
(32.526913, -32.526913),
(42.49846, -17.603437),
])
Binary file added assets/sprite/space/ufo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions examples/scenarios/invaders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use rusty_engine::prelude::*;

struct GameState {
string_vec: Vec<String>,
}

fn main() {
let mut game = Game::new();

// create and position the player
let player = game.add_sprite("player", "sprite/space/ship_blue.png");
player.translation.y = -275.0;
player.collision = true;

for i in 0..5 {
place_barrier(
&mut game,
format!("barrier{}", i),
Vec2::new(-624.0 + (i * (160 + 96)) as f32 + 32.0, -230.0),
);
}
// pre-populate laser labels
let mut game_state = GameState {
string_vec: Vec::new(),
};
for i in 0..2 {
game_state.string_vec.push(format!("laser{}", i));
}

game.add_logic(logic);
game.run(game_state);
}

fn logic(engine: &mut Engine, game_state: &mut GameState) {
// Player movement
let player = engine.sprites.get_mut("player").unwrap();
if let Some(location) = engine.mouse_state.location() {
player.translation.x = player
.translation
.lerp(Vec2::new(location.x, player.translation.y), 0.1)
.x;
}

// Lasers!!!
let player_translation = player.translation;
if engine.mouse_state.just_pressed(MouseButton::Left)
|| engine.keyboard_state.just_pressed(KeyCode::Space)
{
if let Some(label) = game_state.string_vec.pop() {
let laser =
engine.add_sprite(format!("laser{}", label), SpritePreset::RacingBarrierWhite);
laser.rotation = UP;
laser.scale = 0.25;
laser.translation = player_translation;
}
}
}

fn place_barrier(engine: &mut Engine, prefix: String, location: Vec2) {
for x in 0..5 {
for y in 0..3 {
if y == 2 && (x == 0 || x == 4) {
continue;
}
let block = engine.add_sprite(
format!("{}-{}-{}", prefix, x, y),
SpritePreset::RollingBlockSmall,
);
block.translation = Vec2::new(x as f32 * 32.0, y as f32 * 32.0) + location;
}
}
}
2 changes: 1 addition & 1 deletion scenarios/space_invaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Evil aliens are invading! Shoot them down.

Similar to the classic [Space Invaders](https://en.wikipedia.org/wiki/Space_Invaders) arcade game, evil car aliens are invading and you must shoot them down! Cars will be set up in a grid near tho top of the screen. They will march back and forth the screen as they come lower and lower, moving faster the less of them that there are. You are aboard the only trusty green triangle that can shoot them down!
Similar to the classic [Space Invaders](https://en.wikipedia.org/wiki/Space_Invaders) arcade game, evil aliens are invading and you must shoot them down! Aliens will be set up in a grid near the top of the screen. They will march back and forth the screen as they come lower and lower, moving faster the less of them that there are. You are aboard the only spaceship left that can shoot them down!

## Common Setup

Expand Down