Menu
IDS - Extended Universe
Extended Universe
Early video games lived inside of a universe that was the same size as the screen which formed a boundary. Anything outside of the screen was not visible and out of play. If a character attempted to move off the side of the screen, it was forced to stop, or re-appear on the opposite side.
MicroBit Universe
The MicroBit only has a 5x5 LED display but can keep track of objects in a much larger universe. The Player always remains in the centre (2, 2). The Treasure is located at (9,4) so that even if we PLOT it, it will not display on the MicroBit.
Goal: We want to control the player using the B-button ("right" button) so that
|
In our first video game, we set the vector of our character according to the button pressed.
If the "right" button was pressed, then we set the X-vector of our Player to be 1. However, if we want to keep our player in the centre of the screen (2, 2), then we DO NOT want the Player to move by any vector. There are 2 different methods of dealing with this type of game...
If the "right" button was pressed, then we set the X-vector of our Player to be 1. However, if we want to keep our player in the centre of the screen (2, 2), then we DO NOT want the Player to move by any vector. There are 2 different methods of dealing with this type of game...
Method 1: Opposite Vector
Exercise 1: Copy the following code into a MicroBit and try it out. Take note of the following:
- the coordinates of our player never changes (2, 2) so we don't need variables for it
- the coordinates of our player never changes so we don't unplot it either
- the right button sets the vector in the opposite direction ( -1 )
- the forever loop moves everything except our player
Of course, when you press the button, you will not see the Treasure come onto the screen for several seconds - you need to let it travel from (9, 4) one step at a time, until it arrives on screen at (4, 4).
Excercise 2: write code that will allow buttons to control two other directions (up/down or left).
Method 2: Display Offset
Exercise 3: Copy the following code into a MicroBit and try it out. Take note of the following:
- the coordinates of our player never changes (2, 2) so we don't need variables for it
- the coordinates of our player never changes so we don't unplot it either
- the right button sets the vector toward the right like when we moved our player
- the forever loop moves the TopLeft offset by the vector
- plotting requires conversion of the universe coordinate to screen coordinate
- screen coordinate = universe coordinate - TopLeft offset
Exercise 4: write code that will allow buttons to control two other directions (up/down or left).