Barriers are queried, created when colliding with creatures
This commit is contained in:
@@ -722,6 +722,11 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
|
||||
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
|
||||
creaturePacket.roomIndex = roomIndex;
|
||||
network.SendTo(Channels::SERVER, &creaturePacket);
|
||||
|
||||
BarrierPacket barrierPacket;
|
||||
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
|
||||
barrierPacket.roomIndex = roomIndex;
|
||||
network.SendTo(Channels::SERVER, &barrierPacket);
|
||||
}
|
||||
|
||||
//debug
|
||||
@@ -743,9 +748,10 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
|
||||
camera.marginX = 0;
|
||||
camera.marginY = 0;
|
||||
|
||||
//clear the room
|
||||
//clear/reset the room
|
||||
roomIndex = -1;
|
||||
regionPager.UnloadAll();
|
||||
barrierMap.clear();
|
||||
characterMap.clear();
|
||||
creatureMap.clear();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
//the speeds that the characters move
|
||||
constexpr double CREATURE_WALKING_SPEED = 1.0;
|
||||
constexpr double CREATURE_WALKING_MOD = 1.0/sqrt(2.0);
|
||||
constexpr double CREATURE_WALKING_NEGATIVE_MOD = 1.0 - CREATURE_WALKING_MOD;
|
||||
|
||||
//the bounds for the character objects, mapped to the default sprites
|
||||
constexpr int CREATURE_BOUNDS_X = 0;
|
||||
constexpr int CREATURE_BOUNDS_Y = 0;
|
||||
constexpr int CREATURE_BOUNDS_WIDTH = 32;
|
||||
constexpr int CREATURE_BOUNDS_HEIGHT = 32;
|
||||
|
||||
//the character's sprite format
|
||||
constexpr int CREATURE_CELLS_X = 4;
|
||||
constexpr int CREATURE_CELLS_Y = 4;
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "creature_defines.hpp"
|
||||
#include "entity.hpp"
|
||||
|
||||
#include "lua.hpp"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user