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:
@@ -62,24 +62,6 @@ function mapMaker.SmoothEdgesSimple(r)
|
|||||||
end
|
end
|
||||||
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
|
--custom generation systems here
|
||||||
function mapMaker.DebugIsland(r)
|
function mapMaker.DebugIsland(r)
|
||||||
--basic distance check for each tile, placing an island around the world origin
|
--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
|
--A generic edge system
|
||||||
mapMaker.SmoothEdgesSimple(r)
|
mapMaker.SmoothEdgesSimple(r)
|
||||||
|
|
||||||
--place monster spawns
|
|
||||||
mapMaker.PlaceMonsterSpawn(r, -5, -5, nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return mapMaker
|
return mapMaker
|
||||||
@@ -2,6 +2,7 @@ print("Lua script check")
|
|||||||
|
|
||||||
mapMaker = require("map_maker")
|
mapMaker = require("map_maker")
|
||||||
mapSaver = require("map_saver")
|
mapSaver = require("map_saver")
|
||||||
|
mapSystem = require("map_system")
|
||||||
roomSystem = require("room_system")
|
roomSystem = require("room_system")
|
||||||
characterSystem = require("character_system")
|
characterSystem = require("character_system")
|
||||||
networkSystem = require("network")
|
networkSystem = require("network")
|
||||||
@@ -47,6 +48,17 @@ end)
|
|||||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||||
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugIsland, mapSaver.Save)
|
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
|
--debugging
|
||||||
function dumpTrigger(t)
|
function dumpTrigger(t)
|
||||||
local originX, originY = triggerSystem.Trigger.GetOrigin(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)
|
print(triggerSystem.Trigger.GetHandle(t), originX, originY, bx, by, bw, bh, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
|
triggerMgr = roomSystem.Room.GetTriggerMgr(overworld)
|
||||||
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
trigger1, uid1 = triggerSystem.TriggerManager.Create(triggerMgr, "handle1")
|
||||||
trigger2, uid2 = triggerSystem.TriggerManager.Create(triggerMgr, "handle2", 30.2, 40.2)
|
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(trigger1)
|
||||||
dumpTrigger(trigger2)
|
dumpTrigger(trigger2)
|
||||||
dumpTrigger(trigger3)
|
dumpTrigger(trigger3)
|
||||||
|
--]]
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
|
||||||
|
void Entity::Update() {
|
||||||
|
origin += motion;
|
||||||
|
}
|
||||||
|
|
||||||
int Entity::SetRoomIndex(int i) {
|
int Entity::SetRoomIndex(int i) {
|
||||||
return roomIndex = i;
|
return roomIndex = i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
//The base class for all objects in the world
|
//The base class for all objects in the world
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
int SetRoomIndex(int i);
|
int SetRoomIndex(int i);
|
||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
|
|||||||
@@ -21,19 +21,56 @@
|
|||||||
*/
|
*/
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
void RoomData::RunFrame() {
|
void RoomData::RunFrame() {
|
||||||
//get the hook
|
//get the hook
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef);
|
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);
|
lua_pop(lua, 1);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//call the tick function, with this as a parameter
|
//update the entities in the room
|
||||||
lua_pushlightuserdata(lua, this);
|
for (auto& it : characterList) {
|
||||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
it->Update();
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
}
|
||||||
|
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,5 +1,6 @@
|
|||||||
TODO: upgrade to lua 5.3
|
TODO: upgrade to lua 5.3
|
||||||
TODO: Split config.cfg in two, one for the server and the client
|
TODO: Split config.cfg in two, one for the server and the client
|
||||||
|
TODO: Consistency for bounds names
|
||||||
|
|
||||||
TODO: Account passwords (list)
|
TODO: Account passwords (list)
|
||||||
* backbone account server OR
|
* backbone account server OR
|
||||||
|
|||||||
Reference in New Issue
Block a user