Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Instuctions/Instruction.cpp@13:700ea0742b24, 2019-05-05 (annotated)
- Committer:
- ll16o2l
- Date:
- Sun May 05 11:23:07 2019 +0000
- Revision:
- 13:700ea0742b24
- Parent:
- 12:1dfc34bc8382
- Child:
- 15:807eba7c7811
Documentation for Instruction
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ll16o2l | 9:99287b26be1e | 1 | #include "Instruction.h" |
| ll16o2l | 12:1dfc34bc8382 | 2 | #define max_legnth 35 |
| ll16o2l | 9:99287b26be1e | 3 | |
| ll16o2l | 9:99287b26be1e | 4 | Instruction::Instruction() |
| ll16o2l | 9:99287b26be1e | 5 | { |
| ll16o2l | 9:99287b26be1e | 6 | |
| ll16o2l | 9:99287b26be1e | 7 | } |
| ll16o2l | 9:99287b26be1e | 8 | Instruction::~Instruction() |
| ll16o2l | 9:99287b26be1e | 9 | { |
| ll16o2l | 9:99287b26be1e | 10 | |
| ll16o2l | 11:1c5c549ba75e | 11 | } |
| ll16o2l | 9:99287b26be1e | 12 | |
| ll16o2l | 13:700ea0742b24 | 13 | /** |
| ll16o2l | 13:700ea0742b24 | 14 | * This method will be used to initialise the value y. |
| ll16o2l | 13:700ea0742b24 | 15 | * @author Oliver Luong |
| ll16o2l | 13:700ea0742b24 | 16 | * @date 05/05/2019 |
| ll16o2l | 13:700ea0742b24 | 17 | */ |
| ll16o2l | 12:1dfc34bc8382 | 18 | void Instruction::init() |
| ll16o2l | 12:1dfc34bc8382 | 19 | { |
| ll16o2l | 12:1dfc34bc8382 | 20 | y = 0; |
| ll16o2l | 12:1dfc34bc8382 | 21 | //printf("Should not excecute multiple times \n"); |
| ll16o2l | 12:1dfc34bc8382 | 22 | } |
| ll16o2l | 11:1c5c549ba75e | 23 | |
| ll16o2l | 13:700ea0742b24 | 24 | /** |
| ll16o2l | 13:700ea0742b24 | 25 | * This method will be used to read the jostick |
| ll16o2l | 13:700ea0742b24 | 26 | * and then to change the value of y. |
| ll16o2l | 13:700ea0742b24 | 27 | * @author Oliver Luong |
| ll16o2l | 13:700ea0742b24 | 28 | * @date 05/05/2019 |
| ll16o2l | 13:700ea0742b24 | 29 | */ |
| ll16o2l | 12:1dfc34bc8382 | 30 | void Instruction::control(Gamepad &pad) |
| ll16o2l | 9:99287b26be1e | 31 | { |
| ll16o2l | 12:1dfc34bc8382 | 32 | d = pad.get_direction(); |
| ll16o2l | 12:1dfc34bc8382 | 33 | |
| ll16o2l | 9:99287b26be1e | 34 | if (d == N) { |
| ll16o2l | 12:1dfc34bc8382 | 35 | y = y - 1; // updates the speed in directions depending on joystick position, d. |
| ll16o2l | 12:1dfc34bc8382 | 36 | //printf("Joystick up \n"); |
| ll16o2l | 12:1dfc34bc8382 | 37 | wait(0.2); |
| ll16o2l | 9:99287b26be1e | 38 | } else if (d == S) { |
| ll16o2l | 12:1dfc34bc8382 | 39 | y = y + 1; |
| ll16o2l | 12:1dfc34bc8382 | 40 | //printf("Joystick down \n"); |
| ll16o2l | 12:1dfc34bc8382 | 41 | wait(0.2); |
| ll16o2l | 9:99287b26be1e | 42 | } |
| ll16o2l | 9:99287b26be1e | 43 | |
| ll16o2l | 12:1dfc34bc8382 | 44 | //printf("Executing \n"); |
| ll16o2l | 12:1dfc34bc8382 | 45 | //printf("%2d \n", y); |
| ll16o2l | 9:99287b26be1e | 46 | } |
| ll16o2l | 9:99287b26be1e | 47 | |
| ll16o2l | 13:700ea0742b24 | 48 | |
| ll16o2l | 13:700ea0742b24 | 49 | /** |
| ll16o2l | 13:700ea0742b24 | 50 | * This method will be used to write to the lcd. |
| ll16o2l | 13:700ea0742b24 | 51 | * @author Oliver Luong |
| ll16o2l | 13:700ea0742b24 | 52 | * @date 05/05/2019 |
| ll16o2l | 13:700ea0742b24 | 53 | */ |
| ll16o2l | 12:1dfc34bc8382 | 54 | void Instruction::write(N5110 &lcd) |
| ll16o2l | 9:99287b26be1e | 55 | { |
| ll16o2l | 10:0c200ed5973a | 56 | lcd.clear(); |
| ll16o2l | 11:1c5c549ba75e | 57 | lcd.printString("Instructions", 5, (1 - y)); //Top of the screen |
| ll16o2l | 9:99287b26be1e | 58 | |
| ll16o2l | 12:1dfc34bc8382 | 59 | lcd.printString("The game works",1,(3 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 60 | lcd.printString("by using the ",1,(4 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 61 | lcd.printString("joystick to ",1,(5 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 62 | lcd.printString("move your ",1,(6 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 63 | lcd.printString("player around ",1,(7 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 64 | lcd.printString("the screen ",1,(8 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 65 | lcd.printString("while trying ",1,(9 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 66 | lcd.printString("to dodge the ",1,(10 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 67 | lcd.printString("objects that ",1,(11 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 68 | lcd.printString("will bounce ",1,(12 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 69 | lcd.printString("around the ",1,(13 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 70 | lcd.printString("screen and ",1,(14 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 71 | lcd.printString("reflecting off ",1,(15 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 72 | lcd.printString("the walls. At ",1,(16 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 73 | lcd.printString("certains times ",1,(17 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 74 | lcd.printString("a health kit ",1,(18 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 75 | lcd.printString("will spawn, ",1,(19 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 76 | lcd.printString("try to grab ",1,(20 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 77 | lcd.printString("it before it ",1,(21 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 78 | lcd.printString("despawns. Once",1,(22 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 79 | lcd.printString("it has been ",1,(23 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 80 | lcd.printString("collected then",1,(24 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 81 | lcd.printString("you can press",1,(25 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 82 | lcd.printString("A to add a ",1,(26 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 83 | lcd.printString("life to your ",1,(27 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 84 | lcd.printString("life counter. ",1,(28 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 85 | lcd.printString("Have fun and ",1,(29 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 86 | lcd.printString("I hope that ",1,(30 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 87 | lcd.printString("you enjoy the",1,(31 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 88 | lcd.printString(" game!!! ",1,(32 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 89 | |
| ll16o2l | 12:1dfc34bc8382 | 90 | lcd.printString("Press A to play",1,(33 - y)); |
| ll16o2l | 12:1dfc34bc8382 | 91 | lcd.printString(" play",1,(34 - y)); |
| ll16o2l | 9:99287b26be1e | 92 | |
| ll16o2l | 10:0c200ed5973a | 93 | lcd.refresh(); |
| ll16o2l | 9:99287b26be1e | 94 | } |