![](/media/cache/profiles/004acbc8eefec9fe0629b15f52b94bcf.50x50_q85.jpg)
Peter's version
Fork of ScoreCount by
main.cpp@1:d41b5b18175b, 2013-05-01 (annotated)
- Committer:
- gcme93
- Date:
- Wed May 01 14:45:59 2013 +0000
- Revision:
- 1:d41b5b18175b
- Parent:
- 0:c82f950266fc
- Child:
- 2:289c6ccc4e86
Life count down :)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gcme93 | 0:c82f950266fc | 1 | #include "mbed.h" |
gcme93 | 0:c82f950266fc | 2 | #include "TSISensor.h" |
gcme93 | 0:c82f950266fc | 3 | #include "TextLCD.h" |
gcme93 | 0:c82f950266fc | 4 | |
gcme93 | 0:c82f950266fc | 5 | |
gcme93 | 0:c82f950266fc | 6 | |
gcme93 | 0:c82f950266fc | 7 | int hit=0; |
gcme93 | 1:d41b5b18175b | 8 | int lives=10; |
gcme93 | 0:c82f950266fc | 9 | float a; |
gcme93 | 0:c82f950266fc | 10 | TSISensor tsi; |
gcme93 | 0:c82f950266fc | 11 | |
gcme93 | 0:c82f950266fc | 12 | DigitalOut Flash(PTC11); |
gcme93 | 0:c82f950266fc | 13 | |
gcme93 | 0:c82f950266fc | 14 | |
gcme93 | 0:c82f950266fc | 15 | TextLCD lcd(PTD7, PTD6, PTA17, PTA16, PTC17, PTC16); // rs, e, d4-d7 |
gcme93 | 0:c82f950266fc | 16 | |
gcme93 | 0:c82f950266fc | 17 | |
gcme93 | 0:c82f950266fc | 18 | |
gcme93 | 1:d41b5b18175b | 19 | |
gcme93 | 0:c82f950266fc | 20 | int main() |
gcme93 | 0:c82f950266fc | 21 | |
gcme93 | 0:c82f950266fc | 22 | { |
gcme93 | 1:d41b5b18175b | 23 | Flash=1; |
gcme93 | 1:d41b5b18175b | 24 | lcd.cls(); |
gcme93 | 0:c82f950266fc | 25 | |
gcme93 | 0:c82f950266fc | 26 | |
gcme93 | 0:c82f950266fc | 27 | while(1) |
gcme93 | 0:c82f950266fc | 28 | { |
gcme93 | 0:c82f950266fc | 29 | |
gcme93 | 1:d41b5b18175b | 30 | while (lives>0) |
gcme93 | 0:c82f950266fc | 31 | |
gcme93 | 0:c82f950266fc | 32 | { |
gcme93 | 0:c82f950266fc | 33 | a=tsi.readPercentage(); |
gcme93 | 0:c82f950266fc | 34 | |
gcme93 | 0:c82f950266fc | 35 | if (a>=0.01) |
gcme93 | 0:c82f950266fc | 36 | {hit=1;} |
gcme93 | 0:c82f950266fc | 37 | else |
gcme93 | 0:c82f950266fc | 38 | {hit=0;} |
gcme93 | 0:c82f950266fc | 39 | |
gcme93 | 0:c82f950266fc | 40 | lcd.locate(0,0); |
gcme93 | 0:c82f950266fc | 41 | lcd.printf("Lives remaining: %d \n", lives); |
gcme93 | 0:c82f950266fc | 42 | |
gcme93 | 0:c82f950266fc | 43 | |
gcme93 | 0:c82f950266fc | 44 | if (hit==1) |
gcme93 | 0:c82f950266fc | 45 | { |
gcme93 | 1:d41b5b18175b | 46 | unsigned char i; |
gcme93 | 1:d41b5b18175b | 47 | |
gcme93 | 0:c82f950266fc | 48 | |
gcme93 | 0:c82f950266fc | 49 | lives--; |
gcme93 | 0:c82f950266fc | 50 | |
gcme93 | 1:d41b5b18175b | 51 | lcd.locate(0,0); |
gcme93 | 1:d41b5b18175b | 52 | lcd.printf("Lives remaining: %d \n", lives); |
gcme93 | 0:c82f950266fc | 53 | |
gcme93 | 1:d41b5b18175b | 54 | for(i=0;i<4;i++) |
gcme93 | 1:d41b5b18175b | 55 | { |
gcme93 | 1:d41b5b18175b | 56 | Flash=0; |
gcme93 | 1:d41b5b18175b | 57 | wait(0.2); |
gcme93 | 1:d41b5b18175b | 58 | Flash=1; |
gcme93 | 1:d41b5b18175b | 59 | wait(0.2); |
gcme93 | 1:d41b5b18175b | 60 | } |
gcme93 | 0:c82f950266fc | 61 | } |
gcme93 | 0:c82f950266fc | 62 | } |
gcme93 | 1:d41b5b18175b | 63 | |
gcme93 | 1:d41b5b18175b | 64 | while (lives==0) |
gcme93 | 1:d41b5b18175b | 65 | { |
gcme93 | 1:d41b5b18175b | 66 | a=tsi.readPercentage(); |
gcme93 | 1:d41b5b18175b | 67 | |
gcme93 | 1:d41b5b18175b | 68 | if (a>=0.01) |
gcme93 | 1:d41b5b18175b | 69 | {hit=1;} |
gcme93 | 1:d41b5b18175b | 70 | else |
gcme93 | 1:d41b5b18175b | 71 | {hit=0;} |
gcme93 | 1:d41b5b18175b | 72 | |
gcme93 | 1:d41b5b18175b | 73 | lcd.locate(0,0); |
gcme93 | 1:d41b5b18175b | 74 | lcd.printf("Lives remaining: %d \n", lives); |
gcme93 | 1:d41b5b18175b | 75 | |
gcme93 | 1:d41b5b18175b | 76 | |
gcme93 | 1:d41b5b18175b | 77 | if (hit==1) |
gcme93 | 1:d41b5b18175b | 78 | { |
gcme93 | 1:d41b5b18175b | 79 | lives--; |
gcme93 | 1:d41b5b18175b | 80 | } |
gcme93 | 1:d41b5b18175b | 81 | } |
gcme93 | 1:d41b5b18175b | 82 | |
gcme93 | 1:d41b5b18175b | 83 | |
gcme93 | 0:c82f950266fc | 84 | |
gcme93 | 0:c82f950266fc | 85 | lcd.cls(); |
gcme93 | 0:c82f950266fc | 86 | lcd.locate(0,0); |
gcme93 | 0:c82f950266fc | 87 | lcd.printf(" - GAME OVER - ...you suck"); |
gcme93 | 0:c82f950266fc | 88 | |
gcme93 | 1:d41b5b18175b | 89 | |
gcme93 | 1:d41b5b18175b | 90 | unsigned char i; |
gcme93 | 1:d41b5b18175b | 91 | for(i=0;i<200;i++) |
gcme93 | 1:d41b5b18175b | 92 | { |
gcme93 | 1:d41b5b18175b | 93 | Flash=0; |
gcme93 | 1:d41b5b18175b | 94 | wait(0.05); |
gcme93 | 1:d41b5b18175b | 95 | Flash=1; |
gcme93 | 1:d41b5b18175b | 96 | wait(0.05); |
gcme93 | 1:d41b5b18175b | 97 | } |
gcme93 | 1:d41b5b18175b | 98 | |
gcme93 | 0:c82f950266fc | 99 | lcd.cls(); |
gcme93 | 1:d41b5b18175b | 100 | lives= 10; |
gcme93 | 0:c82f950266fc | 101 | } |
gcme93 | 0:c82f950266fc | 102 | } |