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

Improve Game Scenarios #29

Merged
merged 12 commits into from
Jan 16, 2022
Prev Previous commit
Next Next commit
wrote the labrinth scenario...unfortunately the engine doesn't suppor…
…t the whole scenario
CleanCut committed Jan 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e54ba959f9f3d40fb8c7d3364c9f01598cb5201f
2 changes: 1 addition & 1 deletion scenarios/cannon_practice.md
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ In your `// setup goes here` section of `main()`...

## Gameplay Logic

In your `game_logic(...)` function...
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...

1. Decide which keyboard/mouse input will control the rotation of the cannon, and implement rotating the cannon.
- Constrain the min/max angle of rotation to angles in the first quadrant (from straight up to straight right) with [the `.clamp` method](https://doc.rust-lang.org/std/primitive.f32.html#method.clamp) and the [`UP` and `RIGHT` constants](https://docs.rs/rusty_engine/latest/rusty_engine/#constants).
2 changes: 1 addition & 1 deletion scenarios/extreme_drivers_ed.md
Original file line number Diff line number Diff line change
@@ -34,6 +34,6 @@ In your `// game setup goes here` section of `main`...

## Game Logic

In your `game_logic(...)` function...
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...

1.
37 changes: 34 additions & 3 deletions scenarios/labrinth.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

Guide the marble from the beginning to the end of the labrinth...but don't fall in any holes!

NOTE: This scenario is not fully supported by the capabilities of the engine. You will need to supplement the engine with your own physics logic and/or make changes to the engine itself to accomplish this complete scenario. This is included here because we _might_ add enough features to support this scenario in the future. You're certainly welcome to help!

This game consists of a [Labrinth](https://en.wikipedia.org/wiki/Labyrinth) or maze with a beginning and an end. The marble starts at the beginning of the labrynth (naturally) and must proceed to the end. Sounds easy...until you realize that there are holes all along the maze, and you don't have perfect control of the marble! If you fall in one of the holes, start over from the beginning.

## Common Setup
@@ -11,8 +13,13 @@ This game consists of a [Labrinth](https://en.wikipedia.org/wiki/Labyrinth) or m
## Game State

1. Define a game state struct with fields for:
- Current tilt of the labrinth (a `Vec2`)
- Current velocity of the marble (a `Vec2`)
- Lives left (a u8)
- Lives left (a `u8`)
1. Define constants for:
- Marble movement speed (an `f32`)
- Maximum tilt magnitude (an `f32`)
- Maximum marble speed (an `f32`)
1. Choose a sprite to represent the player's marble
1. Choose a sprite to represent the starting area or spot
1. Choose a sprite to represent holes in the labrinth
@@ -33,6 +40,30 @@ In your `// setup goes here` section of `main()`...

## Gameplay Logic

In your `game_logic(...)` function...
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...

1. We will move the marble by virtually tilting the whole labrinth (even though it won't look like we're tilting it). The relative movement of the mouse will do the tilting. The more tilted the labrinth is, the faster the marble will accelerate in that direction.
- Collect [mouse movement events](https://cleancut.github.io/rusty_engine/120-mouse-events.html#mouse-motion-events) (not location events!) and add them to the current tilt of the labrinth
- Clamp the maximum length of the tilt `Vec2` to the maximum tilt magnitude constant with [the `.clamp_length_max` method](https://docs.rs/glam/latest/glam/f32/struct.Vec2.html#method.clamp_length_max).
1. Accelerate the marble.
- Each frame, multiply the tilt `Vec2` in the game state by the movement speed constant AND `engine_state.delta_f32`, and then add that resulting `Vec2` to the marble velocity in the game state. Clamp the maximum length of the marble velocity using the maximum marble velocity constant with [the `.clamp_length_max` method](https://docs.rs/glam/latest/glam/f32/struct.Vec2.html#method.clamp_length_max).
- Each frame, increment the marble sprite's translation by the velocity in the game state.
- At this point, you should be able to get the marble to move around the screen (though it ignores all the other sprites). Play with all the constant values until you get something that feels reasonable. For the game to be playable, you'll need a decently large max tilt magnitude paired with a relatively small movement speed and small max movement speed to give you enough control over the marble. But you don't want _too_ much control...it should feel like rolling a marble on a flat surface by tilting it.

## The sort of unfinished part

This section isn't well-supported by the underlying engine. 😬 Sorry.

1. Make it so that you can't go through your barriers.
- Missing engine feature: Collision contact normals.
1. Make it so that if the center of the marble overlaps a hole, you lose.
- Missing engine feature: Testing if an arbitrary `Vec2` is within a sprite's collider.

## The rest

1. When you touch the goal, you win!


## Challenges

1. We will move the marble by virtually tilting the whole labrinth. The relative movement of the mouse will do the tilting. The more tilted the labrinth is, the faster the marble will accelerate in that direction.
- When you fall down a hole, reset the game nicely and keep playing, keeping track of number of tries.
2 changes: 1 addition & 1 deletion scenarios/space_invaders.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ In your `// setup goes here` section of `main()`...

## Gameplay Logic

In your `game_logic(...)` function...
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...

1.