Improve default Use/Throw angles when not aiming

qteditor^2
Lukas Werling 2016-03-22 18:56:31 +01:00
parent fac684a973
commit acc04b2398
5 changed files with 68 additions and 29 deletions

View File

@ -37,6 +37,8 @@ public func IsDigging() { return is_digging; }
public func HoldingEnabled() { return true; }
public func DefaultCrosshairAngle(object clonk, int d) { return 900 * d; }
public func ControlUseStart(object clonk, int x, int y)
{
AddEffect("ShovelDig", clonk, 1, 1, this);

View File

@ -47,6 +47,14 @@ func ReadyToBeUsed(proplist data)
return !RejectUse(clonk) && !GetEffect("IntReload", this);
}
public func DefaultCrosshairAngle(object clonk, int d)
{
// Easy mode for gamepad users: automatically boost a jump.
if (clonk->GetYDir() < -10)
return Angle(0, 0, -clonk->GetXDir(), -clonk->GetYDir(), 10);
return 0;
}
protected func ControlUse(object clonk, x, y)
{
if (!GetEffect("IntReload", this) && !GetEffect("IntBurstWind", this))

View File

@ -20,6 +20,12 @@ protected func Initialize()
public func FxMoveTimer()
{
if (!crew)
{
RemoveObject();
return FX_Execute_Kill;
}
var target_angle = Angle(0,0,xpos,ypos)*10;
if (!Visible() && !InDeadzone())
@ -37,10 +43,12 @@ public func FxMoveTimer()
else
angle = target_angle;
}
else if (!aiming && Visible())
else if (!aiming)
{
// The player doesn't touch the stick and no item is using the crosshair right now.
SetVisibility(false);
// Aim somewhere useful. Note that this can be overwritten by objects and isn't used for throwing.
angle = 800*(crew->GetDir()*2-1);
}
UpdatePosition();
@ -64,17 +72,18 @@ private func SetVisibility(bool visible)
return newvis != oldvis;
}
public func StartAim(object clonk, bool stealth, object GUImenu)
private func CreateMoveEffect(object clonk)
{
aiming = !stealth;
crew = clonk;
UpdatePosition();
RemoveEffect("Move",this);
AddEffect("Move",this,1,1,this);
}
public func StartAim(object clonk, int default_angle, object GUImenu)
{
aiming = true;
// only reinitialize angle if the crosshair hasn't been there before
if(!GetEffect("Move",this))
{
// which should basically be only the case on the first time aiming
angle = 800*(clonk->GetDir()*2-1);
}
// gui or landscape mode:
if (GUImenu)
{
@ -88,14 +97,11 @@ public func StartAim(object clonk, bool stealth, object GUImenu)
menu = nil;
}
// Aim somewhere useful if the crosshair wasn't visible before.
if (!stealth && SetVisibility(true))
angle = 800*(clonk->GetDir()*2-1);
crew = clonk;
UpdatePosition();
RemoveEffect("Move",this);
AddEffect("Move",this,1,1,this);
// Use the given angle if the player wasn't aiming before.
if (SetVisibility(true) && default_angle)
angle = default_angle;
CreateMoveEffect(clonk);
}
private func UpdatePosition()
@ -122,16 +128,23 @@ public func StopAim()
aiming = false;
}
// Aiming means that some object is currently actively using the crosshair.
public func IsAiming()
{
return aiming;
}
// The crosshair is also active when the player is holding the aiming stick.
public func IsActive()
{
return aiming || Visible();
}
public func Aim(int ctrl, object clonk, int strength, int repeat, int status)
{
// start (stealth) aiming
if(!GetEffect("Move",this))
StartAim(clonk,true);
CreateMoveEffect(clonk);
// aiming with analog pad
if (status == CONS_Moved &&

View File

@ -46,6 +46,9 @@ static const ACTIONTYPE_EXTRA = 4;
// elevators within this range (x) can be called
static const ELEVATOR_CALL_DISTANCE = 30;
// default throwing angle used while the Clonk isn't aiming
static const DEFAULT_THROWING_ANGLE = 500;
/* ++++++++++++++++++++++++ Clonk Inventory Control ++++++++++++++++++++++++ */
/*
@ -362,14 +365,19 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re
if (only_drop || Distance(0, 0, x, y) < 10 || (Abs(x) < 10 && y > 10))
only_drop = true;
// throw
if (ctrl == CON_Throw)
CancelUse();
if (only_drop)
return ObjectCommand("Drop", contents);
else
{
CancelUse();
if (only_drop)
return ObjectCommand("Drop", contents);
else
return ObjectCommand("Throw", contents, x, y);
if (HasVirtualCursor() && !VirtualCursor()->IsActive())
{
var angle = DEFAULT_THROWING_ANGLE * (GetDir()*2 - 1);
x = +Sin(angle, CURSOR_Radius, 10);
y = -Cos(angle, CURSOR_Radius, 10);
}
return ObjectCommand("Throw", contents, x, y);
}
}
}
@ -624,7 +632,15 @@ func StartUseControl(int ctrl, int x, int y, object obj)
this.control.alt = ctrl != CON_Use;
if (HasVirtualCursor())
VirtualCursor()->StartAim(this);
{
var cursor = VirtualCursor(), angle;
if (!cursor->IsActive() && (angle = obj->~DefaultCrosshairAngle(this, GetDir()*2 - 1)))
{
x = +Sin(angle, CURSOR_Radius, 10);
y = -Cos(angle, CURSOR_Radius, 10);
}
cursor->StartAim(this, angle);
}
var hold_enabled = obj->Call("~HoldingEnabled");
@ -944,7 +960,7 @@ func SetMenu(new_menu, bool unclosable)
SetComDir(COMD_Stop);
if (PlayerHasVirtualCursor(GetOwner()))
VirtualCursor()->StartAim(this,false, new_menu);
VirtualCursor()->StartAim(this, 0, new_menu);
else
{
if (GetType(new_menu) == C4V_C4Object && new_menu->~CursorUpdatesEnabled())

View File

@ -79,7 +79,7 @@ func ReinitializeControls()
// if is aiming or in menu and no virtual cursor is there, create one
if (!virtual_cursor)
if (this.menu || this.control.current_object) // properties declared in ClonkControl.ocd
VirtualCursor()->StartAim(this,false,this.menu);
VirtualCursor()->StartAim(this,0,this.menu);
}
else
{