Steven Mahasin / Mbed 2 deprecated DreamDungeon

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Sun Apr 21 23:23:35 2019 +0000
Revision:
10:1a3499f6b583
Child:
12:a1c1991835ca
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?

UserRevisionLine numberNew contents of line
el17sm 10:1a3499f6b583 1 #include "Headless.h"
el17sm 10:1a3499f6b583 2 #include "math.h"
el17sm 10:1a3499f6b583 3 #include <complex>
el17sm 10:1a3499f6b583 4
el17sm 10:1a3499f6b583 5 Headless::Headless(float pos_x, float pos_y){
el17sm 10:1a3499f6b583 6 moving = false;
el17sm 10:1a3499f6b583 7 face = 0;
el17sm 10:1a3499f6b583 8 hp = 0;
el17sm 10:1a3499f6b583 9 hitbox.width = 6;
el17sm 10:1a3499f6b583 10 hitbox.height = 5;
el17sm 10:1a3499f6b583 11 position.x = pos_x;
el17sm 10:1a3499f6b583 12 position.y = pos_y;
el17sm 10:1a3499f6b583 13 sprite_size.width = 6;
el17sm 10:1a3499f6b583 14 sprite_size.height = 9;
el17sm 10:1a3499f6b583 15 sprite_size.offset_x = 0;
el17sm 10:1a3499f6b583 16 sprite_size.offset_y = 4;
el17sm 10:1a3499f6b583 17 }
el17sm 10:1a3499f6b583 18
el17sm 10:1a3499f6b583 19 void Headless::move(float player_x, float player_y){
el17sm 10:1a3499f6b583 20 std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
el17sm 10:1a3499f6b583 21 position.x += headless_velocity * pos_diff.real() / std::abs(pos_diff);
el17sm 10:1a3499f6b583 22 position.y += headless_velocity * pos_diff.imag() / std::abs(pos_diff);
el17sm 10:1a3499f6b583 23
el17sm 10:1a3499f6b583 24 // if(!matrix_collision_test(position.x + mapped_x, position.y, 0)){
el17sm 10:1a3499f6b583 25 // position.x += mapped_x;
el17sm 10:1a3499f6b583 26 // }
el17sm 10:1a3499f6b583 27 // if(!matrix_collision_test(position.x, position.y - mapped_y, 0)){
el17sm 10:1a3499f6b583 28 // position.y -= mapped_y;
el17sm 10:1a3499f6b583 29 //
el17sm 10:1a3499f6b583 30 //
el17sm 10:1a3499f6b583 31 if (std::abs(pos_diff) > 0.1f){
el17sm 10:1a3499f6b583 32 moving = true;
el17sm 10:1a3499f6b583 33 if (pos_diff.imag() / std::abs(pos_diff) < 0 && abs(pos_diff.imag() / std::abs(pos_diff)) > abs(pos_diff.real() / std::abs(pos_diff))){
el17sm 10:1a3499f6b583 34 face = 2;
el17sm 10:1a3499f6b583 35 }
el17sm 10:1a3499f6b583 36 else if (pos_diff.imag() / std::abs(pos_diff) > 0 && abs(pos_diff.imag() / std::abs(pos_diff)) > abs(pos_diff.real() / std::abs(pos_diff))){
el17sm 10:1a3499f6b583 37 face = 0;
el17sm 10:1a3499f6b583 38 }
el17sm 10:1a3499f6b583 39 else if (pos_diff.real() / std::abs(pos_diff) > 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))){
el17sm 10:1a3499f6b583 40 face = 1;
el17sm 10:1a3499f6b583 41 }
el17sm 10:1a3499f6b583 42 else if (pos_diff.real() / std::abs(pos_diff) < 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))){
el17sm 10:1a3499f6b583 43 face = 3;
el17sm 10:1a3499f6b583 44 }
el17sm 10:1a3499f6b583 45 }
el17sm 10:1a3499f6b583 46 }
el17sm 10:1a3499f6b583 47
el17sm 10:1a3499f6b583 48 void Headless::chkdmg(){
el17sm 10:1a3499f6b583 49
el17sm 10:1a3499f6b583 50 }