Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MotionSensor
Entity/Player/Player.cpp@10:1a3499f6b583, 2019-04-21 (annotated)
- Committer:
- el17sm
- Date:
- Sun Apr 21 23:23:35 2019 +0000
- Revision:
- 10:1a3499f6b583
- Child:
- 11:63e54f6e7939
Added entity_collision, Added start of Bullets,; ; Problems:; Headless can be inside player without detected by entity_collision if on the same y level
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17sm | 10:1a3499f6b583 | 1 | #include "Player.h" |
| el17sm | 10:1a3499f6b583 | 2 | #include "math.h" |
| el17sm | 10:1a3499f6b583 | 3 | |
| el17sm | 10:1a3499f6b583 | 4 | Player::Player(float pos_x, float pos_y){ |
| el17sm | 10:1a3499f6b583 | 5 | moving = false; |
| el17sm | 10:1a3499f6b583 | 6 | face = 0; |
| el17sm | 10:1a3499f6b583 | 7 | hp = 0; |
| el17sm | 10:1a3499f6b583 | 8 | hitbox.width = 6; |
| el17sm | 10:1a3499f6b583 | 9 | hitbox.height = 5; |
| el17sm | 10:1a3499f6b583 | 10 | position.x = pos_x; |
| el17sm | 10:1a3499f6b583 | 11 | position.y = pos_y; |
| el17sm | 10:1a3499f6b583 | 12 | sprite_size.width = 6; |
| el17sm | 10:1a3499f6b583 | 13 | sprite_size.height = 12; |
| el17sm | 10:1a3499f6b583 | 14 | sprite_size.offset_x = 0; |
| el17sm | 10:1a3499f6b583 | 15 | sprite_size.offset_y = 7; |
| el17sm | 10:1a3499f6b583 | 16 | } |
| el17sm | 10:1a3499f6b583 | 17 | |
| el17sm | 10:1a3499f6b583 | 18 | void Player::move(float mapped_x, float mapped_y){ |
| el17sm | 10:1a3499f6b583 | 19 | if(!matrix_collision_test(position.x + 1.2f*mapped_x, position.y, 0)){ |
| el17sm | 10:1a3499f6b583 | 20 | position.x += 1.2f*mapped_x; |
| el17sm | 10:1a3499f6b583 | 21 | } |
| el17sm | 10:1a3499f6b583 | 22 | if(!matrix_collision_test(position.x, position.y - 1.2f*mapped_y, 0)){ |
| el17sm | 10:1a3499f6b583 | 23 | position.y -= 1.2f*mapped_y; |
| el17sm | 10:1a3499f6b583 | 24 | } |
| el17sm | 10:1a3499f6b583 | 25 | moving = false; |
| el17sm | 10:1a3499f6b583 | 26 | if (abs(mapped_x) + abs(mapped_y) > 0.1f){ |
| el17sm | 10:1a3499f6b583 | 27 | moving = true; |
| el17sm | 10:1a3499f6b583 | 28 | if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)){ |
| el17sm | 10:1a3499f6b583 | 29 | face = 2; |
| el17sm | 10:1a3499f6b583 | 30 | } |
| el17sm | 10:1a3499f6b583 | 31 | else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)){ |
| el17sm | 10:1a3499f6b583 | 32 | face = 0; |
| el17sm | 10:1a3499f6b583 | 33 | } |
| el17sm | 10:1a3499f6b583 | 34 | else if (mapped_x > 0 && abs(mapped_x) > abs(mapped_y)){ |
| el17sm | 10:1a3499f6b583 | 35 | face = 1; |
| el17sm | 10:1a3499f6b583 | 36 | } |
| el17sm | 10:1a3499f6b583 | 37 | else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)){ |
| el17sm | 10:1a3499f6b583 | 38 | face = 3; |
| el17sm | 10:1a3499f6b583 | 39 | } |
| el17sm | 10:1a3499f6b583 | 40 | } |
| el17sm | 10:1a3499f6b583 | 41 | } |
| el17sm | 10:1a3499f6b583 | 42 | |
| el17sm | 10:1a3499f6b583 | 43 | void Player::chkdmg(){ |
| el17sm | 10:1a3499f6b583 | 44 | |
| el17sm | 10:1a3499f6b583 | 45 | } |
| el17sm | 10:1a3499f6b583 | 46 | |
| el17sm | 10:1a3499f6b583 | 47 | void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X){ |
| el17sm | 10:1a3499f6b583 | 48 | if (button_Y){ |
| el17sm | 10:1a3499f6b583 | 49 | face = 0; |
| el17sm | 10:1a3499f6b583 | 50 | } |
| el17sm | 10:1a3499f6b583 | 51 | else if (button_B){ |
| el17sm | 10:1a3499f6b583 | 52 | face = 1; |
| el17sm | 10:1a3499f6b583 | 53 | } |
| el17sm | 10:1a3499f6b583 | 54 | else if (button_A){ |
| el17sm | 10:1a3499f6b583 | 55 | face = 2; |
| el17sm | 10:1a3499f6b583 | 56 | } |
| el17sm | 10:1a3499f6b583 | 57 | else if (button_X){ |
| el17sm | 10:1a3499f6b583 | 58 | face = 3; |
| el17sm | 10:1a3499f6b583 | 59 | } |
| el17sm | 10:1a3499f6b583 | 60 | } |