Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Gems/Gems.cpp@2:98a41609c827, 2017-05-02 (annotated)
- Committer:
- el15ss
- Date:
- Tue May 02 18:42:45 2017 +0000
- Revision:
- 2:98a41609c827
- Parent:
- 1:db9ff66f67c8
- Child:
- 3:0c690f1c04d8
Added SD card functionality
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 | 1:db9ff66f67c8 | 6 | gemPosX = rand() % 84; |
el15ss | 1:db9ff66f67c8 | 7 | gemPosY = rand() % 42-42; |
el15ss | 1:db9ff66f67c8 | 8 | |
el15ss | 1:db9ff66f67c8 | 9 | gStatus = true; |
el15ss | 1:db9ff66f67c8 | 10 | |
el15ss | 0:12cfe63faa6a | 11 | } |
el15ss | 0:12cfe63faa6a | 12 | |
el15ss | 0:12cfe63faa6a | 13 | void Gems::draw(N5110 &lcd) |
el15ss | 0:12cfe63faa6a | 14 | { |
el15ss | 2:98a41609c827 | 15 | |
el15ss | 1:db9ff66f67c8 | 16 | //lcd.drawRect(gemPosX-4,gemPosY-3,3,3,FILL_BLACK); |
el15ss | 1:db9ff66f67c8 | 17 | //lcd.drawLine(gemPosX-3, gemPosY-3,gemPosX-3,gemPosY+1,1); |
el15ss | 0:12cfe63faa6a | 18 | |
el15ss | 1:db9ff66f67c8 | 19 | //lcd.drawCircle(gemPosX,gemPosY,2,FILL_BLACK); |
el15ss | 1:db9ff66f67c8 | 20 | lcd.setPixel(gemPosX,gemPosY); |
el15ss | 1:db9ff66f67c8 | 21 | lcd.setPixel(gemPosX+1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 22 | lcd.setPixel(gemPosX-1,gemPosY); |
el15ss | 1:db9ff66f67c8 | 23 | lcd.setPixel(gemPosX,gemPosY+1); |
el15ss | 1:db9ff66f67c8 | 24 | lcd.setPixel(gemPosX,gemPosY-1); |
el15ss | 0:12cfe63faa6a | 25 | |
el15ss | 0:12cfe63faa6a | 26 | |
el15ss | 0:12cfe63faa6a | 27 | |
el15ss | 0:12cfe63faa6a | 28 | |
el15ss | 0:12cfe63faa6a | 29 | } |
el15ss | 0:12cfe63faa6a | 30 | |
el15ss | 2:98a41609c827 | 31 | |
el15ss | 2:98a41609c827 | 32 | |
el15ss | 2:98a41609c827 | 33 | int Gems::gemScore() |
el15ss | 2:98a41609c827 | 34 | { |
el15ss | 2:98a41609c827 | 35 | //return counter; |
el15ss | 2:98a41609c827 | 36 | } |
el15ss | 2:98a41609c827 | 37 | |
el15ss | 2:98a41609c827 | 38 | void Gems::updateGems() |
el15ss | 2:98a41609c827 | 39 | { |
el15ss | 2:98a41609c827 | 40 | gemPosY =gemPosY+2; |
el15ss | 2:98a41609c827 | 41 | |
el15ss | 2:98a41609c827 | 42 | } |
el15ss | 2:98a41609c827 | 43 | |
el15ss | 2:98a41609c827 | 44 | |
el15ss | 1:db9ff66f67c8 | 45 | void Gems::gemStatus(Vector2D p) |
el15ss | 0:12cfe63faa6a | 46 | { |
el15ss | 1:db9ff66f67c8 | 47 | if(((gemPosX>p.x-5)&&(gemPosX<p.x+5))&&(gemPosY>p.y)) |
el15ss | 1:db9ff66f67c8 | 48 | { |
el15ss | 1:db9ff66f67c8 | 49 | //counter++; |
el15ss | 1:db9ff66f67c8 | 50 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 51 | } |
el15ss | 1:db9ff66f67c8 | 52 | |
el15ss | 1:db9ff66f67c8 | 53 | |
el15ss | 1:db9ff66f67c8 | 54 | |
el15ss | 0:12cfe63faa6a | 55 | |
el15ss | 1:db9ff66f67c8 | 56 | if(gemPosY > HEIGHT) |
el15ss | 1:db9ff66f67c8 | 57 | { |
el15ss | 1:db9ff66f67c8 | 58 | gStatus = false; |
el15ss | 1:db9ff66f67c8 | 59 | } |
el15ss | 0:12cfe63faa6a | 60 | } |
el15ss | 0:12cfe63faa6a | 61 | |
el15ss | 0:12cfe63faa6a | 62 | |
el15ss | 0:12cfe63faa6a | 63 | |
el15ss | 1:db9ff66f67c8 | 64 | Vector2D Gems::getGemPos() |
el15ss | 1:db9ff66f67c8 | 65 | { |
el15ss | 1:db9ff66f67c8 | 66 | Vector2D p = {gemPosX,gemPosY}; |
el15ss | 0:12cfe63faa6a | 67 | return p; |
el15ss | 0:12cfe63faa6a | 68 | } |
el15ss | 1:db9ff66f67c8 | 69 | |
el15ss | 1:db9ff66f67c8 | 70 | bool Gems::getGemStatus() |
el15ss | 1:db9ff66f67c8 | 71 | { |
el15ss | 1:db9ff66f67c8 | 72 | return gStatus; |
el15ss | 0:12cfe63faa6a | 73 | |
el15ss | 0:12cfe63faa6a | 74 | } |
el15ss | 0:12cfe63faa6a | 75 | |
el15ss | 0:12cfe63faa6a | 76 |