Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Gems/Gems.cpp@6:bf601a65cb27, 2017-05-04 (annotated)
- Committer:
- el15ss
- Date:
- Thu May 04 13:04:14 2017 +0000
- Revision:
- 6:bf601a65cb27
- Parent:
- 5:1bf7c83f86cc
StickRunner v1.0;
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 | 6:bf601a65cb27 | 6 | //fprintf("in gem init"); |
el15ss | 6:bf601a65cb27 | 7 | |
el15ss | 3:0c690f1c04d8 | 8 | //Initializing the X and Y co ordinates of the character |
el15ss | 1:db9ff66f67c8 | 9 | gemPosX = rand() % 84; |
el15ss | 1:db9ff66f67c8 | 10 | gemPosY = rand() % 42-42; |
el15ss | 1:db9ff66f67c8 | 11 | |
el15ss | 3:0c690f1c04d8 | 12 | //variable to store the status of the gem |
el15ss | 1:db9ff66f67c8 | 13 | gStatus = true; |
el15ss | 1:db9ff66f67c8 | 14 | |
el15ss | 0:12cfe63faa6a | 15 | } |
el15ss | 0:12cfe63faa6a | 16 | |
el15ss | 0:12cfe63faa6a | 17 | void Gems::draw(N5110 &lcd) |
el15ss | 0:12cfe63faa6a | 18 | { |
el15ss | 2:98a41609c827 | 19 | |
el15ss | 5:1bf7c83f86cc | 20 | //Drawing the gems |
el15ss | 6:bf601a65cb27 | 21 | //fprintf("gem being drawn"); |
el15ss | 1:db9ff66f67c8 | 22 | lcd.setPixel(gemPosX,gemPosY); |
el15ss | 1:db9ff66f67c8 | 23 | lcd.setPixel(gemPosX+1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 24 | lcd.setPixel(gemPosX-1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 25 | lcd.setPixel(gemPosX,gemPosY+1); |
el15ss | 1:db9ff66f67c8 | 26 | lcd.setPixel(gemPosX,gemPosY-1); |
el15ss | 0:12cfe63faa6a | 27 | |
el15ss | 0:12cfe63faa6a | 28 | |
el15ss | 0:12cfe63faa6a | 29 | |
el15ss | 0:12cfe63faa6a | 30 | |
el15ss | 0:12cfe63faa6a | 31 | } |
el15ss | 0:12cfe63faa6a | 32 | |
el15ss | 2:98a41609c827 | 33 | |
el15ss | 2:98a41609c827 | 34 | |
el15ss | 2:98a41609c827 | 35 | |
el15ss | 3:0c690f1c04d8 | 36 | //To move the gem |
el15ss | 2:98a41609c827 | 37 | void Gems::updateGems() |
el15ss | 2:98a41609c827 | 38 | { |
el15ss | 3:0c690f1c04d8 | 39 | //Updating the position of the gem on the screen and setting its speed |
el15ss | 6:bf601a65cb27 | 40 | //fprintf("updating th gem to make it move"); |
el15ss | 2:98a41609c827 | 41 | gemPosY =gemPosY+2; |
el15ss | 2:98a41609c827 | 42 | |
el15ss | 2:98a41609c827 | 43 | } |
el15ss | 2:98a41609c827 | 44 | |
el15ss | 2:98a41609c827 | 45 | |
el15ss | 1:db9ff66f67c8 | 46 | void Gems::gemStatus(Vector2D p) |
el15ss | 0:12cfe63faa6a | 47 | { |
el15ss | 6:bf601a65cb27 | 48 | //fprintf("in gem status"); |
el15ss | 3:0c690f1c04d8 | 49 | //Loop to check if a gem has touched the character and update its staus to make it siappear from the screen |
el15ss | 1:db9ff66f67c8 | 50 | if(((gemPosX>p.x-5)&&(gemPosX<p.x+5))&&(gemPosY>p.y)) |
el15ss | 1:db9ff66f67c8 | 51 | { |
el15ss | 3:0c690f1c04d8 | 52 | |
el15ss | 1:db9ff66f67c8 | 53 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 54 | } |
el15ss | 1:db9ff66f67c8 | 55 | |
el15ss | 6:bf601a65cb27 | 56 | //fprintf("gem status vale after checking if consumed %d",gStatus ); |
el15ss | 1:db9ff66f67c8 | 57 | |
el15ss | 3:0c690f1c04d8 | 58 | //To check if the gem has reached the bottom of the screen so we can intialise and render again |
el15ss | 1:db9ff66f67c8 | 59 | if(gemPosY > HEIGHT) |
el15ss | 1:db9ff66f67c8 | 60 | { |
el15ss | 1:db9ff66f67c8 | 61 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 62 | } |
el15ss | 0:12cfe63faa6a | 63 | } |
el15ss | 0:12cfe63faa6a | 64 | |
el15ss | 0:12cfe63faa6a | 65 | |
el15ss | 3:0c690f1c04d8 | 66 | //Returns the postion (x,y) of the gems on the screen |
el15ss | 0:12cfe63faa6a | 67 | |
el15ss | 1:db9ff66f67c8 | 68 | Vector2D Gems::getGemPos() |
el15ss | 1:db9ff66f67c8 | 69 | { |
el15ss | 6:bf601a65cb27 | 70 | //fprintf("in gem get pos"); |
el15ss | 1:db9ff66f67c8 | 71 | Vector2D p = {gemPosX,gemPosY}; |
el15ss | 0:12cfe63faa6a | 72 | return p; |
el15ss | 0:12cfe63faa6a | 73 | } |
el15ss | 1:db9ff66f67c8 | 74 | |
el15ss | 3:0c690f1c04d8 | 75 | //Returns the status of the obstacle |
el15ss | 1:db9ff66f67c8 | 76 | bool Gems::getGemStatus() |
el15ss | 1:db9ff66f67c8 | 77 | { |
el15ss | 6:bf601a65cb27 | 78 | |
el15ss | 6:bf601a65cb27 | 79 | //fprintf("in get gem status"); |
el15ss | 6:bf601a65cb27 | 80 | |
el15ss | 6:bf601a65cb27 | 81 | //fprintf("The value of gem status is (in 0/1) %d",gStatus); |
el15ss | 6:bf601a65cb27 | 82 | |
el15ss | 3:0c690f1c04d8 | 83 | //Used to check when to initialise and render the gem |
el15ss | 1:db9ff66f67c8 | 84 | return gStatus; |
el15ss | 4:2fdafb53eac2 | 85 | } |
el15ss | 4:2fdafb53eac2 | 86 | |
el15ss | 0:12cfe63faa6a | 87 | |
el15ss | 0:12cfe63faa6a | 88 |