Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Tue Apr 23 22:59:12 2019 +0000
Revision:
12:a1c1991835ca
Parent:
11:63e54f6e7939
Child:
13:d04a6caba40d
Sprite is now controlled and stored inside each entity's files;

Who changed what in which revision?

UserRevisionLine numberNew 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 12:a1c1991835ca 16 frame.count = 0;
el17sm 12:a1c1991835ca 17 frame.number = 0;
el17sm 12:a1c1991835ca 18 frame.max = 4;
el17sm 10:1a3499f6b583 19 }
el17sm 10:1a3499f6b583 20
el17sm 10:1a3499f6b583 21 void Player::move(float mapped_x, float mapped_y){
el17sm 11:63e54f6e7939 22 if(!matrix_collision_test(position.x + player_speed*mapped_x, position.y, 0)){
el17sm 11:63e54f6e7939 23 position.x += player_speed*mapped_x;
el17sm 10:1a3499f6b583 24 }
el17sm 11:63e54f6e7939 25 if(!matrix_collision_test(position.x, position.y - player_speed*mapped_y, 0)){
el17sm 11:63e54f6e7939 26 position.y -= player_speed*mapped_y;
el17sm 10:1a3499f6b583 27 }
el17sm 10:1a3499f6b583 28 moving = false;
el17sm 10:1a3499f6b583 29 if (abs(mapped_x) + abs(mapped_y) > 0.1f){
el17sm 10:1a3499f6b583 30 moving = true;
el17sm 10:1a3499f6b583 31 if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)){
el17sm 10:1a3499f6b583 32 face = 2;
el17sm 10:1a3499f6b583 33 }
el17sm 10:1a3499f6b583 34 else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)){
el17sm 10:1a3499f6b583 35 face = 0;
el17sm 10:1a3499f6b583 36 }
el17sm 10:1a3499f6b583 37 else if (mapped_x > 0 && abs(mapped_x) > abs(mapped_y)){
el17sm 10:1a3499f6b583 38 face = 1;
el17sm 10:1a3499f6b583 39 }
el17sm 10:1a3499f6b583 40 else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)){
el17sm 10:1a3499f6b583 41 face = 3;
el17sm 10:1a3499f6b583 42 }
el17sm 12:a1c1991835ca 43
el17sm 12:a1c1991835ca 44 if (frame.number < frame.max){
el17sm 12:a1c1991835ca 45 frame.count++;
el17sm 12:a1c1991835ca 46 }
el17sm 12:a1c1991835ca 47 else {
el17sm 12:a1c1991835ca 48 frame.count = 0;
el17sm 12:a1c1991835ca 49 }
el17sm 10:1a3499f6b583 50 }
el17sm 12:a1c1991835ca 51 else{
el17sm 12:a1c1991835ca 52 frame.count = 0;
el17sm 12:a1c1991835ca 53 }
el17sm 12:a1c1991835ca 54 frame.number = (frame.count/4) % frame.max;
el17sm 12:a1c1991835ca 55 }
el17sm 12:a1c1991835ca 56
el17sm 12:a1c1991835ca 57 int * Player::get_frame(){
el17sm 12:a1c1991835ca 58 return (int *) sprite_player[face][frame.number];
el17sm 10:1a3499f6b583 59 }
el17sm 10:1a3499f6b583 60
el17sm 10:1a3499f6b583 61 void Player::chkdmg(){
el17sm 10:1a3499f6b583 62
el17sm 10:1a3499f6b583 63 }
el17sm 10:1a3499f6b583 64
el17sm 10:1a3499f6b583 65 void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X){
el17sm 10:1a3499f6b583 66 if (button_Y){
el17sm 10:1a3499f6b583 67 face = 0;
el17sm 12:a1c1991835ca 68
el17sm 10:1a3499f6b583 69 }
el17sm 10:1a3499f6b583 70 else if (button_B){
el17sm 10:1a3499f6b583 71 face = 1;
el17sm 10:1a3499f6b583 72 }
el17sm 10:1a3499f6b583 73 else if (button_A){
el17sm 10:1a3499f6b583 74 face = 2;
el17sm 10:1a3499f6b583 75 }
el17sm 10:1a3499f6b583 76 else if (button_X){
el17sm 10:1a3499f6b583 77 face = 3;
el17sm 10:1a3499f6b583 78 }
el17sm 10:1a3499f6b583 79 }