forked from Mirrors/openclonk
loam: fixed turning while digging and added some particles
This were supposed to be two commits. Meh. Also, I can't really test how the particles looks because everything is black for me - ck? :(shapetextures
parent
5da08f2720
commit
0c73ae29e7
|
@ -41,23 +41,30 @@ func ControlUseStart(object clonk, int x, int y)
|
||||||
|
|
||||||
func HoldingEnabled() { return true; }
|
func HoldingEnabled() { return true; }
|
||||||
|
|
||||||
func FxIntBridgeStart(object clonk, proplist effect, int temp, int x, int y)
|
func FxIntBridgeStart(object clonk, effect fx, int temp, int x, int y)
|
||||||
{
|
{
|
||||||
if (temp)
|
if (temp)
|
||||||
return FX_OK;
|
return FX_OK;
|
||||||
// Drawing times.
|
// Drawing times.
|
||||||
effect.Begin = 0;
|
fx.Begin = 0;
|
||||||
effect.Last = 0;
|
fx.Last = 0;
|
||||||
// Last bridge coordinates.
|
// Last bridge coordinates.
|
||||||
effect.LastX = GetX();
|
fx.LastX = GetX();
|
||||||
effect.LastY = clonk->GetDefBottom() + 4;
|
fx.LastY = clonk->GetDefBottom() + 4;
|
||||||
// Target coordinates.
|
// Target coordinates.
|
||||||
effect.TargetX = x;
|
fx.TargetX = x;
|
||||||
effect.TargetY = y;
|
fx.TargetY = y;
|
||||||
|
// Dust particles that are used to hide that the material pops up out of nowhere.
|
||||||
|
fx.particles =
|
||||||
|
{
|
||||||
|
Prototype = Particles_Dust(),
|
||||||
|
R = 200, G = 150, B = 50,
|
||||||
|
Size = PV_KeyFrames(0, 0, 1, 100, 3, 1000, 2),
|
||||||
|
};
|
||||||
return FX_OK;
|
return FX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
func FxIntBridgeTimer(object clonk, proplist effect, int time)
|
func FxIntBridgeTimer(object clonk, effect fx, int time)
|
||||||
{
|
{
|
||||||
// something happened - don't try to dig anymore
|
// something happened - don't try to dig anymore
|
||||||
if (!(clonk->~IsBridging()))
|
if (!(clonk->~IsBridging()))
|
||||||
|
@ -66,33 +73,30 @@ func FxIntBridgeTimer(object clonk, proplist effect, int time)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clonk faces bridge direction
|
|
||||||
var tdir = 0;
|
|
||||||
// get global drawing coordinates
|
// get global drawing coordinates
|
||||||
var x = effect.TargetX + GetX();
|
var x = fx.TargetX + GetX();
|
||||||
var y = effect.TargetY + GetY();
|
var y = fx.TargetY + GetY();
|
||||||
if (x > 0) ++tdir;
|
|
||||||
clonk->SetDir(tdir);
|
|
||||||
|
|
||||||
// bridge speed: Build in smaller steps when briding upwards so Clonk moves up with bridge
|
// bridge speed: Build in smaller steps when briding upwards so Clonk moves up with bridge
|
||||||
var min_dt = 3;
|
var min_dt = 3;
|
||||||
if (effect.TargetY < -20 && !Abs(effect.TargetX*5/effect.TargetY))
|
if (fx.TargetY < -20 && !Abs(fx.TargetX*5/fx.TargetY))
|
||||||
min_dt = 2;
|
min_dt = 2;
|
||||||
|
|
||||||
// bridge speed by dig physical
|
// bridge speed by dig physical
|
||||||
var speed = clonk.ActMap.Dig.Speed/6;
|
var speed = clonk.ActMap.Dig.Speed/6;
|
||||||
|
|
||||||
// build bridge in chunks (for better angle precision)
|
// build bridge in chunks (for better angle precision)
|
||||||
var dt = time - effect.Last;
|
var dt = time - fx.Last;
|
||||||
if (dt < min_dt) return FX_OK;
|
if (dt < min_dt) return FX_OK;
|
||||||
effect.Last += dt;
|
fx.Last += dt;
|
||||||
|
|
||||||
// draw loam (earth) line
|
// draw loam (earth) line
|
||||||
var line_wdt = 3;
|
var line_wdt = 3;
|
||||||
var line_len = speed * dt;
|
var line_len = speed * dt;
|
||||||
var last_x = effect.LastX;
|
var last_x = fx.LastX;
|
||||||
var last_y = effect.LastY;
|
var last_y = fx.LastY;
|
||||||
var dx = x-last_x, dy=y-last_y, d=Distance(dx, dy);
|
var dx = x-last_x, dy=y-last_y;
|
||||||
|
var d = Distance(dx, dy);
|
||||||
// Quantize angle as a multiple of 30 degrees.
|
// Quantize angle as a multiple of 30 degrees.
|
||||||
var quant = 30;
|
var quant = 30;
|
||||||
var angle = Angle(0, 0, dx, dy);
|
var angle = Angle(0, 0, dx, dy);
|
||||||
|
@ -103,15 +107,26 @@ func FxIntBridgeTimer(object clonk, proplist effect, int time)
|
||||||
// Don't use up loam if the mouse position is reached...
|
// Don't use up loam if the mouse position is reached...
|
||||||
// wait for the mouse being moved and then continue bridging
|
// wait for the mouse being moved and then continue bridging
|
||||||
// into that direction
|
// into that direction
|
||||||
if(!d) return FX_OK;
|
if(d <= 1) return FX_OK;
|
||||||
|
|
||||||
var ox = dy * line_wdt / d, oy = -dx * line_wdt / d;
|
var ox = dy * line_wdt / d, oy = -dx * line_wdt / d;
|
||||||
dx = dx * line_len / (d*10);
|
dx = dx * line_len / (d*10);
|
||||||
dy = dy * line_len / (d*10);
|
dy = dy * line_len / (d*10);
|
||||||
DrawMaterialQuad("Earth-earth", last_x-ox,last_y-oy, last_x+dx-ox,last_y+dy-oy, last_x+dx+ox,last_y+dy+oy, last_x+ox,last_y+oy, DMQ_Bridge);
|
DrawMaterialQuad("Earth-earth", last_x-ox,last_y-oy, last_x+dx-ox,last_y+dy-oy, last_x+dx+ox,last_y+dy+oy, last_x+ox,last_y+oy, DMQ_Bridge);
|
||||||
effect.LastX += dx;
|
fx.LastX += dx;
|
||||||
effect.LastY += dy;
|
fx.LastY += dy;
|
||||||
|
|
||||||
|
// Some dust to hide the otherwise ugly construction.
|
||||||
|
var local_x = fx.LastX - clonk->GetX();
|
||||||
|
var local_y = fx.LastY - clonk->GetY();
|
||||||
|
clonk->CreateParticle("SmokeDirty", PV_Random(local_x - 5, local_x + 5), PV_Random(local_y - 5, local_y + 5), PV_Random(-5, 5), PV_Random(-5, 5), PV_Random(5, 10), fx.particles, 40);
|
||||||
|
|
||||||
|
// Clonk faces bridge direction.
|
||||||
|
var view_direction = DIR_Left;
|
||||||
|
if (local_x > 0)
|
||||||
|
view_direction = DIR_Right;
|
||||||
|
clonk->SetTurnForced(view_direction);
|
||||||
|
|
||||||
// bridge time is up?
|
// bridge time is up?
|
||||||
loamused += Max(line_len/10,1);
|
loamused += Max(line_len/10,1);
|
||||||
if (loamused >= BridgeLength)
|
if (loamused >= BridgeLength)
|
||||||
|
|
Loading…
Reference in New Issue