Skip to content

Commit

Permalink
Fix artifact pickups and player collision callbacks. Fix setting rada…
Browse files Browse the repository at this point in the history
…r trace icon and color.
  • Loading branch information
daid committed Feb 23, 2025
1 parent 06db87f commit 788b323
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
43 changes: 24 additions & 19 deletions scripts/api/entity/artifact.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ function Artifact()
e.components.transform = {rotation=random(0, 360)}

local model_number = irandom(1, 8)
e.components.mesh_render = {
mesh="mesh/Artifact" .. model_number .. ".obj",
texture="texture/electric_sphere_texture.png",
scale=3.0,
}
e.components.radar_trace = {
icon="radar/blip.png",
radius=120.0,
rotate=false,
e.components = {
mesh_render = {
mesh="mesh/Artifact" .. model_number .. ".obj",
texture="texture/electric_sphere_texture.png",
scale=3.0,
},
radar_trace = {
icon="radar/blip.png",
radius=120.0,
rotate=false,
},
physics = {
type="sensor", size=100
},
}
return e
end
Expand Down Expand Up @@ -59,14 +64,14 @@ end
--- Passes the artifact and colliding SpaceObject to the called function.
--- Example: artifact:onCollision(function(artifact, collider) print("Collision occurred") end)
function Entity:onCollision(callback)
self.components.collision_callback = {player=false, callback}
self.components.collision_callback = {player=false, callback=callback}
return self
end
--- Defines a function to call every tick when a PlayerSpaceship is colliding with the artifact.
--- Passes the artifact and colliding PlayerSpaceship to the called function.
--- Example: artifact:onCollision(function(artifact, player) print("Collision occurred") end)
function Entity:onPlayerCollision(callback)
self.components.collision_callback = {player=true, callback}
self.components.collision_callback = {player=true, callback=callback}
return self
end
--- Defines a function to call once when a PlayerSpaceship collides with the artifact and allowPickup is enabled.
Expand All @@ -88,9 +93,9 @@ end
--- Example: artifact:setSpin(0.5)
function Entity:setSpin(spin)
if spin ~= 0.0 then
self.spin = {rate=spin}
self.components.spin = {rate=spin}
else
self.spin = nil
self.components.spin = nil
end
return self
end
Expand All @@ -99,26 +104,26 @@ end
--- Valid values are filenames to PNG files relative to resources/radar/.
--- Example: artifact:setRadarTraceIcon("arrow.png") -- displays an arrow instead of a blip for this artifact
function Entity:setRadarTraceIcon(icon)
if self.radar_trace then self.radar_trace.icon = "radar/" .. icon end
if self.components.radar_trace then self.components.radar_trace.icon = "radar/" .. icon end
return self
end
--- Scales the radar trace for this artifact.
--- A value of 0 restores standard autoscaling relative to the artifact's radius.
--- Set to 1 to mimic ship traces.
--- Example: artifact:setRadarTraceScale(0.7)
function Entity:setRadarTraceScale(scale)
if self.radar_trace then
self.radar_trace.min_size = scale * 32
self.radar_trace.max_size = scale * 32
if self.components.radar_trace then
self.components.radar_trace.min_size = scale * 32
self.components.radar_trace.max_size = scale * 32
end
return self
end
--- Sets the color of this artifact's radar trace.
--- Optional. Defaults to solid white (255,255,255)
--- Example: artifact:setRadarTraceColor(255,200,100) -- mimics an asteroid
function Entity:setRadarTraceColor(r, g, b)
if self.radar_trace then
self.radar_trace.color = {r, g, b}
if self.components.radar_trace then
self.components.radar_trace.color = {r, g, b, 255}
end
return self
end
4 changes: 2 additions & 2 deletions scripts/api/entity/spaceship.lua
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ end
--- Example: ship:setBeamWeaponArcColor(0,0,128,0,0,255,0) -- makes beam 0's arc green
function Entity:setBeamWeaponArcColor(index, idle_r, idle_g, idle_b, fire_r, fire_g, fire_b)
if self.components.beam_weapons == nil or #self.components.beam_weapons <= index then return self end
self.components.beam_weapons[index + 1].arc_color = {idle_r, idle_g, idle_b}
self.components.beam_weapons[index + 1].arc_color_fire = {fire_r, fire_g, fire_b}
self.components.beam_weapons[index + 1].arc_color = {idle_r, idle_g, idle_b, 255}
self.components.beam_weapons[index + 1].arc_color_fire = {fire_r, fire_g, fire_b, 255}
return self
end
--- Sets the damage type dealt by the BeamWeapon with the given index on this SpaceShip.
Expand Down
2 changes: 2 additions & 0 deletions src/init/ecs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "systems/radarblock.h"
#include "systems/zone.h"
#include "systems/player.h"
#include "systems/pickup.h"


void initSystemsAndComponents()
Expand Down Expand Up @@ -155,5 +156,6 @@ void initSystemsAndComponents()
engine->registerSystem<RadarBlockSystem>();
engine->registerSystem<ZoneSystem>();
engine->registerSystem<PlayerRadarRender>();
engine->registerSystem<PickupSystem>();
initComponentScriptBindings();
}
1 change: 1 addition & 0 deletions src/systems/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

void PickupSystem::update(float delta)
{
sp::CollisionSystem::addHandler(this);
}

void PickupSystem::collision(sp::ecs::Entity a, sp::ecs::Entity b, float force)
Expand Down

0 comments on commit 788b323

Please sign in to comment.