Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:prophile/xsera into interface
Browse files Browse the repository at this point in the history
  • Loading branch information
adam000 committed Mar 14, 2010
2 parents c6d1c87 + f7785ec commit 216d8ae
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
1 change: 1 addition & 0 deletions Engine/Sound/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static bool disable_music = false;

void Init ( int frequency, int resolution, int sources )
{
Mix_Init(MIX_INIT_MOD|MIX_INIT_OGG);
int volume_sound = MIX_MAX_VOLUME, volume_music = MIX_MAX_VOLUME;
Uint16 format;
switch (resolution)
Expand Down
53 changes: 39 additions & 14 deletions Resources/Scripts/Modes/Demo4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,36 @@ import('PrintRecursive')
import('KeyboardControl')
import('PilotAI')
import('Interfaces')
--[[
trackingTarget = {
position = vec(0,0);
velocity = vec(0,0);
mass = 1.0;
collision_radius = 1.0;
angle = 0.0;
angular_velocity = 0.0;
}]]

trackingTarget = {}
mdown = false
mrad = MOUSE_RADIUS / cameraRatio
aimMethod = "smart"

function init()
physics.open(0.6)
start_time = mode_manager.time()
last_time = mode_manager.time()

trackingTarget = physics.new_object(1.0)
trackingTarget.collision_radius = MOUSE_RADIUS

-- local tmp = physics.new_object(1.0)
-- physics.destroy_object(tmp)

-- trackingTarget.collision_radius = MOUSE_RADIUS

scen = LoadScenario(demoLevel)

selection.control = scen.playership
selection.target = nil
trackingTarget.position = GetMouseCoords()

-- trackingTarget.position = GetMouseCoords()
end

function key( k )
Expand Down Expand Up @@ -93,18 +105,20 @@ function update()
local cols = physics.collisions()

for idx, pair in pairs(cols) do
if pair[1] == 1 then
-- if pair[1] == 1 then
--[==[
if mdown == true then
if keyboard[2][5].active == true then
print("TARGET SELECT")
selection.target = scen.objects[pair[2]]
selection.target = scen.objects[pair[2] ]
else
print("CONTROL SELECT")
selection.control = scen.objects[pair[2]]
selection.control = scen.objects[pair[2] ]
end
mdown = false
end
else
--]==]
-- else
local a = scen.objects[pair[1]]
local b = scen.objects[pair[2]]

Expand All @@ -113,7 +127,7 @@ function update()
and a.ai.owner ~= b.ai.owner then
Collide(a,b)
end
end
-- end
end
mdown = false

Expand Down Expand Up @@ -295,7 +309,7 @@ function update()
RemoveDead()
TestConditions(scen)
GenerateStatusLines(scen)
trackingTarget.position = GetMouseCoords()
-- trackingTarget.position = GetMouseCoords()
physics.update(dt)
end

Expand Down Expand Up @@ -378,8 +392,6 @@ function render()

end

-- graphics.draw_circle(trackingTarget.position, trackingTarget.collision_radius, 1.0, ClutColour(5, 1))

graphics.draw_particles()

graphics.end_warp()
Expand All @@ -402,8 +414,21 @@ function mouse(button, x, y)
end
end

function mouseup()
function mouse_up()
mdown = false

local mousePos = GetMouseCoords()
for i, o in pairs(scen.objects) do
if find_hypot(o.physics.position, mousePos) <= o.physics.collision_radius + mrad == true then
if keyboard[2][5].active == true then
print("TARGET SELECT")
selection.target = scen.objects[i]
else
print("CONTROL SELECT")
selection.control = scen.objects[i]
end
end
end
end

function shutdown()
Expand Down
15 changes: 8 additions & 7 deletions Resources/Scripts/Modules/Actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ local new = NewObject(action["which-base-type"])

new.physics.position = srcMotion.position + offset

--[[BEG AQUIRE TARGET]]--
local targ = selection.target and selection.target.physics or {position=GetMouseCoords(),velocity=vec(0,0)}
--[[END AQUIRE TARGET]]--


if new.type == "beam"
and new.base.beam.kind ~= "kinetic" then
Expand All @@ -146,15 +150,14 @@ and new.base.beam.kind ~= "kinetic" then

if new.base.beam.kind == "bolt-relative"
or new.base.beam.kind == "static-relative" then
-- local offset = VecSub(trackingTarget.position, new.src.position)
local len = math.min(new.base.beam.range, find_hypot(new.gfx.source.position, trackingTarget.position))
local dir = NormalizeVec(trackingTarget.position - new.physics.position)
local len = math.min(new.base.beam.range, find_hypot(new.gfx.source.position, targ.position))
local dir = NormalizeVec(targ.position - new.physics.position)

new.gfx.relative = dir * len
new.physics.position = new.physics.position + new.gfx.relative
else

new.gfx.target = trackingTarget
new.gfx.target = targ

local len = math.min(new.base.beam.range,find_hypot(new.physics.position,new.gfx.target.position))
local dir = NormalizeVec(new.target.position - new.gfx.source.position)
Expand All @@ -166,9 +169,7 @@ end


if source.base.attributes["auto-target"] == true then
--[[BEG AQUIRE TARGET]]--
local targ = selection.target and selection.target.physics or trackingTarget
--[[END AQUIRE TARGET]]--

if aimMethod == "smart" then
local vel = (new.base["initial-velocity"] or 0) * SPEED_FACTOR
new.physics.angle = AimAhead(srcMotion, targ, vel)
Expand Down
6 changes: 3 additions & 3 deletions Resources/Scripts/Modules/Conditions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end;
["current-computer-condition"] = function(cond) end;
["current-message-condition"] = function(cond) end;
["destruction-condition"] = function(cond)
if scen.objects[cond.value + 2] == nil then
if scen.objects[cond.value + 1] == nil then
return true
else
return false
Expand All @@ -47,7 +47,7 @@ end;
["direct-is-subject-target-condition"] = function(cond) end;
["distance-greater-condition"] = function(cond) end;
["half-health-condition"] = function(cond)
local objectStatus = scen.objects[cond["subject-object"]+2].status
local objectStatus = scen.objects[cond["subject-object"]+1].status
if objectStatus.health * 2 <= objectStatus.healthMax then
return true
else
Expand All @@ -70,7 +70,7 @@ end;
["object-is-being-built-condition"] = function(cond) end;
["owner-condition"] = function(cond)
local player = cond.value
local object = scen.objects[cond["subject-object"] + 2]
local object = scen.objects[cond["subject-object"] + 1]
if object.ai.owner == player then
return true
else
Expand Down
8 changes: 4 additions & 4 deletions Resources/Scripts/Modules/Interfaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ end

function GetMouseCoords()
local x, y = mouse_position()
return {
x = scen.playerShip.physics.position.x -shipAdjust + camera.w * x - camera.w / 2;
y = scen.playerShip.physics.position.y + camera.h * y - camera.h / 2;
}
return vec(
scen.playerShip.physics.position.x -shipAdjust + camera.w * x - camera.w / 2,
scen.playerShip.physics.position.y + camera.h * y - camera.h / 2
)
end

local realPos = { x, y }
Expand Down
6 changes: 2 additions & 4 deletions Resources/Scripts/Modules/Scenarios.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ function LoadScenario(id)
end

if state["initial-destination"] ~= -1 then
--Convert from 0 based indexes to 2 based indexes
--Indexes are 2 based instead of 1 based because the cursor has a physics_object with an id of 1

new.ai.objectives.dest = scen.objects[state["initial-destination"]+2]
--Convert from 0 based indexes to 1 based indexes
new.ai.objectives.dest = scen.objects[state["initial-destination"]+1]
end

scen.objects[new.physics.object_id] = new
Expand Down

0 comments on commit 216d8ae

Please sign in to comment.