From cefcb3889bb6d86dfa1f9fef03c44c1c5033567d Mon Sep 17 00:00:00 2001 From: Ethan Adams Date: Sun, 23 Jun 2024 14:21:52 -0400 Subject: [PATCH] Added weapon scripting system, added shotgun as example. --- Resources/scenes/debugScene.xml | 2 +- Resources/scripts/shotgun_script.lua | 17 ++++++ Resources/weapons/bubblegun.xml | 15 +++++ YuppleMayham/include/gameplay/scene.h | 6 +- .../include/gameplay/weapons/weapon.h | 23 ++++++-- .../include/utility/resourcemanager.h | 12 ++-- YuppleMayham/include/utility/script.h | 11 +++- YuppleMayham/include/utility/xmlloader.h | 1 + YuppleMayham/src/gameplay/scene.cpp | 24 +++++++- .../src/gameplay/weapons/bulletmanager.cpp | 4 +- YuppleMayham/src/gameplay/weapons/weapon.cpp | 51 ++++++++++++++--- YuppleMayham/src/utility/resourcemanager.cpp | 13 ++++- YuppleMayham/src/utility/script.cpp | 56 ++++++++++++++----- YuppleMayham/src/utility/xmlloader.cpp | 9 ++- 14 files changed, 200 insertions(+), 44 deletions(-) create mode 100644 Resources/scripts/shotgun_script.lua diff --git a/Resources/scenes/debugScene.xml b/Resources/scenes/debugScene.xml index af91548..456c249 100644 --- a/Resources/scenes/debugScene.xml +++ b/Resources/scenes/debugScene.xml @@ -34,7 +34,7 @@ - + diff --git a/Resources/scripts/shotgun_script.lua b/Resources/scripts/shotgun_script.lua new file mode 100644 index 0000000..4c8e4b6 --- /dev/null +++ b/Resources/scripts/shotgun_script.lua @@ -0,0 +1,17 @@ +-- How bullets are produced make sure to generate bullet data, then pass it through createBullet +function onShoot() + rot = weapon.wielder.rotation + data = weapon:genBulletData() + for i=1, 10 do + spread = math.random(-20, 20) + print("direction x: "..data.direction.x.." y: "..data.direction.y); + data.direction.x = math.cos(math.rad(rot + spread)) + data.direction.y = math.sin(math.rad(rot + spread)) + weapon:createBullet(data) + end +end + +-- How the bulllet, target or wielder respond when the bullet hits a target. +function onHit(target) + +end diff --git a/Resources/weapons/bubblegun.xml b/Resources/weapons/bubblegun.xml index 0d3163c..96ab369 100644 --- a/Resources/weapons/bubblegun.xml +++ b/Resources/weapons/bubblegun.xml @@ -11,6 +11,21 @@ + +