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.
Diff: Player/Player.cpp
- Revision:
- 3:e4e1cbf750b6
- Parent:
- 2:f22cb01c43bc
- Child:
- 4:cf5088ace087
diff -r f22cb01c43bc -r e4e1cbf750b6 Player/Player.cpp
--- a/Player/Player.cpp Fri Apr 10 19:07:13 2020 +0000
+++ b/Player/Player.cpp Mon May 18 16:06:27 2020 +0000
@@ -1,5 +1,5 @@
#include "Player.h"
-Gamepad pad;
+#include "Sprites.h"
Player::Player()
{
@@ -11,39 +11,26 @@
}
-
-bool Player::dir()
+void Player::init(int x,int y)
{
-
- Direction d;
- //true for left to right
- if(d == E || d == NE || d == SE) {
- _direction = true;
- _vx = 2;
-
-
- }
- //false for right to left
- else if(d == W || d == NW || d == SW) {
- _direction = false;
- _vx = 2;
- }
- return _direction;
+ _playerX = x;
+ _playerY = y;
}
-bool Player::jump()
+
+
+
+bool Player::jump(Gamepad &pad)
{
bool bttnA = pad.A_pressed();
_jmp = false;
// returns true when A is pressed for jump
if(bttnA == true) {
_jmp = true;
- _vy = 3;
- return _jmp;
+ return _jmp;
} else {
- _jmp = false;
- _vy = 0;
- }
+ _jmp = false;
+ }
return _jmp;
}
@@ -52,13 +39,42 @@
void Player::draw(N5110 &lcd)
{
- if(_direction == true & _playerX + 9 < WIDTH) {
- _playerX = _playerX + _vx;
- player.render(lcd, _playerX, _playerY);
+ if(_dir == E) {
+ Bitmap bit_player(s_player, 8, 9);
+ bit_player.render(lcd, _playerX, _playerY);
}
- if(_direction == false & _playerX > 0) {
- _playerX = _playerX - _vx;
- player_inv.render(lcd, _playerX, _playerY);
+ if(_dir == W) {
+ Bitmap bit_player_inv(s_player_inv, 8, 9);
+ bit_player_inv.render(lcd, _playerX, _playerY);
+ } else {
+ Bitmap bit_player(s_player, 8, 9);
+ bit_player.render(lcd, _playerX, _playerY);
}
}
+
+void Player::update(Direction d, float mag)
+{
+ int _vx = int(mag*4.0f);
+ if(d == E) {
+ _playerX = _playerX + _vx;
+ _dir = E;
+ }
+
+ if(d == W) {
+ _playerX = _playerX - _vx;
+ _dir = W;
+ }
+ if (_playerX > WIDTH - 8) {
+ _playerX = WIDTH - 8;
+ }
+ if(_playerX < 0) {
+ _playerX = 0;
+ }
+}
+
+Vector2D Player::get_pos()
+{
+ Vector2D pos = {_playerX, _playerY};
+ return pos;
+}
\ No newline at end of file