![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Person.cpp@12:c74115744b24, 2016-12-05 (annotated)
- Committer:
- th_mbed
- Date:
- Mon Dec 05 12:01:14 2016 +0000
- Revision:
- 12:c74115744b24
- Parent:
- 8:2fd3eedcde64
- Child:
- 13:70e31c1d8205
modify Person and add Stage.; But Stage always returns all 1 height stage.
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 | 12:c74115744b24 | 11 | point Person::update(int h){ |
th_mbed | 12:c74115744b24 | 12 | int height = LCD_Y - h - 1; |
th_mbed | 8:2fd3eedcde64 | 13 | if(jump_time > 0){ |
th_mbed | 8:2fd3eedcde64 | 14 | //while jumpping |
th_mbed | 8:2fd3eedcde64 | 15 | p.y -= JUMP_SIZE; |
th_mbed | 8:2fd3eedcde64 | 16 | jump_time--; |
th_mbed | 2:50a76ed8bf55 | 17 | }else{ |
th_mbed | 8:2fd3eedcde64 | 18 | //while down or go |
th_mbed | 8:2fd3eedcde64 | 19 | if(isGround(height)){ |
th_mbed | 8:2fd3eedcde64 | 20 | //while go |
th_mbed | 8:2fd3eedcde64 | 21 | jump_count = 0; |
th_mbed | 8:2fd3eedcde64 | 22 | }else{ |
th_mbed | 8:2fd3eedcde64 | 23 | //while down |
th_mbed | 12:c74115744b24 | 24 | p.y += JUMP_SIZE; |
th_mbed | 8:2fd3eedcde64 | 25 | } |
th_mbed | 2:50a76ed8bf55 | 26 | } |
th_mbed | 2:50a76ed8bf55 | 27 | return p; |
th_mbed | 2:50a76ed8bf55 | 28 | } |
th_mbed | 2:50a76ed8bf55 | 29 | |
th_mbed | 8:2fd3eedcde64 | 30 | point Person::jump(){ |
th_mbed | 8:2fd3eedcde64 | 31 | //start jump |
th_mbed | 8:2fd3eedcde64 | 32 | if(jump_count < MAX_JUMP_COUNT){ |
th_mbed | 8:2fd3eedcde64 | 33 | p.y -= JUMP_SIZE; |
th_mbed | 8:2fd3eedcde64 | 34 | jump_time = MAX_JUMP_TIME; |
th_mbed | 8:2fd3eedcde64 | 35 | jump_count++; |
th_mbed | 8:2fd3eedcde64 | 36 | } |
th_mbed | 2:50a76ed8bf55 | 37 | return p; |
th_mbed | 2:50a76ed8bf55 | 38 | } |
th_mbed | 2:50a76ed8bf55 | 39 | |
th_mbed | 8:2fd3eedcde64 | 40 | bool Person::isGround(int height){ |
th_mbed | 12:c74115744b24 | 41 | return height == (p.y + HERSON_SIZE - 1); |
th_mbed | 2:50a76ed8bf55 | 42 | } |