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.
Player/Player.cpp@2:f22cb01c43bc, 2020-04-10 (annotated)
- Committer:
- joebarhouch
- Date:
- Fri Apr 10 19:07:13 2020 +0000
- Revision:
- 2:f22cb01c43bc
- Child:
- 3:e4e1cbf750b6
Player control V1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joebarhouch | 2:f22cb01c43bc | 1 | #include "Player.h" |
| joebarhouch | 2:f22cb01c43bc | 2 | Gamepad pad; |
| joebarhouch | 2:f22cb01c43bc | 3 | |
| joebarhouch | 2:f22cb01c43bc | 4 | Player::Player() |
| joebarhouch | 2:f22cb01c43bc | 5 | { |
| joebarhouch | 2:f22cb01c43bc | 6 | |
| joebarhouch | 2:f22cb01c43bc | 7 | } |
| joebarhouch | 2:f22cb01c43bc | 8 | |
| joebarhouch | 2:f22cb01c43bc | 9 | Player::~Player() |
| joebarhouch | 2:f22cb01c43bc | 10 | { |
| joebarhouch | 2:f22cb01c43bc | 11 | |
| joebarhouch | 2:f22cb01c43bc | 12 | } |
| joebarhouch | 2:f22cb01c43bc | 13 | |
| joebarhouch | 2:f22cb01c43bc | 14 | |
| joebarhouch | 2:f22cb01c43bc | 15 | bool Player::dir() |
| joebarhouch | 2:f22cb01c43bc | 16 | { |
| joebarhouch | 2:f22cb01c43bc | 17 | |
| joebarhouch | 2:f22cb01c43bc | 18 | Direction d; |
| joebarhouch | 2:f22cb01c43bc | 19 | //true for left to right |
| joebarhouch | 2:f22cb01c43bc | 20 | if(d == E || d == NE || d == SE) { |
| joebarhouch | 2:f22cb01c43bc | 21 | _direction = true; |
| joebarhouch | 2:f22cb01c43bc | 22 | _vx = 2; |
| joebarhouch | 2:f22cb01c43bc | 23 | |
| joebarhouch | 2:f22cb01c43bc | 24 | |
| joebarhouch | 2:f22cb01c43bc | 25 | } |
| joebarhouch | 2:f22cb01c43bc | 26 | //false for right to left |
| joebarhouch | 2:f22cb01c43bc | 27 | else if(d == W || d == NW || d == SW) { |
| joebarhouch | 2:f22cb01c43bc | 28 | _direction = false; |
| joebarhouch | 2:f22cb01c43bc | 29 | _vx = 2; |
| joebarhouch | 2:f22cb01c43bc | 30 | } |
| joebarhouch | 2:f22cb01c43bc | 31 | return _direction; |
| joebarhouch | 2:f22cb01c43bc | 32 | } |
| joebarhouch | 2:f22cb01c43bc | 33 | |
| joebarhouch | 2:f22cb01c43bc | 34 | bool Player::jump() |
| joebarhouch | 2:f22cb01c43bc | 35 | { |
| joebarhouch | 2:f22cb01c43bc | 36 | bool bttnA = pad.A_pressed(); |
| joebarhouch | 2:f22cb01c43bc | 37 | _jmp = false; |
| joebarhouch | 2:f22cb01c43bc | 38 | // returns true when A is pressed for jump |
| joebarhouch | 2:f22cb01c43bc | 39 | if(bttnA == true) { |
| joebarhouch | 2:f22cb01c43bc | 40 | _jmp = true; |
| joebarhouch | 2:f22cb01c43bc | 41 | _vy = 3; |
| joebarhouch | 2:f22cb01c43bc | 42 | return _jmp; |
| joebarhouch | 2:f22cb01c43bc | 43 | } else { |
| joebarhouch | 2:f22cb01c43bc | 44 | _jmp = false; |
| joebarhouch | 2:f22cb01c43bc | 45 | _vy = 0; |
| joebarhouch | 2:f22cb01c43bc | 46 | } |
| joebarhouch | 2:f22cb01c43bc | 47 | |
| joebarhouch | 2:f22cb01c43bc | 48 | return _jmp; |
| joebarhouch | 2:f22cb01c43bc | 49 | } |
| joebarhouch | 2:f22cb01c43bc | 50 | |
| joebarhouch | 2:f22cb01c43bc | 51 | |
| joebarhouch | 2:f22cb01c43bc | 52 | |
| joebarhouch | 2:f22cb01c43bc | 53 | void Player::draw(N5110 &lcd) |
| joebarhouch | 2:f22cb01c43bc | 54 | { |
| joebarhouch | 2:f22cb01c43bc | 55 | if(_direction == true & _playerX + 9 < WIDTH) { |
| joebarhouch | 2:f22cb01c43bc | 56 | _playerX = _playerX + _vx; |
| joebarhouch | 2:f22cb01c43bc | 57 | player.render(lcd, _playerX, _playerY); |
| joebarhouch | 2:f22cb01c43bc | 58 | } |
| joebarhouch | 2:f22cb01c43bc | 59 | |
| joebarhouch | 2:f22cb01c43bc | 60 | if(_direction == false & _playerX > 0) { |
| joebarhouch | 2:f22cb01c43bc | 61 | _playerX = _playerX - _vx; |
| joebarhouch | 2:f22cb01c43bc | 62 | player_inv.render(lcd, _playerX, _playerY); |
| joebarhouch | 2:f22cb01c43bc | 63 | } |
| joebarhouch | 2:f22cb01c43bc | 64 | } |