![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Person.cpp@8:2fd3eedcde64, 2016-12-05 (annotated)
- Committer:
- th_mbed
- Date:
- Mon Dec 05 08:09:45 2016 +0000
- Revision:
- 8:2fd3eedcde64
- Parent:
- 7:defdc7cb4e0b
- Child:
- 12:c74115744b24
- Child:
- 17:dfb8d3c5911a
add isGround in Person.; please look at models.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaku_jyoko | 4:0fe59e58def9 | 1 | #include "point.h" |
kaku_jyoko | 4:0fe59e58def9 | 2 | #include "models.h" |
th_mbed | 2:50a76ed8bf55 | 3 | |
th_mbed | 2:50a76ed8bf55 | 4 | Person::Person(){ |
kaku_jyoko | 4:0fe59e58def9 | 5 | p.x = DEFAULT_X; |
kaku_jyoko | 4:0fe59e58def9 | 6 | p.y = DEFAULT_Y; |
th_mbed | 2:50a76ed8bf55 | 7 | jump_count = 0; |
th_mbed | 2:50a76ed8bf55 | 8 | jump_time = 0; |
th_mbed | 2:50a76ed8bf55 | 9 | } |
th_mbed | 2:50a76ed8bf55 | 10 | |
th_mbed | 8:2fd3eedcde64 | 11 | point Person::update(int height){ |
th_mbed | 8:2fd3eedcde64 | 12 | if(jump_time > 0){ |
th_mbed | 8:2fd3eedcde64 | 13 | //while jumpping |
th_mbed | 8:2fd3eedcde64 | 14 | p.y -= JUMP_SIZE; |
th_mbed | 8:2fd3eedcde64 | 15 | jump_time--; |
th_mbed | 2:50a76ed8bf55 | 16 | }else{ |
th_mbed | 8:2fd3eedcde64 | 17 | //while down or go |
th_mbed | 8:2fd3eedcde64 | 18 | if(isGround(height)){ |
th_mbed | 8:2fd3eedcde64 | 19 | //while go |
th_mbed | 8:2fd3eedcde64 | 20 | jump_count = 0; |
th_mbed | 8:2fd3eedcde64 | 21 | }else{ |
th_mbed | 8:2fd3eedcde64 | 22 | //while down |
th_mbed | 8:2fd3eedcde64 | 23 | p.y += JUMP_SIZE |
th_mbed | 8:2fd3eedcde64 | 24 | } |
th_mbed | 2:50a76ed8bf55 | 25 | } |
th_mbed | 2:50a76ed8bf55 | 26 | return p; |
th_mbed | 2:50a76ed8bf55 | 27 | } |
th_mbed | 2:50a76ed8bf55 | 28 | |
th_mbed | 8:2fd3eedcde64 | 29 | point Person::jump(){ |
th_mbed | 8:2fd3eedcde64 | 30 | //start jump |
th_mbed | 8:2fd3eedcde64 | 31 | if(jump_count < MAX_JUMP_COUNT){ |
th_mbed | 8:2fd3eedcde64 | 32 | p.y -= JUMP_SIZE; |
th_mbed | 8:2fd3eedcde64 | 33 | jump_time = MAX_JUMP_TIME; |
th_mbed | 8:2fd3eedcde64 | 34 | jump_count++; |
th_mbed | 8:2fd3eedcde64 | 35 | } |
th_mbed | 2:50a76ed8bf55 | 36 | return p; |
th_mbed | 2:50a76ed8bf55 | 37 | } |
th_mbed | 2:50a76ed8bf55 | 38 | |
th_mbed | 8:2fd3eedcde64 | 39 | bool Person::isGround(int height){ |
th_mbed | 8:2fd3eedcde64 | 40 | return height == p.y; |
th_mbed | 2:50a76ed8bf55 | 41 | } |