1
This commit is contained in:
parent
5e2122d2a9
commit
66f692e324
@ -1,6 +1,10 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "movement.h"
|
||||
#include "bullet.h"
|
||||
#include "human.h"
|
||||
#include "room.h"
|
||||
#include "metadata.h"
|
||||
|
||||
void MovementComponent::RayDetection()
|
||||
{
|
||||
@ -9,15 +13,90 @@ void MovementComponent::RayDetection()
|
||||
|
||||
void MovementComponent::Clear()
|
||||
{
|
||||
|
||||
passed_distance = 0.0f;
|
||||
target_distance = 0.0f;
|
||||
start_point = Vector2D();
|
||||
target_point = Vector2D();
|
||||
detection_objects.clear();
|
||||
}
|
||||
|
||||
void MovementComponent::GetCollisionObjects(std::set<Entity*>& objects)
|
||||
{
|
||||
|
||||
if (owner->entity_type == ET_Bullet) {
|
||||
Bullet* bullet = (Bullet*)owner;
|
||||
for (Entity* entity : detection_objects) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (bullet->TestCollision(entity)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MovementComponent::TestCollision()
|
||||
{
|
||||
if (owner->entity_type == ET_Bullet) {
|
||||
Bullet* bullet = (Bullet*)owner;
|
||||
for (Entity* entity : detection_objects) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (bullet->TestCollision(entity)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (owner->entity_type == ET_Player) {
|
||||
Human* hum = (Human*)owner;
|
||||
if (hum->room->OverBorder(hum->pos, hum->meta->i->radius())){
|
||||
return true;
|
||||
}
|
||||
if (a8::HasBitFlag(hum->status, HS_Jump)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Entity* entity : detection_objects) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
{
|
||||
if (
|
||||
(hum->last_collision_door == nullptr || hum->last_collision_door != entity) &&
|
||||
hum->TestCollision(entity)
|
||||
){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ET_Building:
|
||||
{
|
||||
if (hum->TestCollision(entity)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user