Add smooth shellmap movement
This commit is contained in:
committed by
Matthias Mailänder
parent
59ecb8d8a3
commit
2804d103ae
@@ -71,6 +71,8 @@ namespace OpenRA.Graphics
|
||||
float defaultScale;
|
||||
bool overrideUserScale;
|
||||
|
||||
public Func<float2> ViewportCenterProvider;
|
||||
|
||||
public float Zoom
|
||||
{
|
||||
get => zoom;
|
||||
@@ -177,6 +179,9 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
if (lastViewportDistance != graphicSettings.ViewportDistance)
|
||||
UpdateViewportZooms();
|
||||
|
||||
if (ViewportCenterProvider != null)
|
||||
Center(ViewportCenterProvider());
|
||||
}
|
||||
|
||||
static float CalculateMinimumZoom(float minHeight, float maxHeight)
|
||||
|
||||
65
OpenRA.Mods.Common/Traits/World/CameraMover.cs
Normal file
65
OpenRA.Mods.Common/Traits/World/CameraMover.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
[Desc("Moves the camera in an oval pattern around its starting position.")]
|
||||
sealed class CameraOvalMoverInfo : TraitInfo
|
||||
{
|
||||
[Desc("Starting angle in degrees.")]
|
||||
public int StartAngle = 45;
|
||||
|
||||
[Desc("How fast the camera moves around the oval.")]
|
||||
public float DegreesPerSecond = 3f;
|
||||
|
||||
[Desc("The X and Y radius of the oval path. Z is unused.")]
|
||||
public WVec OvalRadius = new(19200, 20480, 0);
|
||||
|
||||
public override object Create(ActorInitializer init) { return new CameraOvalMover(this); }
|
||||
}
|
||||
|
||||
sealed class CameraOvalMover : IWorldLoaded
|
||||
{
|
||||
readonly CameraOvalMoverInfo info;
|
||||
public CameraOvalMover(CameraOvalMoverInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
var vo = wr.Viewport.CenterPosition;
|
||||
var viewportOrigin = new float2(vo.X, vo.Y);
|
||||
|
||||
float angle = info.StartAngle;
|
||||
long lastTime = 0;
|
||||
wr.Viewport.ViewportCenterProvider = () =>
|
||||
{
|
||||
var currentTime = Game.RunTime;
|
||||
var dt = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
|
||||
// Prevent large jumps when the game is paused or the framerate is very low.
|
||||
const float MaxStep = 0.25f;
|
||||
angle += Math.Min(dt / 1000.0f * info.DegreesPerSecond, MaxStep);
|
||||
|
||||
var rad = angle * (Math.PI / 180);
|
||||
var offset = new float2((float)(info.OvalRadius.X * Math.Sin(rad)), (float)(info.OvalRadius.Y * Math.Cos(rad)));
|
||||
return viewportOrigin + offset;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,18 +139,6 @@ InitializeHarvester = function(harvester)
|
||||
harvester.FindResources()
|
||||
end
|
||||
|
||||
Ticks = 0
|
||||
Speed = 5
|
||||
|
||||
Tick = function()
|
||||
Ticks = Ticks + 1
|
||||
|
||||
if Ticks > 1 or not Map.IsPausedShellmap then
|
||||
local t = (Ticks + 45) % (360 * Speed) * (math.pi / 180) / Speed;
|
||||
Camera.Position = ViewportOrigin + WVec.New(19200 * math.sin(t), 28800 * math.cos(t), 0)
|
||||
end
|
||||
end
|
||||
|
||||
WorldLoaded = function()
|
||||
Atreides = Player.GetPlayer("Atreides")
|
||||
Harkonnen = Player.GetPlayer("Harkonnen")
|
||||
@@ -162,8 +150,6 @@ WorldLoaded = function()
|
||||
Reinforcements.Reinforce(Atreides, { "carryall" }, { atr_carry_2.Location })
|
||||
Reinforcements.Reinforce(Atreides, { "carryall" }, { atr_carry_3.Location })
|
||||
|
||||
ViewportOrigin = Camera.Position
|
||||
|
||||
Utils.Do(Utils.Take(4, Upgrades), function(upgrade)
|
||||
atr_cyard.Produce(upgrade)
|
||||
har_cyard.Produce(upgrade)
|
||||
@@ -201,6 +187,4 @@ WorldLoaded = function()
|
||||
Produce(Corrino, CorrinoTankTypes)
|
||||
Produce(Corrino, CorrinoStarportTypes)
|
||||
end)
|
||||
|
||||
Tick()
|
||||
end
|
||||
|
||||
@@ -19,6 +19,8 @@ World:
|
||||
DisableWorldSounds: true
|
||||
LuaScript:
|
||||
Scripts: utils.lua, d2k-shellmap.lua
|
||||
CameraOvalMover:
|
||||
OvalRadius: 19200, 28800, 0
|
||||
|
||||
^Palettes:
|
||||
-MenuPostProcessEffect:
|
||||
|
||||
@@ -170,20 +170,9 @@ ChronoshiftAlliedUnits = function()
|
||||
Trigger.AfterDelay(DateTime.Seconds(60), ChronoshiftAlliedUnits)
|
||||
end
|
||||
|
||||
Ticks = 0
|
||||
Speed = 5
|
||||
|
||||
Tick = function()
|
||||
Ticks = Ticks + 1
|
||||
|
||||
local t = (Ticks + 45) % (360 * Speed) * (math.pi / 180) / Speed;
|
||||
Camera.Position = ViewportOrigin + WVec.New(19200 * math.sin(t), 20480 * math.cos(t), 0)
|
||||
end
|
||||
|
||||
WorldLoaded = function()
|
||||
Allies = Player.GetPlayer("Allies")
|
||||
Soviets = Player.GetPlayer("Soviets")
|
||||
ViewportOrigin = Camera.Position
|
||||
|
||||
SetupAlliedUnits()
|
||||
SetupFactories()
|
||||
|
||||
@@ -20,6 +20,7 @@ World:
|
||||
LuaScript:
|
||||
Scripts: desert-shellmap.lua
|
||||
-StartGameNotification:
|
||||
CameraOvalMover:
|
||||
|
||||
^Palettes:
|
||||
-MenuPostProcessEffect:
|
||||
|
||||
Reference in New Issue
Block a user