You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: scenarios/cannon_practice.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ In your `// setup goes here` section of `main()`...
35
35
36
36
## Gameplay Logic
37
37
38
-
In your `game_logic(...)` function...
38
+
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...
39
39
40
40
1. Decide which keyboard/mouse input will control the rotation of the cannon, and implement rotating the cannon.
41
41
- 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).
Copy file name to clipboardExpand all lines: scenarios/labrinth.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
Guide the marble from the beginning to the end of the labrinth...but don't fall in any holes!
4
4
5
+
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!
6
+
5
7
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.
6
8
7
9
## Common Setup
@@ -11,8 +13,13 @@ This game consists of a [Labrinth](https://en.wikipedia.org/wiki/Labyrinth) or m
11
13
## Game State
12
14
13
15
1. Define a game state struct with fields for:
16
+
- Current tilt of the labrinth (a `Vec2`)
14
17
- Current velocity of the marble (a `Vec2`)
15
-
- Lives left (a u8)
18
+
- Lives left (a `u8`)
19
+
1. Define constants for:
20
+
- Marble movement speed (an `f32`)
21
+
- Maximum tilt magnitude (an `f32`)
22
+
- Maximum marble speed (an `f32`)
16
23
1. Choose a sprite to represent the player's marble
17
24
1. Choose a sprite to represent the starting area or spot
18
25
1. Choose a sprite to represent holes in the labrinth
@@ -33,6 +40,30 @@ In your `// setup goes here` section of `main()`...
33
40
34
41
## Gameplay Logic
35
42
36
-
In your `game_logic(...)` function...
43
+
In your [`game_logic(...)` function](https://cleancut.github.io/rusty_engine/25-game-logic-function.html)...
44
+
45
+
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.
46
+
- 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
47
+
- 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).
48
+
1. Accelerate the marble.
49
+
- 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).
50
+
- Each frame, increment the marble sprite's translation by the velocity in the game state.
51
+
- 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.
52
+
53
+
## The sort of unfinished part
54
+
55
+
This section isn't well-supported by the underlying engine. 😬 Sorry.
56
+
57
+
1. Make it so that you can't go through your barriers.
1. Make it so that if the center of the marble overlaps a hole, you lose.
60
+
- Missing engine feature: Testing if an arbitrary `Vec2` is within a sprite's collider.
61
+
62
+
## The rest
63
+
64
+
1. When you touch the goal, you win!
65
+
66
+
67
+
## Challenges
37
68
38
-
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.
69
+
- When you fall down a hole, reset the game nicely and keep playing, keeping track of number of tries.
0 commit comments