Barriers are queried, created when colliding with creatures

This commit is contained in:
2016-04-04 02:41:14 +10:00
parent 7205d6692c
commit 8749d1fd93
7 changed files with 84 additions and 9 deletions
+6 -1
View File
@@ -22,7 +22,12 @@
#include "character_data.hpp"
CharacterData::CharacterData(): Entity("character") {
//EMPTY
SetBounds({
CHARACTER_BOUNDS_X,
CHARACTER_BOUNDS_Y,
CHARACTER_BOUNDS_WIDTH,
CHARACTER_BOUNDS_HEIGHT
});
}
int CharacterData::GetOwner() {
+2 -2
View File
@@ -28,7 +28,7 @@ BarrierData::BarrierData(int i):
Entity::Entity("barrier")
{
instanceIndex = i;
memcpy(status, 0, sizeof(int) * 8);
memset(status, 0, sizeof(int) * 8);
}
BarrierData::~BarrierData() {
@@ -38,7 +38,7 @@ BarrierData::~BarrierData() {
int BarrierData::Update(lua_State* L) {
int ret = 0;
if (scriptRef != 0) {
if (scriptRef != LUA_NOREF) {
//Call the script reference
lua_pushinteger(L, scriptRef);
lua_gettable(L, LUA_REGISTRYINDEX);
+6 -1
View File
@@ -29,7 +29,12 @@ CreatureData::CreatureData(std::string _avatar, int _scriptRef):
avatar(_avatar),
scriptRef(_scriptRef)
{
//EMPTY
SetBounds({
CREATURE_BOUNDS_X,
CREATURE_BOUNDS_Y,
CREATURE_BOUNDS_WIDTH,
CREATURE_BOUNDS_HEIGHT
});
}
int CreatureData::Update(lua_State* L) {
+1
View File
@@ -21,6 +21,7 @@
*/
#pragma once
#include "creature_defines.hpp"
#include "entity.hpp"
#include "lua.hpp"
+23 -4
View File
@@ -66,7 +66,28 @@ void RoomData::RunFrame() {
//Compare the triggers to the entities, using their real hitboxes
triggerMgr.Compare(entityStack);
//set the creature updates
//Creature/character collisions, O(m*n)
for (auto characterIt : characterList) {
BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin();
for (auto creatureIt : *creatureMgr.GetContainer()) {
BoundingBox creatureBox = creatureIt.second.GetBounds() + creatureIt.second.GetOrigin();
if (characterBox.CheckOverlap(creatureBox)) {
int barrierIndex = barrierMgr.Create(-1);
BarrierData* barrierData = barrierMgr.Find(barrierIndex);
barrierData->SetRoomIndex(roomIndex);
BarrierPacket barrierPacket;
barrierPacket.type = SerialPacketType::BARRIER_CREATE;
copyBarrierToPacket(&barrierPacket, barrierData, barrierIndex);
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&barrierPacket), roomIndex, characterIt->GetOrigin(), INFLUENCE_RADIUS);
}
}
}
//send the creature updates
for (auto& it : creatureList) {
CreaturePacket packet;
copyCreatureToPacket(&packet, it.second, it.first);
@@ -75,7 +96,7 @@ void RoomData::RunFrame() {
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
}
//send the updates
//send the barrier updates
for (auto& it : barrierList) {
BarrierPacket packet;
copyBarrierToPacket(&packet, it.second, it.first);
@@ -83,8 +104,6 @@ void RoomData::RunFrame() {
packet.roomIndex = roomIndex;
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
}
//TODO: (0) creature/character collisions
}
std::string RoomData::SetName(std::string s) {