forked from Mirrors/openclonk
grab ladder while in wall jump
parent
a9f93378fa
commit
69de4e72fd
|
@ -92,8 +92,8 @@ func UpdateLines()
|
|||
{
|
||||
angle = Angle(particles[2][0][0], particles[2][0][1], particles[0][0][0], particles[0][0][1]);
|
||||
end = particles[0][0][:];
|
||||
end[0] += -Sin(angle, 45*Rope_Precision/10);
|
||||
end[1] += +Cos(angle, 45*Rope_Precision/10);
|
||||
end[0] += -Sin(angle, 45*LIB_ROPE_Precision/10);
|
||||
end[1] += +Cos(angle, 45*LIB_ROPE_Precision/10);
|
||||
segments[i]->SetGraphics("Invis");
|
||||
}
|
||||
|
||||
|
@ -101,21 +101,21 @@ func UpdateLines()
|
|||
{
|
||||
angle = Angle(particles[2][0][0], particles[2][0][1], particles[0][0][0], particles[0][0][1]);
|
||||
start = particles[0][0][:];
|
||||
start[0] += -Sin(angle, 45*Rope_Precision/10);
|
||||
start[1] += +Cos(angle, 45*Rope_Precision/10);
|
||||
start[0] += -Sin(angle, 45*LIB_ROPE_Precision/10);
|
||||
start[1] += +Cos(angle, 45*LIB_ROPE_Precision/10);
|
||||
segments[i]->SetGraphics("Short");
|
||||
}
|
||||
|
||||
var diff = Vec_Sub(end,start);
|
||||
var point = Vec_Add(start, Vec_Div(diff, 2));
|
||||
var diffangle = Vec_Angle(diff, [0,0]);
|
||||
var length = Vec_Length(diff)*1000/Rope_Precision/10;
|
||||
var length = Vec_Length(diff)*1000/LIB_ROPE_Precision/10;
|
||||
|
||||
if(i == ParticleCount-1)
|
||||
{
|
||||
var old = particles[i-2][0][:];
|
||||
var old_diff = Vec_Sub(start,old);
|
||||
var o_length = Vec_Length(old_diff)*1000/Rope_Precision/10;
|
||||
var o_length = Vec_Length(old_diff)*1000/LIB_ROPE_Precision/10;
|
||||
if(!o_length) diff = old_diff;
|
||||
else diff = Vec_Div(Vec_Mul(old_diff, length),o_length);
|
||||
diffangle = Vec_Angle(diff, [0,0]);
|
||||
|
@ -215,8 +215,8 @@ func ForcesOnObjects()
|
|||
}
|
||||
pull_frame = FrameCounter();
|
||||
|
||||
obj->SetXDir( xdir, Rope_Precision);
|
||||
obj->SetYDir( obj->GetYDir(Rope_Precision) + ydir, Rope_Precision);
|
||||
obj->SetXDir( xdir, LIB_ROPE_Precision);
|
||||
obj->SetYDir( obj->GetYDir(LIB_ROPE_Precision) + ydir, LIB_ROPE_Precision);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ public func FxIntGrappleControlTimer(object target, fxnum, int time)
|
|||
var off = rope->GetClonkOff();
|
||||
// off = [0,0];
|
||||
//var pos = rope->GetClonkPos();
|
||||
//target->SetPosition(pos[0], pos[1], nil, Rope_Precision);
|
||||
//target->SetPosition(pos[0], pos[1], nil, LIB_ROPE_Precision);
|
||||
target.MyAngle = angle;
|
||||
//angle = 0;
|
||||
target->SetMeshTransformation(Trans_Translate(-off[0]*10+3000*(1-2*target->GetDir()),-off[1]*10), 2);
|
||||
|
|
|
@ -150,7 +150,7 @@ func AdjustClonkMovement()
|
|||
if(clonk->Contained()) clonk = clonk->Contained();
|
||||
|
||||
var rope_vector = Vec_Sub(particles[-1][0], particles[-2][0]);
|
||||
var clonk_speed = [clonk->GetXDir(Rope_Precision), clonk->GetYDir(Rope_Precision)];
|
||||
var clonk_speed = [clonk->GetXDir(LIB_ROPE_Precision), clonk->GetYDir(LIB_ROPE_Precision)];
|
||||
|
||||
|
||||
var rope_orthogonal = [rope_vector[1], -rope_vector[0]];
|
||||
|
@ -158,8 +158,8 @@ func AdjustClonkMovement()
|
|||
|
||||
var clonk_newspeed = Vec_Normalize(rope_orthogonal, new_speed);
|
||||
|
||||
clonk->SetXDir(clonk_newspeed[0], Rope_Precision);
|
||||
clonk->SetYDir(clonk_newspeed[1], Rope_Precision);
|
||||
clonk->SetXDir(clonk_newspeed[0], LIB_ROPE_Precision);
|
||||
clonk->SetYDir(clonk_newspeed[1], LIB_ROPE_Precision);
|
||||
}
|
||||
|
||||
local last_point;
|
||||
|
@ -183,28 +183,28 @@ func UpdateLines()
|
|||
{
|
||||
angle = Angle(particles[2][0][0], particles[2][0][1], particles[0][0][0], particles[0][0][1]);
|
||||
end = particles[0][0][:];
|
||||
end[0] += -Sin(angle, 45*Rope_Precision/10);
|
||||
end[1] += +Cos(angle, 45*Rope_Precision/10);
|
||||
end[0] += -Sin(angle, 45*LIB_ROPE_Precision/10);
|
||||
end[1] += +Cos(angle, 45*LIB_ROPE_Precision/10);
|
||||
}
|
||||
|
||||
if(i == 2)
|
||||
{
|
||||
angle = Angle(particles[2][0][0], particles[2][0][1], particles[0][0][0], particles[0][0][1]);
|
||||
start = particles[0][0][:];
|
||||
start[0] += -Sin(angle, 45*Rope_Precision/10);
|
||||
start[1] += +Cos(angle, 45*Rope_Precision/10);
|
||||
start[0] += -Sin(angle, 45*LIB_ROPE_Precision/10);
|
||||
start[1] += +Cos(angle, 45*LIB_ROPE_Precision/10);
|
||||
}
|
||||
|
||||
var diff = Vec_Sub(end,start);
|
||||
var point = Vec_Add(start, Vec_Div(diff, 2));
|
||||
var diffangle = Vec_Angle(diff, [0,0]);
|
||||
var length = Vec_Length(diff)*1000/Rope_Precision/10;
|
||||
var length = Vec_Length(diff)*1000/LIB_ROPE_Precision/10;
|
||||
|
||||
if(i == ParticleCount-1)
|
||||
{
|
||||
var old = particles[i-2][0][:];
|
||||
var old_diff = Vec_Sub(start,old);
|
||||
var o_length = Vec_Length(old_diff)*1000/Rope_Precision/10;
|
||||
var o_length = Vec_Length(old_diff)*1000/LIB_ROPE_Precision/10;
|
||||
if(!o_length) diff = old_diff;
|
||||
else diff = Vec_Div(Vec_Mul(old_diff, length),o_length);
|
||||
// objects[1][0]->Message("%d", Vec_Length(diff)*1000/Rope_Precision/10);
|
||||
|
@ -218,8 +218,8 @@ func UpdateLines()
|
|||
{
|
||||
segments[i]->SetGraphics(nil, GrappleHook);
|
||||
segments[i].MeshTransformation = Trans_Mul(Trans_Translate(1500,0,0),Trans_Scale(1500));
|
||||
point[0] += -Cos(diffangle, 15*Rope_Precision/10)+Sin(diffangle, 4*Rope_Precision);
|
||||
point[1] += -Cos(diffangle, 4*Rope_Precision)-Sin(diffangle, 15*Rope_Precision/10);
|
||||
point[0] += -Cos(diffangle, 15*LIB_ROPE_Precision/10)+Sin(diffangle, 4*LIB_ROPE_Precision);
|
||||
point[1] += -Cos(diffangle, 4*LIB_ROPE_Precision)-Sin(diffangle, 15*LIB_ROPE_Precision/10);
|
||||
length = 1000;
|
||||
}
|
||||
|
||||
|
@ -298,8 +298,8 @@ func ForcesOnObjects()
|
|||
var xdir = BoundBy(particles[j][0][0]-particles[j][1][0], -300, 300);
|
||||
var ydir = BoundBy(particles[j][0][1]-particles[j][1][1], -300, 300);
|
||||
|
||||
obj->SetXDir( xdir, Rope_Precision);
|
||||
obj->SetYDir( ydir, Rope_Precision);
|
||||
obj->SetXDir( xdir, LIB_ROPE_Precision);
|
||||
obj->SetYDir( ydir, LIB_ROPE_Precision);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
Ropebridge
|
||||
Author: Randrian
|
||||
|
||||
|
@ -8,10 +8,10 @@
|
|||
|
||||
#include Library_Rope
|
||||
|
||||
static const Ladder_MaxParticles = 15;//30;//15*3;
|
||||
static const Ladder_MaxParticles = 15;
|
||||
static const Ladder_Iterations = 10;
|
||||
static const Ladder_Precision = 100;
|
||||
static const Ladder_SegmentLength = 5;//2;
|
||||
static const Ladder_SegmentLength = 5;
|
||||
|
||||
local particles;
|
||||
local segments;
|
||||
|
@ -22,41 +22,42 @@ local ParticleCount;
|
|||
|
||||
public func UpdateSegmentOverlays()
|
||||
{
|
||||
for(var i = 1; i < GetLength(segments); i++)
|
||||
for (var i = 1; i < GetLength(segments); i++)
|
||||
{
|
||||
segments[i]->CreateDouble();
|
||||
segments[i]->CreateDouble();
|
||||
segments[i]->SetGraphics("Line", GetID(), 2, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 3, 1);
|
||||
segments[i].Double->SetGraphics("Line", GetID(), 4, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 5, 1);
|
||||
if(i>1)
|
||||
{
|
||||
segments[i].Double->SetGraphics("Line", GetID(), 7, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 8, 1);
|
||||
}
|
||||
segments[i]->SetSolidMask(6,0,7,3,-5,9);
|
||||
segments[i].Double->SetGraphics("Line", GetID(), 4, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 5, 1);
|
||||
if (i > 1)
|
||||
{
|
||||
segments[i].Double->SetGraphics("Line", GetID(), 7, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 8, 1);
|
||||
}
|
||||
segments[i]->SetSolidMask(6,0,7,3,-5,9);
|
||||
if(i > 1 && i < GetLength(segments)-1)
|
||||
{
|
||||
segments[i].Plank = 1;
|
||||
{
|
||||
segments[i].Plank = 1;
|
||||
segments[i]->SetGraphics("Segment", GetID(), 6, 1);
|
||||
segments[i]->SetClrModulation(HSL(255,0,128+Random(128)), 6);
|
||||
}
|
||||
if(i%2 == 0)
|
||||
{
|
||||
var color = RGB(200,200,200);
|
||||
segments[i]->SetClrModulation(color, 2);
|
||||
segments[i]->SetClrModulation(color, 3);
|
||||
segments[i].Double->SetClrModulation(color, 4);
|
||||
segments[i]->SetClrModulation(color, 5);
|
||||
segments[i].Double->SetClrModulation(color, 7);
|
||||
segments[i]->SetClrModulation(color, 8);
|
||||
}
|
||||
segments[i]->SetClrModulation(HSL(255,0,128+Random(128)), 6);
|
||||
}
|
||||
if(i % 2 == 0)
|
||||
{
|
||||
var color = RGB(200,200,200);
|
||||
segments[i]->SetClrModulation(color, 2);
|
||||
segments[i]->SetClrModulation(color, 3);
|
||||
segments[i].Double->SetClrModulation(color, 4);
|
||||
segments[i]->SetClrModulation(color, 5);
|
||||
segments[i].Double->SetClrModulation(color, 7);
|
||||
segments[i]->SetClrModulation(color, 8);
|
||||
}
|
||||
}
|
||||
segments[0]->CreateDouble();
|
||||
segments[-1]->CreateDouble();
|
||||
segments[-1]->CreateDouble();
|
||||
segments[1]->SetSolidMask();
|
||||
segments[-1]->SetSolidMask();
|
||||
segments[1]->SetGraphics(nil, nil,6);
|
||||
segments[-1]->SetSolidMask();
|
||||
segments[1]->SetGraphics(nil, nil,6);
|
||||
return;
|
||||
}
|
||||
|
||||
public func MakeBridge(obj1, obj2)
|
||||
|
@ -153,9 +154,9 @@ func UpdateLines()
|
|||
for(var i=1; i < ParticleCount; i++)
|
||||
{
|
||||
// Update the Position of the Segment
|
||||
segments[i]->SetPosition(particles[i][0][0], particles[i][0][1], 0, Rope_Precision);
|
||||
segments[i]->SetPosition(particles[i][0][0], particles[i][0][1], 0, LIB_ROPE_Precision);
|
||||
if(segments[i].Double)
|
||||
segments[i].Double->SetPosition(particles[i][0][0], particles[i][0][1], 0, Rope_Precision);
|
||||
segments[i].Double->SetPosition(particles[i][0][0], particles[i][0][1], 0, LIB_ROPE_Precision);
|
||||
|
||||
// Calculate the angle to the previous segment
|
||||
var angle;
|
||||
|
@ -170,29 +171,29 @@ func UpdateLines()
|
|||
|
||||
segments[i]->SetR(90+angle);
|
||||
// Draw the left line
|
||||
var start = GetRopeConnetPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 0, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 0, 1, angle, oldangle);
|
||||
var end1 = start;
|
||||
DrawRopeLine(start, end, i, 2);
|
||||
if(segments[i].Plank)
|
||||
DrawRopeLine2(start, end, i, 6);
|
||||
|
||||
// Draw the right line
|
||||
var start = GetRopeConnetPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 1, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 1, 1, angle, oldangle);
|
||||
var end2 = start;
|
||||
DrawRopeLine(start, end, i, 3);
|
||||
|
||||
// Draw the upper left line
|
||||
var start = GetRopeConnetPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 0, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 0, 1, angle, oldangle);
|
||||
var end3 = start[:];
|
||||
start[1]-=800;end[1]-=800;
|
||||
DrawRopeLine(start, end, i, 4);
|
||||
|
||||
// Draw the upder right line
|
||||
var start = GetRopeConnetPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 1, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 1, 1, angle, oldangle);
|
||||
var end4 = start[:];
|
||||
start[1]-=800;end[1]-=800;
|
||||
DrawRopeLine(start, end, i, 5);
|
||||
|
@ -228,7 +229,7 @@ static const Ropebridge_Anchor_RightYOffset = 0;
|
|||
static const Ropebridge_Anchor_LeftXOffset = -150;
|
||||
static const Ropebridge_Anchor_LeftYOffset = -100;
|
||||
|
||||
func GetRopeConnetPosition(int index, bool fRight, bool fEnd, int angle, int oldangle)
|
||||
func GetRopeConnectPosition(int index, bool fRight, bool fEnd, int angle, int oldangle)
|
||||
{
|
||||
var SegmentOffset = [[Ropebridge_Segment_LeftXOffset, Ropebridge_Segment_LeftYOffset],
|
||||
[Ropebridge_Segment_RightXOffset, Ropebridge_Segment_RightYOffset]];
|
||||
|
|
|
@ -25,7 +25,7 @@ local TestArray;
|
|||
|
||||
local MaxSegmentCount;
|
||||
|
||||
local SwitchRopes;
|
||||
local switch_ropes;
|
||||
local MirrorSegments;
|
||||
|
||||
local UnrollDir;
|
||||
|
@ -43,10 +43,10 @@ public func ControlUse(object clonk, int x, int y)
|
|||
{
|
||||
// Unroll dir
|
||||
var dir = -1;
|
||||
if(x > 0) dir = 1;
|
||||
if (x > 0) dir = 1;
|
||||
if(clonk->GetAction() == "Scale")
|
||||
{
|
||||
if(clonk->GetDir() == 0)
|
||||
if (clonk->GetDir() == 0)
|
||||
{
|
||||
Exit(0, 8);
|
||||
Unroll(1, COMD_Right);
|
||||
|
@ -67,23 +67,22 @@ public func ControlUse(object clonk, int x, int y)
|
|||
Exit(0, 5);
|
||||
Unroll(dir, COMD_Down);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public func UpdateSegmentOverlays()
|
||||
{
|
||||
for(var i = 1; i < GetLength(segments); i++)
|
||||
for (var i = 1; i < GetLength(segments); i++)
|
||||
{
|
||||
segments[i]->SetGraphics("Line", GetID(), 2, 1);
|
||||
segments[i]->SetGraphics("Line", GetID(), 3, 1);
|
||||
segments[i]->SetGraphics(nil, nil, 4);
|
||||
segments[i]->SetGraphics(nil, nil, 5);
|
||||
if(i > 1)
|
||||
if (i > 1)
|
||||
segments[i]->SetGraphics("NoRope", segments[i]->GetID(), 4, 1);
|
||||
if(i == GetLength(segments)-1)
|
||||
if (i == GetLength(segments)-1)
|
||||
segments[i]->SetGraphics("NoRope", segments[i]->GetID(), 5, 1);
|
||||
if(i == 1)
|
||||
if (i == 1)
|
||||
{
|
||||
segments[i]->SetGraphics("Anchor", GetID(), 1, 1);
|
||||
segments[i]->SetGraphics("AnchorOverlay", GetID(), 5, 1);
|
||||
|
@ -91,27 +90,29 @@ public func UpdateSegmentOverlays()
|
|||
}
|
||||
}
|
||||
|
||||
func TestMoveOut(xdir, ydir)
|
||||
public func TestMoveOut(int xdir, int ydir)
|
||||
{
|
||||
if(!Stuck()) return;
|
||||
for(var i = 0; i < 8; i++)
|
||||
if (!Stuck())
|
||||
return;
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if(!GBackSolid(i*xdir, i*ydir))
|
||||
if (!GBackSolid(i * xdir, i * ydir))
|
||||
{
|
||||
SetPosition(GetX()+i*xdir, GetY()+i*ydir);
|
||||
if(!Stuck())
|
||||
SetPosition(GetX() + i * xdir, GetY() + i * ydir);
|
||||
if (!Stuck())
|
||||
break;
|
||||
SetPosition(GetX()-i*xdir, GetY()-i*ydir);
|
||||
SetPosition(GetX() - i * xdir, GetY() - i * ydir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func Unroll(int dir, int unrolldir, int length)
|
||||
{
|
||||
if(!unrolldir) unrolldir = COMD_Down;
|
||||
SwitchRopes = 0;
|
||||
if (!unrolldir)
|
||||
unrolldir = COMD_Down;
|
||||
switch_ropes = false;
|
||||
// Unroll dir
|
||||
if(unrolldir == COMD_Left || unrolldir == COMD_Right)
|
||||
if (unrolldir == COMD_Left || unrolldir == COMD_Right)
|
||||
{
|
||||
var xdir = 1;
|
||||
if(unrolldir == COMD_Right)
|
||||
|
@ -143,7 +144,7 @@ public func Unroll(int dir, int unrolldir, int length)
|
|||
|
||||
SetPosition(GetX(), GetY()+y0+2);
|
||||
SetR(-90+Angle(x2, y2, x1, y1));
|
||||
SwitchRopes = 1;
|
||||
switch_ropes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -168,14 +169,6 @@ public func Unroll(int dir, int unrolldir, int length)
|
|||
DoUnroll(dir);
|
||||
}
|
||||
|
||||
public func MakeBridge(obj1, obj2)
|
||||
{
|
||||
MirrorSegments = 1;
|
||||
SetProperty("Collectible", 0);
|
||||
StartRopeConnect(obj1, obj2);
|
||||
AddEffect("IntHang", this, 1, 1, this);
|
||||
}//MakeBridge(Object(221), Object(150))
|
||||
|
||||
protected func DoUnroll(dir)
|
||||
{
|
||||
MirrorSegments = dir;
|
||||
|
@ -183,8 +176,6 @@ protected func DoUnroll(dir)
|
|||
SetAction("Hanging");
|
||||
SetProperty("Collectible", 0);
|
||||
|
||||
// TestArray = [[0, 1], [1, 0], [1, 1], [0, 2], [1, 2], [2, 0], [2, 1], [2, 2], [0, 3], [1, 3], [2, 3], [3, 0], [3, 1], [3, 2], [0, 4], [1, 4], [2, 4], [3, 3], [4, 0], [4, 1], [4, 2], [0, 5], [1, 5], [2, 5], [3, 4], [3, 5], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [0, 6], [1, 6], [2, 6], [3, 6], [4, 5], [5, 4], [6, 0], [6, 1], [6, 2], [6, 3], [0, 7], [1, 7], [2, 7], [3, 7], [4, 6], [5, 5], [5, 6], [6, 4], [6, 5], [7, 0], [7, 1], [7, 2], [7, 3], [0, 8], [1, 8], [2, 8], [3, 8], [4, 7], [4, 8], [5, 7], [6, 6], [7, 4], [7, 5], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 8], [6, 7], [7, 6], [7, 7], [8, 5], [9, 0], [9, 1], [9, 2], [9, 3], [9, 4]];
|
||||
|
||||
grabber = CreateObjectAbove(Ropeladder_Grabber);
|
||||
grabber->SetAction("Attach", this);
|
||||
|
||||
|
@ -313,8 +304,8 @@ func UpdateLines()
|
|||
}
|
||||
|
||||
// Draw the left line
|
||||
var start = GetRopeConnetPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 0, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 0, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 0, 1, angle, oldangle);
|
||||
|
||||
var diff = Vec_Sub(end,start);
|
||||
var diffangle = Vec_Angle(diff, [0,0]);
|
||||
|
@ -324,8 +315,8 @@ func UpdateLines()
|
|||
SetLineTransform(segments[i], -diffangle, point[0]*10-GetPartX(i)*1000,point[1]*10-GetPartY(i)*1000, length, 2 );
|
||||
|
||||
// Draw the right line
|
||||
var start = GetRopeConnetPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnetPosition(i, 1, 1, angle, oldangle);
|
||||
var start = GetRopeConnectPosition(i, 1, 0, angle, oldangle);
|
||||
var end = GetRopeConnectPosition(i, 1, 1, angle, oldangle);
|
||||
|
||||
var diff = Vec_Sub(end,start);
|
||||
var diffangle = Vec_Angle(diff, [0,0]);
|
||||
|
@ -342,11 +333,11 @@ func UpdateLines()
|
|||
static const Ropeladder_Segment_LeftXOffset = 200;
|
||||
static const Ropeladder_Segment_RightXOffset = -100;
|
||||
|
||||
func GetRopeConnetPosition(int index, bool fRight, bool fEnd, int angle, int oldangle)
|
||||
func GetRopeConnectPosition(int index, bool fRight, bool fEnd, int angle, int oldangle)
|
||||
{
|
||||
if(SwitchRopes && index == 1 && fEnd == 0) fRight = !fRight;
|
||||
if(!(index == 1 && fEnd == 0) && MirrorSegments == -1) fRight = !fRight;
|
||||
if(fEnd == 0)
|
||||
if (switch_ropes && index == 1 && !fEnd) fRight = !fRight;
|
||||
if (!(index == 1 && !fEnd) && MirrorSegments == -1) fRight = !fRight;
|
||||
if (!fEnd)
|
||||
{
|
||||
var start = [0,0];
|
||||
if(fRight == 0)
|
||||
|
@ -359,9 +350,9 @@ func GetRopeConnetPosition(int index, bool fRight, bool fEnd, int angle, int old
|
|||
}
|
||||
else
|
||||
{
|
||||
start = [GetX()*Ladder_Precision, GetY()*Ladder_Precision];
|
||||
start[0] += -Cos(GetR(), 188)+Sin(GetR(), 113);
|
||||
start[1] += -Sin(GetR(), 188)-Cos(GetR(), 113);
|
||||
start = [GetX() * Ladder_Precision, GetY() * Ladder_Precision];
|
||||
start[0] += -Cos(GetR(), 188) + Sin(GetR(), 113);
|
||||
start[1] += -Sin(GetR(), 188) - Cos(GetR(), 113);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -470,13 +461,13 @@ public func IsTool() { return true; }
|
|||
public func IsToolProduct() { return true; }
|
||||
|
||||
local ActMap = {
|
||||
Hanging = {
|
||||
Prototype = Action,
|
||||
Name = "Hanging"
|
||||
},
|
||||
Hanging = {
|
||||
Prototype = Action,
|
||||
Name = "Hanging"
|
||||
},
|
||||
};
|
||||
local Name = "$Name$";
|
||||
local UsageHelp = "$UsageHelp$";
|
||||
local Description = "$Description$";
|
||||
local Collectible = 1;
|
||||
local Collectible = true;
|
||||
local Rebuy = true;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
/*--
|
||||
Ladder climbing
|
||||
Authors: Randrian
|
||||
/**
|
||||
Ladder Climbing
|
||||
Gives the ability to clonks climb on ladders.
|
||||
|
||||
Gives the ability to climb on ladders
|
||||
--*/
|
||||
@author Randrian
|
||||
*/
|
||||
|
||||
local jump_startcall;
|
||||
local no_ladder_counter;
|
||||
|
||||
func GetTurnPhase() { return _inherited(...); }
|
||||
public func GetTurnPhase() { return _inherited(...); }
|
||||
|
||||
func Definition(def) {
|
||||
public func Definition(proplist def)
|
||||
{
|
||||
// Only add action if included by clonk.
|
||||
if (!def.ActMap)
|
||||
return _inherited(def);
|
||||
|
@ -31,50 +32,61 @@ func Definition(def) {
|
|||
StartCall = "StartSearchLadder",
|
||||
// save old phasecall of jump
|
||||
StartCallLadderOverloaded = def.ActMap.Jump.StartCall
|
||||
},
|
||||
WallJump = {
|
||||
Prototype = def.ActMap.WallJump,
|
||||
StartCall = "StartSearchLadder",
|
||||
// save old phasecall of jump
|
||||
StartCallLadderOverloaded = def.ActMap.WallJump.StartCall
|
||||
}
|
||||
};
|
||||
_inherited(def);
|
||||
}
|
||||
|
||||
func StartScale()
|
||||
public func StartScale()
|
||||
{
|
||||
// Should be overloaded, and add a climb animation here
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
func StartSearchLadder()
|
||||
public func StartSearchLadder()
|
||||
{
|
||||
// call overwriten old phase call
|
||||
if (GetProperty("StartCallLadderOverloaded", GetProperty("Jump", GetProperty("ActMap"))))
|
||||
Call(GetProperty("StartCallLadderOverloaded", GetProperty("Jump", GetProperty("ActMap"))));
|
||||
// Call the overwriten old phase call.
|
||||
if (GetAction() == "Jump" && this.ActMap.Jump.StartCallLadderOverloaded)
|
||||
Call(this.ActMap.Jump.StartCallLadderOverloaded);
|
||||
if (GetAction() == "WallJump" && this.ActMap.WallJump.StartCallLadderOverloaded)
|
||||
Call(this.ActMap.WallJump.StartCallLadderOverloaded);
|
||||
if (!GetEffect("InSearchLadder", this))
|
||||
{
|
||||
AddEffect("IntSearchLadder", this, 1, 5, this);
|
||||
}
|
||||
FxIntSearchLadderTimer();
|
||||
return;
|
||||
}
|
||||
|
||||
func GetLadderScaleAnimation()
|
||||
public func GetLadderScaleAnimation()
|
||||
{
|
||||
var animation = _inherited(...);
|
||||
if(animation) return animation;
|
||||
if (animation)
|
||||
return animation;
|
||||
return "Scale";
|
||||
}
|
||||
|
||||
func FxIntSearchLadderTimer(target, effect, time)
|
||||
public func FxIntSearchLadderTimer(object target, proplist effect, int time)
|
||||
{
|
||||
if (GetAction() != "Jump") return -1;
|
||||
if (GetAction() != "Jump" && GetAction() != "WallJump")
|
||||
return FX_Execute_Kill;
|
||||
|
||||
var ladder;
|
||||
if (!no_ladder_counter)
|
||||
{
|
||||
for(ladder in FindObjects(Find_AtRect(-5,-5,10,10), Find_Func("IsLadder"),
|
||||
Find_NoContainer(), Find_Layer(GetObjectLayer())))
|
||||
for (ladder in FindObjects(Find_AtRect(-5,-5,10,10), Find_Func("IsLadder"), Find_NoContainer(), Find_Layer(GetObjectLayer())))
|
||||
{
|
||||
if(ladder->~CanNotBeClimbed()) continue;
|
||||
else break;
|
||||
if (ladder->~CanNotBeClimbed())
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
if(ladder && ladder->~CanNotBeClimbed()) ladder = nil;
|
||||
if (ladder && ladder->~CanNotBeClimbed())
|
||||
ladder = nil;
|
||||
}
|
||||
else
|
||||
no_ladder_counter--;
|
||||
|
@ -84,20 +96,23 @@ func FxIntSearchLadderTimer(target, effect, time)
|
|||
SetAction("Climb");
|
||||
ladder->~OnLadderGrab(this);
|
||||
PlayAnimation(GetLadderScaleAnimation(), CLONK_ANIM_SLOT_Movement, Anim_Y(0, GetAnimationLength(GetLadderScaleAnimation()), 0, 15), Anim_Linear(0, 0, 1000, 5, ANIM_Remove));
|
||||
AddEffect("IntClimbControl", this, 1, 1, this, 0, ladder);
|
||||
return -1;
|
||||
AddEffect("IntClimbControl", this, 1, 1, this, nil, ladder);
|
||||
return FX_Execute_Kill;
|
||||
}
|
||||
}
|
||||
|
||||
func FxIntSearchLadderStop(target, effect, reason, tmp)
|
||||
public func FxIntSearchLadderStop(object target, proplist effect, reason, tmp)
|
||||
{
|
||||
if (tmp) return;
|
||||
if (tmp)
|
||||
return FX_OK;
|
||||
no_ladder_counter = 0;
|
||||
return FX_OK;
|
||||
}
|
||||
|
||||
func FxIntClimbControlStart(target, effect, tmp, ladder)
|
||||
public func FxIntClimbControlStart(object target, proplist effect, tmp, object ladder)
|
||||
{
|
||||
if (tmp) return;
|
||||
if (tmp)
|
||||
return FX_OK;
|
||||
effect.ladder = ladder;
|
||||
SetXDir(0);
|
||||
SetYDir(0);
|
||||
|
@ -105,12 +120,13 @@ func FxIntClimbControlStart(target, effect, tmp, ladder)
|
|||
effect.odd = 0; // odd or even segment?
|
||||
SetHandAction(1);
|
||||
SetTurnType(1);
|
||||
return FX_OK;
|
||||
}
|
||||
|
||||
func SetTurnType() { return _inherited(...); }
|
||||
func SetHandAction() { return _inherited(...); }
|
||||
public func SetTurnType() { return _inherited(...); }
|
||||
public func SetHandAction() { return _inherited(...); }
|
||||
|
||||
func LadderStep(target, effect, fUp)
|
||||
public func LadderStep(target, effect, fUp)
|
||||
{
|
||||
if (fUp == 1)
|
||||
{
|
||||
|
@ -127,13 +143,13 @@ func LadderStep(target, effect, fUp)
|
|||
if (contact & CNAT_Left || contact & CNAT_Right)
|
||||
{
|
||||
SetAction("Scale");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
no_ladder_counter = 5;
|
||||
SetAction("Jump");
|
||||
SetXDir(-5+10*GetDir());
|
||||
SetYDir(-5);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -151,83 +167,90 @@ func LadderStep(target, effect, fUp)
|
|||
if (contact & CNAT_Left || contact & CNAT_Right)
|
||||
{
|
||||
SetAction("Scale");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
no_ladder_counter = 5;
|
||||
SetAction("Jump");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (effect.ladder == nil) return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
func FxIntClimbControlTimer(target, effect, time)
|
||||
public func FxIntClimbControlTimer(object target, proplist effect, int time)
|
||||
{
|
||||
if (GetAction() != "Climb" || Contained()) return -1;
|
||||
if(effect.ladder && effect.ladder->~CanNotBeClimbed(1)) effect.ladder = nil;
|
||||
if(!effect.ladder)
|
||||
if (GetAction() != "Climb" || Contained())
|
||||
return FX_Execute_Kill;
|
||||
if (effect.ladder && effect.ladder->~CanNotBeClimbed(1))
|
||||
effect.ladder = nil;
|
||||
if (!effect.ladder)
|
||||
{
|
||||
no_ladder_counter = 5;
|
||||
SetAction("Jump");
|
||||
SetXDir(-5+10*GetDir());
|
||||
SetXDir(-5 + 10 * GetDir());
|
||||
SetYDir(-5);
|
||||
return -1;
|
||||
return FX_Execute_Kill;
|
||||
}
|
||||
|
||||
// Progress
|
||||
var step = 0;
|
||||
if (GetComDir() == COMD_Down) step = -1;
|
||||
if (GetComDir() == COMD_Up) step = 1;
|
||||
if (GetComDir() == COMD_Down)
|
||||
step = -1;
|
||||
if (GetComDir() == COMD_Up)
|
||||
step = 1;
|
||||
|
||||
if (step && LadderStep(target, effect, step) == 0)
|
||||
{
|
||||
var contact = GetContact(-1);
|
||||
if (contact & CNAT_Left || contact & CNAT_Right)
|
||||
SetAction("Scale");
|
||||
SetAction("Scale");
|
||||
else
|
||||
{
|
||||
no_ladder_counter = 5;
|
||||
SetAction("Jump");
|
||||
if (step == 1) // For Up add some speed
|
||||
{
|
||||
SetXDir(-5+10*GetDir());
|
||||
SetXDir(-5 + 10 * GetDir());
|
||||
SetYDir(-5);
|
||||
no_ladder_counter = 10;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return FX_Execute_Kill;
|
||||
}
|
||||
var data = effect.ladder->GetLadderData();
|
||||
var startx = data[0], starty = data[1], endx = data[2], endy = data[3], angle = data[4];
|
||||
var x = startx + (endx-startx)*effect.pos/100+5000-100*GetTurnPhase();
|
||||
var y = starty + (endy-starty)*effect.pos/100;
|
||||
var x = startx + (endx-startx) * effect.pos / 100 + 5000 - 100 * GetTurnPhase();
|
||||
var y = starty + (endy-starty) * effect.pos / 100;
|
||||
var lx = LadderToLandscapeCoordinates(x);
|
||||
var ly = LadderToLandscapeCoordinates(y);
|
||||
var old_x = GetX(), old_y = GetY();
|
||||
if(Abs(old_x-lx)+Abs(old_y-ly) > 10 && time > 1)
|
||||
return -1;
|
||||
if (Abs(old_x - lx) + Abs(old_y - ly) > 10 && time > 1)
|
||||
return FX_Execute_Kill;
|
||||
SetPosition(lx, ly);
|
||||
SetXDir(0); SetYDir(0);
|
||||
SetLadderRotation(-angle, x-GetX()*1000, y-GetY()*1000);//effect.odd);
|
||||
SetXDir(0);
|
||||
SetYDir(0);
|
||||
SetLadderRotation(-angle, x - GetX() * 1000, y - GetY() * 1000);
|
||||
if (Stuck())
|
||||
{
|
||||
var dir = -1;
|
||||
if (GetDir() == 0) dir = 1;
|
||||
if (GetDir() == 0)
|
||||
dir = 1;
|
||||
for (var i = 1; i <= 5; i++)
|
||||
{
|
||||
SetPosition(LadderToLandscapeCoordinates(x)+i*dir, LadderToLandscapeCoordinates(y));
|
||||
SetPosition(LadderToLandscapeCoordinates(x) + i * dir, LadderToLandscapeCoordinates(y));
|
||||
if (!Stuck()) break;
|
||||
}
|
||||
if (Stuck()) SetPosition(LadderToLandscapeCoordinates(x)+5*dir, LadderToLandscapeCoordinates(y));
|
||||
if (Stuck()) SetPosition(LadderToLandscapeCoordinates(x) + 5 * dir, LadderToLandscapeCoordinates(y));
|
||||
}
|
||||
if (Stuck())
|
||||
{
|
||||
// Revert Position and step
|
||||
SetPosition(old_x, old_y);
|
||||
if (step) LadderStep(target, effect, -step);
|
||||
if (step)
|
||||
LadderStep(target, effect, -step);
|
||||
// if we are to far left or right try to turn
|
||||
if (GetDir() == 0 && LadderToLandscapeCoordinates(x)-2 > GetX())
|
||||
if (GetDir() == 0 && LadderToLandscapeCoordinates(x) - 2 > GetX())
|
||||
{
|
||||
SetComDir(COMD_Right);
|
||||
SetDir(1);
|
||||
|
@ -274,45 +297,51 @@ func FxIntClimbControlTimer(target, effect, time)
|
|||
SetAction("Walk");
|
||||
return -1;
|
||||
}
|
||||
/* if(contact & CNAT_Left || contact & CNAT_Right)
|
||||
{
|
||||
SetAction("Scale");
|
||||
return -1;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
func LadderToLandscapeCoordinates(int x)
|
||||
private func LadderToLandscapeCoordinates(int x)
|
||||
{
|
||||
return (x+500)/1000; // round to the next thousand
|
||||
// Round to the next thousand.
|
||||
return (x + 500) / 1000;
|
||||
}
|
||||
|
||||
func FxIntClimbControlStop(target, effect)
|
||||
public func FxIntClimbControlStop(target, effect)
|
||||
{
|
||||
if(GetAction() == "Climb") SetAction("Walk");
|
||||
if (GetAction() == "Climb")
|
||||
SetAction("Walk");
|
||||
SetLadderRotation(0);
|
||||
SetHandAction(0);
|
||||
}
|
||||
|
||||
func FxIntClimbControlControl(target, number, ctrl, x,y,strength, repeat, release)
|
||||
public func FxIntClimbControlControl(object target, proplist effect, int ctrl, int x, int y, int strength, bool repeat, bool release)
|
||||
{
|
||||
if (ctrl != CON_Up && ctrl != CON_Down && ctrl != CON_Right && ctrl != CON_Left) return;
|
||||
if (release == 1) return;
|
||||
if (ctrl == CON_Up) SetComDir(COMD_Up);
|
||||
else if (ctrl == CON_Down) SetComDir(COMD_Down);
|
||||
//Log("LIBLADDER: Control effect ctrl = %d, dir = %d", ctrl, GetDir());
|
||||
// Only handle movement controls.
|
||||
if (ctrl != CON_Up && ctrl != CON_Down && ctrl != CON_Right && ctrl != CON_Left)
|
||||
return false;
|
||||
// Perform actions on key down and not on release.
|
||||
if (release)
|
||||
return false;
|
||||
|
||||
if (ctrl == CON_Up)
|
||||
SetComDir(COMD_Up);
|
||||
else if (ctrl == CON_Down)
|
||||
SetComDir(COMD_Down);
|
||||
|
||||
else if (ctrl == CON_Left)
|
||||
{
|
||||
if (GetDir() == 0)
|
||||
if (GetDir() == DIR_Left)
|
||||
{
|
||||
if (GetComDir() == COMD_Stop)
|
||||
{
|
||||
SetPosition(GetX()-10, GetY());
|
||||
SetPosition(GetX() - 10, GetY());
|
||||
if (!Stuck())
|
||||
{
|
||||
SetComDir(COMD_Right);
|
||||
SetDir(1);
|
||||
SetDir(DIR_Right);
|
||||
}
|
||||
SetPosition(GetX()+10, GetY());
|
||||
SetPosition(GetX() + 10, GetY());
|
||||
}
|
||||
SetComDir(COMD_Stop);
|
||||
}
|
||||
|
@ -325,17 +354,17 @@ func FxIntClimbControlControl(target, number, ctrl, x,y,strength, repeat, releas
|
|||
}
|
||||
else if (ctrl == CON_Right)
|
||||
{
|
||||
if (GetDir() == 1)
|
||||
if (GetDir() == DIR_Right)
|
||||
{
|
||||
if (GetComDir() == COMD_Stop)
|
||||
{
|
||||
SetPosition(GetX()+10, GetY());
|
||||
SetPosition(GetX() + 10, GetY());
|
||||
if (!Stuck())
|
||||
{
|
||||
SetComDir(COMD_Left);
|
||||
SetDir(0);
|
||||
SetDir(DIR_Left);
|
||||
}
|
||||
SetPosition(GetX()-10, GetY());
|
||||
SetPosition(GetX() - 10, GetY());
|
||||
}
|
||||
SetComDir(COMD_Stop);
|
||||
}
|
||||
|
@ -343,23 +372,17 @@ func FxIntClimbControlControl(target, number, ctrl, x,y,strength, repeat, releas
|
|||
{
|
||||
no_ladder_counter = 5;
|
||||
SetAction("Jump");
|
||||
SetXDir(+15);
|
||||
SetXDir(15);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
func SetLadderRotation (int r, int xoff, int yoff) {
|
||||
SetMeshTransformation(Trans_Mul(Trans_Translate(0, -10000), Trans_Rotate(-r,0,0,1), Trans_Translate(xoff, 10000+yoff)), 5);
|
||||
// SetProperty("MeshTransformation", Trans_Mul(Trans_Translate(0, -10000), Trans_Rotate(-r,0,0,1), Trans_Translate(xoff, 10000+yoff)));
|
||||
public func SetLadderRotation (int r, int xoff, int yoff)
|
||||
{
|
||||
SetMeshTransformation(Trans_Mul(Trans_Translate(0, -10000), Trans_Rotate(-r, 0, 0, 1), Trans_Translate(xoff, 10000 + yoff)), 5);
|
||||
return;
|
||||
// var fsin=Sin(r, 1000), fcos=Cos(r, 1000);
|
||||
// // set matrix values
|
||||
// SetObjDrawTransform (
|
||||
// +fcos, +fsin, xoff, //(1000-fcos)*xoff - fsin*yoff,
|
||||
// -fsin, +fcos, yoff, //(1000-fcos)*yoff + fsin*xoff,
|
||||
// );
|
||||
}
|
||||
|
||||
// Defined to prevent an error.
|
||||
// Defined to prevent an error, because SetMeshTransformation is overloaded by the clonk.
|
||||
func SetMeshTransformation() { return _inherited(...); }
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/** Rope control
|
||||
* This library contains all functions for using dynamic ropes
|
||||
* @sa Ropeladder, GrapplerRope
|
||||
* @author Randrian
|
||||
/**
|
||||
Rope Library
|
||||
This library contains all functions for using dynamic ropes
|
||||
|
||||
@author Randrian
|
||||
*/
|
||||
|
||||
static const Rope_MaxParticles = 15;//30;//15*3;
|
||||
static const Rope_Iterations = 10;
|
||||
static const Rope_Precision = 100;
|
||||
static const Rope_SegmentLength = 5;//2;
|
||||
static const LIB_ROPE_Iterations = 10;
|
||||
static const LIB_ROPE_Precision = 100;
|
||||
static const LIB_ROPE_SegmentLength = 5;
|
||||
|
||||
local particles;
|
||||
local segments;
|
||||
|
@ -21,9 +21,9 @@ local length_auto;
|
|||
|
||||
local Max_Length;
|
||||
|
||||
func GetRopeGravity()
|
||||
public func GetRopeGravity()
|
||||
{
|
||||
return GetGravity()*Rope_Precision/100;
|
||||
return GetGravity() * LIB_ROPE_Precision / 100;
|
||||
}
|
||||
|
||||
/** Starts a rope
|
||||
|
@ -35,14 +35,14 @@ protected func StartRope()
|
|||
{
|
||||
objects = [[this, 0], [nil, nil]];
|
||||
TestArray = [[0, 1], [1, 0], [1, 1], [0, 2], [1, 2], [2, 0], [2, 1], [2, 2], [0, 3], [1, 3], [2, 3], [3, 0], [3, 1], [3, 2], [0, 4], [1, 4], [2, 4], [3, 3], [4, 0], [4, 1], [4, 2], [0, 5], [1, 5], [2, 5], [3, 4], [3, 5], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [0, 6], [1, 6], [2, 6], [3, 6], [4, 5], [5, 4], [6, 0], [6, 1], [6, 2], [6, 3], [0, 7], [1, 7], [2, 7], [3, 7], [4, 6], [5, 5], [5, 6], [6, 4], [6, 5], [7, 0], [7, 1], [7, 2], [7, 3], [0, 8], [1, 8], [2, 8], [3, 8], [4, 7], [4, 8], [5, 7], [6, 6], [7, 4], [7, 5], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 8], [6, 7], [7, 6], [7, 7], [8, 5], [9, 0], [9, 1], [9, 2], [9, 3], [9, 4]];
|
||||
length = Rope_SegmentLength;
|
||||
length = LIB_ROPE_SegmentLength;
|
||||
|
||||
ParticleCount = 1;
|
||||
segments = CreateArray(ParticleCount);
|
||||
segments[0] = CreateSegment(0, nil);
|
||||
|
||||
particles = CreateArray(ParticleCount);
|
||||
particles[0] = [[ GetX()*Rope_Precision, GetY()*Rope_Precision], [(GetX()+1)*Rope_Precision, GetY()*Rope_Precision], [0,GetRopeGravity()], 0];
|
||||
particles[0] = [[ GetX()*LIB_ROPE_Precision, GetY()*LIB_ROPE_Precision], [(GetX()+1)*LIB_ROPE_Precision, GetY()*LIB_ROPE_Precision], [0,GetRopeGravity()], 0];
|
||||
}
|
||||
|
||||
/** Connects \a obj1 and \a obj2
|
||||
|
@ -58,7 +58,7 @@ public func StartRopeConnect(object obj1, object obj2)
|
|||
|
||||
TestArray = [[0, 1], [1, 0], [1, 1], [0, 2], [1, 2], [2, 0], [2, 1], [2, 2], [0, 3], [1, 3], [2, 3], [3, 0], [3, 1], [3, 2], [0, 4], [1, 4], [2, 4], [3, 3], [4, 0], [4, 1], [4, 2], [0, 5], [1, 5], [2, 5], [3, 4], [3, 5], [4, 3], [4, 4], [5, 0], [5, 1], [5, 2], [5, 3], [0, 6], [1, 6], [2, 6], [3, 6], [4, 5], [5, 4], [6, 0], [6, 1], [6, 2], [6, 3], [0, 7], [1, 7], [2, 7], [3, 7], [4, 6], [5, 5], [5, 6], [6, 4], [6, 5], [7, 0], [7, 1], [7, 2], [7, 3], [0, 8], [1, 8], [2, 8], [3, 8], [4, 7], [4, 8], [5, 7], [6, 6], [7, 4], [7, 5], [8, 0], [8, 1], [8, 2], [8, 3], [8, 4], [0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 8], [6, 7], [7, 6], [7, 7], [8, 5], [9, 0], [9, 1], [9, 2], [9, 3], [9, 4]];
|
||||
|
||||
ParticleCount = length/Rope_SegmentLength;
|
||||
ParticleCount = length/LIB_ROPE_SegmentLength;
|
||||
|
||||
var yoff = 0;
|
||||
if(ParticleCount < 2)
|
||||
|
@ -80,10 +80,11 @@ public func StartRopeConnect(object obj1, object obj2)
|
|||
var x, y;
|
||||
for(var i = 0; i < ParticleCount; i++)
|
||||
{
|
||||
x = obj1->GetX(Rope_Precision)*(ParticleCount-i)/ParticleCount+obj2->GetX(Rope_Precision)*i/ParticleCount;
|
||||
y = obj1->GetY(Rope_Precision)*(ParticleCount-i)/ParticleCount+obj2->GetY(Rope_Precision)*i/ParticleCount;
|
||||
x = obj1->GetX(LIB_ROPE_Precision)*(ParticleCount-i)/ParticleCount+obj2->GetX(LIB_ROPE_Precision)*i/ParticleCount;
|
||||
y = obj1->GetY(LIB_ROPE_Precision)*(ParticleCount-i)/ParticleCount+obj2->GetY(LIB_ROPE_Precision)*i/ParticleCount;
|
||||
y += yoff*i;
|
||||
particles[i] = [[ x, y], [ x, y], [0,GetRopeGravity()], 1]; // Pos, Oldpos, acceleration (gravity), mass
|
||||
// Pos, Oldpos, acceleration (gravity), mass.
|
||||
particles[i] = [[ x, y], [ x, y], [0,GetRopeGravity()], 1];
|
||||
}
|
||||
particles[0][2] = [0,0];
|
||||
particles[0][3] = 0;
|
||||
|
@ -103,12 +104,12 @@ protected func Destruction()
|
|||
RemoveRope();
|
||||
}
|
||||
|
||||
func SetMaxLength(int newlength)
|
||||
public func SetMaxLength(int newlength)
|
||||
{
|
||||
Max_Length = newlength;
|
||||
}
|
||||
|
||||
func GetMaxLength()
|
||||
public func GetMaxLength()
|
||||
{
|
||||
return Max_Length;
|
||||
}
|
||||
|
@ -141,7 +142,7 @@ public func SetFixed(bool fixed_1, bool fixed_2)
|
|||
* A loose rope will vary the length according to the connected objects. If a object is non-fixed and pulls at the rope the length will increase.
|
||||
* If it doesn't pull the length will decrease.
|
||||
*/
|
||||
func ConnectLoose()
|
||||
public func ConnectLoose()
|
||||
{
|
||||
length_auto = 1;
|
||||
}
|
||||
|
@ -151,12 +152,12 @@ func ConnectLoose()
|
|||
*/
|
||||
local table2 ;//= [80,126,177,232,292,355,421,491,563,638,716,796,878,963,1050,1139,1230,1323,1417,1514,1612,1712,1814,1917,2022,2128,2236,2346,2457,2569,2683,2798,2914,3032,3151,3271,3393,3516,3640,3765,3891,4019,4148,4278,4409,4541,4674,4808,4943,5080,5217,5356,5495,5635,5777,5919,6063,6207,6352,6498,6645,6794,6943,7092,7243,7395,7547,7701,7855,8010,8166,8323,8481,8639,8798,8958,9119,9281,9444,9607,9771,9936,10102,10268,10435,10603,10772,10941,11111,11282,11454,11626,11799,11973,12148,12323,12499,12675,12853,13031,13209,13389,13569,13749,13931,14113,14295,14479,14663,14847,15033,15219,15405,15593,15780,15969,16158,16348,16538,16729,16921,17113,17306,17499,17693,17888,18083,18279,18475,18672,18870,19068,19267,19466,19666,19867,20000,20000,20000,2000];
|
||||
|
||||
func ConnectPull()
|
||||
public func ConnectPull()
|
||||
{
|
||||
length_auto = 0;
|
||||
}
|
||||
|
||||
func TogglePull()
|
||||
public func TogglePull()
|
||||
{
|
||||
if(length_auto) ConnectPull();
|
||||
else ConnectLoose();
|
||||
|
@ -201,7 +202,7 @@ public func AddSegment(int xoffset, int yoffset)
|
|||
|
||||
ParticleCount++;
|
||||
|
||||
length += Rope_SegmentLength;
|
||||
length += LIB_ROPE_SegmentLength;
|
||||
|
||||
UpdateSegmentOverlays();
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ public func RemoveSegment(fNoLengthAdjust)
|
|||
}
|
||||
|
||||
if(!fNoLengthAdjust)
|
||||
length -= Rope_SegmentLength;
|
||||
length -= LIB_ROPE_SegmentLength;
|
||||
|
||||
SetLength(segments, ParticleCount);
|
||||
SetLength(particles, ParticleCount);
|
||||
|
@ -271,11 +272,11 @@ public func DoLength(int dolength)
|
|||
MaxLengthReached();
|
||||
length = GetMaxLength();
|
||||
}
|
||||
if(length < Rope_SegmentLength*2) length = Rope_SegmentLength*2;
|
||||
if(length < LIB_ROPE_SegmentLength*2) length = LIB_ROPE_SegmentLength*2;
|
||||
|
||||
var last_length = GetLastLength();
|
||||
// Remove Points
|
||||
while( last_length < Rope_SegmentLength*Rope_Precision/2 && ParticleCount > 2)
|
||||
while( last_length < LIB_ROPE_SegmentLength*LIB_ROPE_Precision/2 && ParticleCount > 2)
|
||||
{
|
||||
particles[ParticleCount-2] = particles[ParticleCount-1];
|
||||
RemoveSegment(1);
|
||||
|
@ -283,7 +284,7 @@ public func DoLength(int dolength)
|
|||
last_length = GetLastLength();
|
||||
}
|
||||
var i = 0;
|
||||
while( last_length > Rope_SegmentLength*Rope_Precision*3/2)
|
||||
while( last_length > LIB_ROPE_SegmentLength*LIB_ROPE_Precision*3/2)
|
||||
{
|
||||
ParticleCount++;
|
||||
SetLength(particles, ParticleCount);
|
||||
|
@ -308,7 +309,7 @@ public func DoLength(int dolength)
|
|||
var y4 = particles[i][1][1];
|
||||
|
||||
particles[i] = [[ x/ParticleCount +x2*(ParticleCount-1)/ParticleCount, y/ParticleCount +y2*(ParticleCount-1)/ParticleCount],
|
||||
[ x3/ParticleCount+x4*(ParticleCount-1)/ParticleCount, y3/ParticleCount+y4*(ParticleCount-1)/ParticleCount], [0,1*Rope_Precision], 1];
|
||||
[ x3/ParticleCount+x4*(ParticleCount-1)/ParticleCount, y3/ParticleCount+y4*(ParticleCount-1)/ParticleCount], [0,1*LIB_ROPE_Precision], 1];
|
||||
}
|
||||
SetLength(segments, ParticleCount);
|
||||
segments[ParticleCount-1] = CreateSegment(ParticleCount, segments[ParticleCount-2]);
|
||||
|
@ -321,12 +322,12 @@ public func DoLength(int dolength)
|
|||
return;
|
||||
}
|
||||
|
||||
/** Returns the length of the last segment (other segments have \c Rope_SegmentLength length)
|
||||
/** Returns the length of the last segment (other segments have \c LIB_ROPE_SegmentLength length)
|
||||
* @return the length of the last segment
|
||||
*/
|
||||
func GetLastLength()
|
||||
public func GetLastLength()
|
||||
{
|
||||
return length*Rope_Precision-Rope_SegmentLength*Rope_Precision*(ParticleCount-1);
|
||||
return length*LIB_ROPE_Precision-LIB_ROPE_SegmentLength*LIB_ROPE_Precision*(ParticleCount-1);
|
||||
}
|
||||
|
||||
/** This is called when a new segment is added, the segments can adjust their appeareance to that
|
||||
|
@ -353,7 +354,7 @@ public func TimeStep()
|
|||
* These are gravity and for connect \a loose mode this is also a straightening of the rope.
|
||||
* Only called when in connect \a loose mode. NOT USED AT THE MOMENT!
|
||||
*/
|
||||
func AccumulateForces()
|
||||
public func AccumulateForces()
|
||||
{
|
||||
for(var i = 1; i < ParticleCount; i++)
|
||||
{
|
||||
|
@ -361,14 +362,8 @@ func AccumulateForces()
|
|||
if(i < ParticleCount-2)
|
||||
{
|
||||
angle = Angle(particles[i][0][0], particles[i][0][1], particles[i+1][0][0], particles[i+1][0][1]);
|
||||
fx = Sin(angle, 5*Rope_Precision);
|
||||
fy =-Cos(angle, 5*Rope_Precision);
|
||||
/* angle = Angle(particles[i-1][0][0], particles[i-1][0][1], particles[i+1][0][0], particles[i+1][0][1]);
|
||||
var middle = Vec_Div(Vec_Add(particles[i-1][0], particles[i+1][0]), 1);
|
||||
var diff = Vec_Sub(middle, particles[i][0]);
|
||||
var length = Vec_Length(diff);
|
||||
fx = Sin(angle, length/2);
|
||||
fy =-Cos(angle, length/2);*/
|
||||
fx = Sin(angle, 5*LIB_ROPE_Precision);
|
||||
fy =-Cos(angle, 5*LIB_ROPE_Precision);
|
||||
}
|
||||
particles[i][2] = [fx,fy+GetRopeGravity()];
|
||||
}
|
||||
|
@ -382,10 +377,7 @@ private func Verlet()
|
|||
// Copy Position of the objects
|
||||
var j = 0;
|
||||
for(var i = 0; i < 2; i++ || j--)
|
||||
{//Log("Verlet %d %d (%v), %d", i, j, objects, objects[i][1] == 0);
|
||||
// if(objects[i][1] == 0 )//|| PullObjects())
|
||||
SetParticleToObject(j, i);
|
||||
}//Log("End");
|
||||
|
||||
// Verlet
|
||||
var start = 1;
|
||||
|
@ -421,8 +413,8 @@ public func SetParticleToObject(int index, int obj_index)
|
|||
if(obj == nil) return;
|
||||
|
||||
if(obj->Contained()) obj = obj->Contained();
|
||||
particles[index][0][0] = obj->GetX(Rope_Precision);
|
||||
particles[index][0][1] = obj->GetY(Rope_Precision);
|
||||
particles[index][0][0] = obj->GetX(LIB_ROPE_Precision);
|
||||
particles[index][0][1] = obj->GetY(LIB_ROPE_Precision);
|
||||
return;
|
||||
//Log("Set %d %d", index, obj_index);
|
||||
// particles[index][1][0] = particles[index][0][0];
|
||||
|
@ -442,7 +434,7 @@ public func ConstraintObjects()
|
|||
public func ConstraintLength()
|
||||
{
|
||||
// Satisfy all stick constraints (move the particles to fit the length)
|
||||
var normal_restlength = Rope_SegmentLength*Rope_Precision;
|
||||
var normal_restlength = LIB_ROPE_SegmentLength*LIB_ROPE_Precision;
|
||||
var restlength;
|
||||
var invmass1, invmass2;
|
||||
var delta = [0,0], deltaDot, deltalength; // diff
|
||||
|
@ -496,11 +488,11 @@ public func ConstraintLandscape()
|
|||
// Calculate the new position (if we don't move in a direction don't overwrite the old value)
|
||||
var new = [0,0];
|
||||
if(pos[0])
|
||||
new[0] = (GetPartX(i)+xdir*pos[0])*Rope_Precision-xdir*Rope_Precision/2+xdir;
|
||||
new[0] = (GetPartX(i)+xdir*pos[0])*LIB_ROPE_Precision-xdir*LIB_ROPE_Precision/2+xdir;
|
||||
else
|
||||
new[0] = particles[i][0][0];
|
||||
if(pos[1])
|
||||
new[1] = (GetPartY(i)+ydir*pos[1])*Rope_Precision-ydir*Rope_Precision/2+ydir;
|
||||
new[1] = (GetPartY(i)+ydir*pos[1])*LIB_ROPE_Precision-ydir*LIB_ROPE_Precision/2+ydir;
|
||||
else
|
||||
new[1] = particles[i][0][1];
|
||||
particles[i][4] = 1; // Notifier for applying friction after the constraints
|
||||
|
@ -521,7 +513,7 @@ public func ConstraintLandscape()
|
|||
*/
|
||||
private func SatisfyConstraints()
|
||||
{
|
||||
for(var j=0; j < Rope_Iterations; j++)
|
||||
for(var j=0; j < LIB_ROPE_Iterations; j++)
|
||||
{
|
||||
ConstraintObjects();
|
||||
ConstraintLength();
|
||||
|
@ -541,7 +533,7 @@ private func SatisfyConstraints()
|
|||
/** Returns the length of the rope
|
||||
* @return the length of the rope
|
||||
*/
|
||||
func GetLineLength()
|
||||
public func GetLineLength()
|
||||
{
|
||||
var length_vertex = 0;
|
||||
for(var i=1; i < ParticleCount; i++)
|
||||
|
@ -549,11 +541,11 @@ func GetLineLength()
|
|||
return length_vertex;
|
||||
}
|
||||
|
||||
func LengthAutoTryCount() { return 5; }
|
||||
public func LengthAutoTryCount() { return 5; }
|
||||
|
||||
/** Applies the forces on the objects (only non-fixed ones) or adjust the length then the object pulls
|
||||
*/
|
||||
func ForcesOnObjects()
|
||||
public func ForcesOnObjects()
|
||||
{
|
||||
if(!length) return;
|
||||
|
||||
|
@ -583,27 +575,27 @@ func ForcesOnObjects()
|
|||
|
||||
if(obj->Contained()) obj = obj->Contained();
|
||||
|
||||
/* var x = obj->GetX(Rope_Precision), y = obj->GetY(Rope_Precision);
|
||||
obj->SetPosition(particles[j][0][0], particles[j][0][1], 1, Rope_Precision);
|
||||
/* var x = obj->GetX(LIB_ROPE_Precision), y = obj->GetY(LIB_ROPE_Precision);
|
||||
obj->SetPosition(particles[j][0][0], particles[j][0][1], 1, LIB_ROPE_Precision);
|
||||
if(obj->Stuck())
|
||||
obj->SetPosition(x, y, 1, Rope_Precision);*/
|
||||
obj->SetPosition(x, y, 1, LIB_ROPE_Precision);*/
|
||||
|
||||
if( (obj->GetAction() == "Walk" || obj->GetAction() == "Scale" || obj->GetAction() == "Hangle"))
|
||||
obj->SetAction("Jump");
|
||||
if( obj->GetAction() == "Climb")
|
||||
obj->SetAction("Jump");
|
||||
|
||||
obj->SetXDir( particles[j][0][0]-particles[j][1][0], Rope_Precision);
|
||||
obj->SetYDir( particles[j][0][1]-particles[j][1][1], Rope_Precision);
|
||||
obj->SetXDir( particles[j][0][0]-particles[j][1][0], LIB_ROPE_Precision);
|
||||
obj->SetYDir( particles[j][0][1]-particles[j][1][1], LIB_ROPE_Precision);
|
||||
}
|
||||
}
|
||||
|
||||
func PullObjects()
|
||||
public func PullObjects()
|
||||
{
|
||||
return !length_auto || length == GetMaxLength();
|
||||
}
|
||||
|
||||
func ObjContact(obj)
|
||||
public func ObjContact(obj)
|
||||
{
|
||||
if(obj->Contained()) obj = obj->Contained();
|
||||
if(obj->GetContact(-1)) return true;
|
||||
|
@ -647,64 +639,64 @@ func LogSpeed()
|
|||
* @param y vector to add
|
||||
* @param return vector \a x plus \a y
|
||||
*/
|
||||
func Vec_Add(array x, array y) { return [x[0]+y[0], x[1]+y[1]]; }
|
||||
public func Vec_Add(array x, array y) { return [x[0] + y[0], x[1] + y[1]]; }
|
||||
|
||||
/** Subtraction of two vectors
|
||||
* @param x vector 1
|
||||
* @param y vector to subtract
|
||||
* @param return vector \a x minus \a y
|
||||
*/
|
||||
func Vec_Sub(array x, array y) { return [x[0]-y[0], x[1]-y[1]]; }
|
||||
public func Vec_Sub(array x, array y) { return [x[0] - y[0], x[1] - y[1]]; }
|
||||
|
||||
/** Multiplication of a vector and a number
|
||||
* @param x vector
|
||||
* @param i number
|
||||
* @param return \a i times \a x
|
||||
*/
|
||||
func Vec_Mul(array x, int i) { return [x[0]*i, x[1]*i]; }
|
||||
public func Vec_Mul(array x, int i) { return [x[0] * i, x[1] * i]; }
|
||||
|
||||
/** Division of a vector and a number
|
||||
* @param x vector
|
||||
* @param i number
|
||||
* @param return \a x divided throught \a i
|
||||
*/
|
||||
func Vec_Div(array x, int i) { return [x[0]/i, x[1]/i]; }
|
||||
public func Vec_Div(array x, int i) { return [x[0] / i, x[1] / i]; }
|
||||
|
||||
/** Dot product of two vectors
|
||||
* @param x vector 1
|
||||
* @param y vector 2
|
||||
* @param return dot product between \a x and \a y
|
||||
*/
|
||||
func Vec_Dot(array x, array y) { return x[0]*y[0]+x[1]*y[1]; }
|
||||
public func Vec_Dot(array x, array y) { return x[0] * y[0] + x[1] * y[1]; }
|
||||
|
||||
/** Length of a vector
|
||||
* @param x vector
|
||||
* @param return length of vector \a a
|
||||
*/
|
||||
func Vec_Length(array x) { return Sqrt(x[0]*x[0]+x[1]*x[1]); }
|
||||
public func Vec_Length(array x) { return Sqrt(x[0] * x[0] + x[1] * x[1]); }
|
||||
|
||||
/** Angle between two vectors
|
||||
* @param x vector 1
|
||||
* @param y vector 2
|
||||
* @param return angle between \a x and \a y
|
||||
*/
|
||||
func Vec_Angle(array x, array y) { return Angle(x[0], x[1], y[0], y[1]); }
|
||||
public func Vec_Angle(array x, array y) { return Angle(x[0], x[1], y[0], y[1]); }
|
||||
|
||||
/** Normalizes a vector with precision
|
||||
* @param x vector
|
||||
* @param precision factor for the resultion length
|
||||
* @param return the normalize vector with length 1*precision
|
||||
*/
|
||||
func Vec_Normalize(array x, int precision) { return Vec_Div(Vec_Mul(x, precision), Vec_Length(x)); }
|
||||
public func Vec_Normalize(array x, int precision) { return Vec_Div(Vec_Mul(x, precision), Vec_Length(x)); }
|
||||
|
||||
/** Gives the the rounded x coordinate of particles \a index
|
||||
* @param index the particle which position is desired
|
||||
* @param return the x coordinate of particle \a index
|
||||
*/
|
||||
func GetPartX(index) { return (particles[index][0][0]+Rope_Precision/2)/Rope_Precision; }
|
||||
public func GetPartX(index) { return (particles[index][0][0] + LIB_ROPE_Precision / 2) / LIB_ROPE_Precision; }
|
||||
|
||||
/** Gives the the rounded y coordinate of particles \a index
|
||||
* @param index the particle which position is desired
|
||||
* @param return the y coordinate of particle \a index
|
||||
*/
|
||||
func GetPartY(index) { return (particles[index][0][1]+Rope_Precision/2)/Rope_Precision; }
|
||||
public func GetPartY(index) { return (particles[index][0][1] + LIB_ROPE_Precision / 2) / LIB_ROPE_Precision; }
|
||||
|
|
Loading…
Reference in New Issue