ECE 2036 Project
Dependencies: mbed wave_player 4DGL-uLCD-SE
game.h@2:2042f29de6b7, 2019-11-21 (annotated)
- Committer:
- abraha2d
- Date:
- Thu Nov 21 16:10:57 2019 +0000
- Revision:
- 2:2042f29de6b7
- Parent:
- 0:cf4396614a79
Because other peeps is wanting dis...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:cf4396614a79 | 1 | #pragma once |
rconnorlawson | 0:cf4396614a79 | 2 | |
rconnorlawson | 0:cf4396614a79 | 3 | #include "physics.h" |
rconnorlawson | 0:cf4396614a79 | 4 | #include "doublely_linked_list.h" |
rconnorlawson | 0:cf4396614a79 | 5 | |
rconnorlawson | 0:cf4396614a79 | 6 | /* A structure for holding all the game inputs */ |
abraha2d | 2:2042f29de6b7 | 7 | struct GameInputs { |
rconnorlawson | 0:cf4396614a79 | 8 | // Measurements from the accelerometer |
rconnorlawson | 0:cf4396614a79 | 9 | double ax, ay, az; |
rconnorlawson | 0:cf4396614a79 | 10 | }; |
rconnorlawson | 0:cf4396614a79 | 11 | |
rconnorlawson | 0:cf4396614a79 | 12 | ////////////////////////// |
rconnorlawson | 0:cf4396614a79 | 13 | // Arena Element structs |
rconnorlawson | 0:cf4396614a79 | 14 | ////////////////////////// |
rconnorlawson | 0:cf4396614a79 | 15 | /** The basic ArenaElement structure. |
rconnorlawson | 0:cf4396614a79 | 16 | Every item in an arena DLinkedList should be able to be cast to this struct. |
rconnorlawson | 0:cf4396614a79 | 17 | The type member is used to tell what other struct this element might be. |
rconnorlawson | 0:cf4396614a79 | 18 | */ |
rconnorlawson | 0:cf4396614a79 | 19 | struct ArenaElement { |
rconnorlawson | 0:cf4396614a79 | 20 | int type; |
rconnorlawson | 0:cf4396614a79 | 21 | }; |
rconnorlawson | 0:cf4396614a79 | 22 | |
rconnorlawson | 0:cf4396614a79 | 23 | // Element types |
rconnorlawson | 0:cf4396614a79 | 24 | #define WALL 0 |
rconnorlawson | 0:cf4396614a79 | 25 | #define BALL 1 |
abraha2d | 2:2042f29de6b7 | 26 | #define GOAL 2 |
abraha2d | 2:2042f29de6b7 | 27 | #define HOLE 3 |
rconnorlawson | 0:cf4396614a79 | 28 | |
rconnorlawson | 0:cf4396614a79 | 29 | /** An ArenaElement struct representing the ball. */ |
rconnorlawson | 0:cf4396614a79 | 30 | struct Ball { |
rconnorlawson | 0:cf4396614a79 | 31 | // ArenaElement type (must be first element) |
rconnorlawson | 0:cf4396614a79 | 32 | int type; |
rconnorlawson | 0:cf4396614a79 | 33 | // Drawing info |
rconnorlawson | 0:cf4396614a79 | 34 | int x, y; |
rconnorlawson | 0:cf4396614a79 | 35 | }; |
rconnorlawson | 0:cf4396614a79 | 36 | |
abraha2d | 2:2042f29de6b7 | 37 | /** An ArenaElement struct representing the goal. */ |
abraha2d | 2:2042f29de6b7 | 38 | struct Goal { |
abraha2d | 2:2042f29de6b7 | 39 | // ArenaElement type (must be first element) |
abraha2d | 2:2042f29de6b7 | 40 | int type; |
abraha2d | 2:2042f29de6b7 | 41 | // Drawing info |
abraha2d | 2:2042f29de6b7 | 42 | int x, y; |
abraha2d | 2:2042f29de6b7 | 43 | int should_draw; |
abraha2d | 2:2042f29de6b7 | 44 | }; |
abraha2d | 2:2042f29de6b7 | 45 | |
abraha2d | 2:2042f29de6b7 | 46 | /** An ArenaElement struct representing a hole. */ |
abraha2d | 2:2042f29de6b7 | 47 | struct Hole { |
abraha2d | 2:2042f29de6b7 | 48 | // ArenaElement type (must be first element) |
abraha2d | 2:2042f29de6b7 | 49 | int type; |
abraha2d | 2:2042f29de6b7 | 50 | // Drawing info |
abraha2d | 2:2042f29de6b7 | 51 | int x, y; |
abraha2d | 2:2042f29de6b7 | 52 | int should_draw; |
abraha2d | 2:2042f29de6b7 | 53 | }; |
abraha2d | 2:2042f29de6b7 | 54 | |
rconnorlawson | 0:cf4396614a79 | 55 | ///////////////////////// |
rconnorlawson | 0:cf4396614a79 | 56 | // ArenaElement helpers |
rconnorlawson | 0:cf4396614a79 | 57 | ///////////////////////// |
rconnorlawson | 0:cf4396614a79 | 58 | /** Erases the ball */ |
rconnorlawson | 0:cf4396614a79 | 59 | void erase_ball(Ball* ball); |
rconnorlawson | 0:cf4396614a79 | 60 | /** Draws the ball at the current state */ |
rconnorlawson | 0:cf4396614a79 | 61 | void draw_ball(Ball* ball, Physics* state); |
rconnorlawson | 0:cf4396614a79 | 62 | |
rconnorlawson | 0:cf4396614a79 | 63 | /* Add additional helpers for other ArenaElement types here */ |
rconnorlawson | 0:cf4396614a79 | 64 | |
abraha2d | 2:2042f29de6b7 | 65 | /** Draws the goal */ |
abraha2d | 2:2042f29de6b7 | 66 | void draw_goal(Goal* goal); |
abraha2d | 2:2042f29de6b7 | 67 | /** Draws a hole */ |
abraha2d | 2:2042f29de6b7 | 68 | void draw_hole(Hole* hole); |
abraha2d | 2:2042f29de6b7 | 69 | |
rconnorlawson | 0:cf4396614a79 | 70 | /////////////////////////// |
abraha2d | 2:2042f29de6b7 | 71 | // Game control functions |
rconnorlawson | 0:cf4396614a79 | 72 | /////////////////////////// |
rconnorlawson | 0:cf4396614a79 | 73 | /* Reads all game inputs */ |
rconnorlawson | 0:cf4396614a79 | 74 | GameInputs read_inputs(); |
rconnorlawson | 0:cf4396614a79 | 75 | |
rconnorlawson | 0:cf4396614a79 | 76 | /* Performs a single physics update. */ |
rconnorlawson | 0:cf4396614a79 | 77 | int update_game(DLinkedList* arena, Physics* prev, GameInputs inputs, float delta); |
rconnorlawson | 0:cf4396614a79 | 78 | |
rconnorlawson | 0:cf4396614a79 | 79 | /* Implements the game loop */ |
rconnorlawson | 0:cf4396614a79 | 80 | int run_game(DLinkedList* arena, Physics* state); |