Triggers have a basic response to character collision

I've hacked the trigger system to create a really basic teleport pad,
using the dirt tile as an indicator. This behaviour is not coded into the
engine, but is in fact scripted in lua.

This commit is messy, due to lack of sleep.
This commit is contained in:
Kayne Ruse
2015-03-04 06:16:12 +11:00
parent 74ed93ddc7
commit 41d6314beb
6 changed files with 64 additions and 27 deletions
+4
View File
@@ -21,6 +21,10 @@
*/
#include "entity.hpp"
void Entity::Update() {
origin += motion;
}
int Entity::SetRoomIndex(int i) {
return roomIndex = i;
}
+2
View File
@@ -28,6 +28,8 @@
//The base class for all objects in the world
class Entity {
public:
virtual void Update();
//accessors & mutators
int SetRoomIndex(int i);
Vector2 SetOrigin(Vector2 v);
+43 -6
View File
@@ -21,19 +21,56 @@
*/
#include "room_data.hpp"
#include <iostream>
#include <stdexcept>
void RoomData::RunFrame() {
//get the hook
lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef);
if (lua_isnil(lua, -1)) {
if (!lua_isnil(lua, -1)) {
//call the tick function, with this as a parameter
lua_pushlightuserdata(lua, this);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
}
else {
lua_pop(lua, 1);
return;
}
//call the tick function, with this as a parameter
lua_pushlightuserdata(lua, this);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
//update the entities in the room
for (auto& it : characterList) {
it->Update();
}
for (auto& it : *monsterMgr.GetContainer()) {
it.second.Update();
}
//compare the triggers to the entities
for (auto& it : *triggerMgr.GetContainer()) {
for (auto& character : characterList) {
//positional boxes
BoundingBox hitBox = character->GetBounds() + character->GetOrigin();
BoundingBox itBox = it.second.GetBoundingBox() + it.second.GetOrigin();
if ( itBox.CheckOverlap(hitBox) ) {
//TODO: trigger script
lua_rawgeti(lua, LUA_REGISTRYINDEX, it.second.GetScriptReference());
lua_pushlightuserdata(lua, character);
//run the script
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
//error
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
}
}
// for (auto& monster : *monsterMgr.GetContainer()) {
// if (it.second.Compare(static_cast<Entity*>(&monster.second))) {
// //TODO: (1) trigger script
// }
// }
}
}