Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Gems/Gems.cpp@4:2fdafb53eac2, 2017-05-03 (annotated)
- Committer:
- el15ss
- Date:
- Wed May 03 18:00:37 2017 +0000
- Revision:
- 4:2fdafb53eac2
- Parent:
- 3:0c690f1c04d8
- Child:
- 5:1bf7c83f86cc
Completed inline and DOygen commenting
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15ss | 0:12cfe63faa6a | 1 | #include "Gems.h" |
el15ss | 0:12cfe63faa6a | 2 | |
el15ss | 0:12cfe63faa6a | 3 | |
el15ss | 0:12cfe63faa6a | 4 | void Gems::init() |
el15ss | 0:12cfe63faa6a | 5 | { |
el15ss | 3:0c690f1c04d8 | 6 | //Initializing the X and Y co ordinates of the character |
el15ss | 1:db9ff66f67c8 | 7 | gemPosX = rand() % 84; |
el15ss | 1:db9ff66f67c8 | 8 | gemPosY = rand() % 42-42; |
el15ss | 1:db9ff66f67c8 | 9 | |
el15ss | 3:0c690f1c04d8 | 10 | //variable to store the status of the gem |
el15ss | 1:db9ff66f67c8 | 11 | gStatus = true; |
el15ss | 1:db9ff66f67c8 | 12 | |
el15ss | 0:12cfe63faa6a | 13 | } |
el15ss | 0:12cfe63faa6a | 14 | |
el15ss | 0:12cfe63faa6a | 15 | void Gems::draw(N5110 &lcd) |
el15ss | 0:12cfe63faa6a | 16 | { |
el15ss | 2:98a41609c827 | 17 | |
el15ss | 3:0c690f1c04d8 | 18 | //Drawing the gems |
el15ss | 1:db9ff66f67c8 | 19 | lcd.setPixel(gemPosX,gemPosY); |
el15ss | 1:db9ff66f67c8 | 20 | lcd.setPixel(gemPosX+1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 21 | lcd.setPixel(gemPosX-1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 22 | lcd.setPixel(gemPosX,gemPosY+1); |
el15ss | 1:db9ff66f67c8 | 23 | lcd.setPixel(gemPosX,gemPosY-1); |
el15ss | 0:12cfe63faa6a | 24 | |
el15ss | 0:12cfe63faa6a | 25 | |
el15ss | 0:12cfe63faa6a | 26 | |
el15ss | 0:12cfe63faa6a | 27 | |
el15ss | 0:12cfe63faa6a | 28 | } |
el15ss | 0:12cfe63faa6a | 29 | |
el15ss | 2:98a41609c827 | 30 | |
el15ss | 2:98a41609c827 | 31 | |
el15ss | 2:98a41609c827 | 32 | |
el15ss | 3:0c690f1c04d8 | 33 | //To move the gem |
el15ss | 2:98a41609c827 | 34 | void Gems::updateGems() |
el15ss | 2:98a41609c827 | 35 | { |
el15ss | 3:0c690f1c04d8 | 36 | //Updating the position of the gem on the screen and setting its speed |
el15ss | 2:98a41609c827 | 37 | gemPosY =gemPosY+2; |
el15ss | 2:98a41609c827 | 38 | |
el15ss | 2:98a41609c827 | 39 | } |
el15ss | 2:98a41609c827 | 40 | |
el15ss | 2:98a41609c827 | 41 | |
el15ss | 1:db9ff66f67c8 | 42 | void Gems::gemStatus(Vector2D p) |
el15ss | 0:12cfe63faa6a | 43 | { |
el15ss | 3:0c690f1c04d8 | 44 | //Loop to check if a gem has touched the character and update its staus to make it siappear from the screen |
el15ss | 1:db9ff66f67c8 | 45 | if(((gemPosX>p.x-5)&&(gemPosX<p.x+5))&&(gemPosY>p.y)) |
el15ss | 1:db9ff66f67c8 | 46 | { |
el15ss | 3:0c690f1c04d8 | 47 | |
el15ss | 1:db9ff66f67c8 | 48 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 49 | } |
el15ss | 1:db9ff66f67c8 | 50 | |
el15ss | 1:db9ff66f67c8 | 51 | |
el15ss | 1:db9ff66f67c8 | 52 | |
el15ss | 3:0c690f1c04d8 | 53 | //To check if the gem has reached the bottom of the screen so we can intialise and render again |
el15ss | 1:db9ff66f67c8 | 54 | if(gemPosY > HEIGHT) |
el15ss | 1:db9ff66f67c8 | 55 | { |
el15ss | 1:db9ff66f67c8 | 56 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 57 | } |
el15ss | 0:12cfe63faa6a | 58 | } |
el15ss | 0:12cfe63faa6a | 59 | |
el15ss | 0:12cfe63faa6a | 60 | |
el15ss | 3:0c690f1c04d8 | 61 | //Returns the postion (x,y) of the gems on the screen |
el15ss | 0:12cfe63faa6a | 62 | |
el15ss | 1:db9ff66f67c8 | 63 | Vector2D Gems::getGemPos() |
el15ss | 1:db9ff66f67c8 | 64 | { |
el15ss | 1:db9ff66f67c8 | 65 | Vector2D p = {gemPosX,gemPosY}; |
el15ss | 0:12cfe63faa6a | 66 | return p; |
el15ss | 0:12cfe63faa6a | 67 | } |
el15ss | 1:db9ff66f67c8 | 68 | |
el15ss | 3:0c690f1c04d8 | 69 | //Returns the status of the obstacle |
el15ss | 1:db9ff66f67c8 | 70 | bool Gems::getGemStatus() |
el15ss | 1:db9ff66f67c8 | 71 | { |
el15ss | 3:0c690f1c04d8 | 72 | //Used to check when to initialise and render the gem |
el15ss | 1:db9ff66f67c8 | 73 | return gStatus; |
el15ss | 4:2fdafb53eac2 | 74 | } |
el15ss | 4:2fdafb53eac2 | 75 | |
el15ss | 0:12cfe63faa6a | 76 | |
el15ss | 0:12cfe63faa6a | 77 |