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
-21
View File
@@ -62,24 +62,6 @@ function mapMaker.SmoothEdgesSimple(r)
end
end
function mapMaker.PlaceMonsterSpawn(r, x, y, script)
--place monster spawns here, highlighted by dirt patches
--wrong region
if x < Region.GetX(r) or x >= Region.GetX(r) + Region.GetWidth(r) or
y < Region.GetY(r) or y >= Region.GetY(r) + Region.GetHeight(r)
then
return
end
--place a dirt tile, clearing the above layers
Region.SetTile(r, x - Region.GetX(r), y - Region.GetY(r), 1, mapMaker.dirt)
Region.SetTile(r, x - Region.GetX(r), y - Region.GetY(r), 2, mapMaker.blank)
Region.SetTile(r, x - Region.GetX(r), y - Region.GetY(r), 3, mapMaker.blank)
--TODO: (1) create a monster spawn trigger using the given script
end
--custom generation systems here
function mapMaker.DebugIsland(r)
--basic distance check for each tile, placing an island around the world origin
@@ -109,9 +91,6 @@ function mapMaker.DebugIsland(r)
--A generic edge system
mapMaker.SmoothEdgesSimple(r)
--place monster spawns
mapMaker.PlaceMonsterSpawn(r, -5, -5, nil)
end
return mapMaker
+14
View File
@@ -2,6 +2,7 @@ print("Lua script check")
mapMaker = require("map_maker")
mapSaver = require("map_saver")
mapSystem = require("map_system")
roomSystem = require("room_system")
characterSystem = require("character_system")
networkSystem = require("network")
@@ -47,6 +48,17 @@ end)
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
--debug: test the trigger system
local pager = roomSystem.Room.GetPager(overworld)
mapSystem.RegionPager.SetTile(pager, 0, 0, 0, mapMaker.dirt)
local triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
--TODO: (1) What does the trigger script take as a parameter?
triggerSystem.TriggerManager.Create(triggerMgr, "dirt", 0, 0, 0, 0, 32, 32, function(character)
local x, y = characterSystem.Character.GetOrigin(character)
characterSystem.Character.SetOrigin(character, x, y + 128)
networkSystem.PumpCharacterUpdate(character)
end)
--debugging
function dumpTrigger(t)
local originX, originY = triggerSystem.Trigger.GetOrigin(t)
@@ -55,6 +67,7 @@ function dumpTrigger(t)
print(triggerSystem.Trigger.GetHandle(t), originX, originY, bx, by, bw, bh, s)
end
--[[
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
trigger2, uid2 = triggerSystem.TriggerManager.Create(triggerMgr, "handle2", 30.2, 40.2)
@@ -63,5 +76,6 @@ trigger3, uid3 = triggerSystem.TriggerManager.Create(triggerMgr, "handle3", 30.2
dumpTrigger(trigger1)
dumpTrigger(trigger2)
dumpTrigger(trigger3)
--]]
print("Finished the lua script")
+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
// }
// }
}
}
+1
View File
@@ -1,5 +1,6 @@
TODO: upgrade to lua 5.3
TODO: Split config.cfg in two, one for the server and the client
TODO: Consistency for bounds names
TODO: Account passwords (list)
* backbone account server OR