registerShakeEffect and time expiring shaking
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using OpenRa.Traits;
|
using OpenRa.Traits;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
namespace OpenRa.Traits
|
namespace OpenRa.Traits
|
||||||
{
|
{
|
||||||
@@ -12,26 +14,57 @@ namespace OpenRa.Traits
|
|||||||
public class ScreenShaker : ITick
|
public class ScreenShaker : ITick
|
||||||
{
|
{
|
||||||
int ticks = 0;
|
int ticks = 0;
|
||||||
|
static List<Tuple<int, float2, int>> shakeEffects = new List<Tuple<int, float2, int>>();
|
||||||
|
|
||||||
public ScreenShaker (Actor self){}
|
public ScreenShaker (Actor self){}
|
||||||
|
|
||||||
public void Tick (Actor self)
|
public void Tick (Actor self)
|
||||||
{
|
{
|
||||||
Game.viewport.Scroll(getScrollOffset());
|
Game.viewport.Scroll(getScrollOffset());
|
||||||
|
updateList();
|
||||||
ticks++;
|
ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void registerShakeEffect(float2 position, int time)
|
private void updateList()
|
||||||
//{
|
{
|
||||||
//}
|
var toRemove = new List<Tuple<int, float2, int>>();
|
||||||
|
|
||||||
|
for (int i = 0; i < shakeEffects.Count; i++){
|
||||||
|
var tuple = shakeEffects[i];
|
||||||
|
tuple.a = tuple.a - 1;
|
||||||
|
shakeEffects[i] = tuple;
|
||||||
|
|
||||||
|
if (tuple.a == 0)
|
||||||
|
toRemove.Add(tuple);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(Tuple<int, float2, int> t in toRemove){
|
||||||
|
shakeEffects.Remove(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerShakeEffect(int time, float2 position, int intensity)
|
||||||
|
{
|
||||||
|
shakeEffects.Add(Tuple.New<int, float2, int>(time, position, intensity));
|
||||||
|
}
|
||||||
|
|
||||||
public float2 getScrollOffset()
|
public float2 getScrollOffset()
|
||||||
{
|
{
|
||||||
int xFreq = 4;
|
int xFreq = 4;
|
||||||
int yFreq = 5;
|
int yFreq = 5;
|
||||||
int intensity = 3;
|
|
||||||
|
|
||||||
return intensity * new float2( (float) Math.Sin((ticks*2*Math.PI)/xFreq) , (float) Math.Cos((ticks*2*Math.PI)/yFreq));
|
return getIntensity() * new float2( (float) Math.Sin((ticks*2*Math.PI)/xFreq) , (float) Math.Cos((ticks*2*Math.PI)/yFreq));
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getIntensity()
|
||||||
|
{
|
||||||
|
float intensity = 0;
|
||||||
|
foreach(Tuple<int, float2, int> tuple in shakeEffects)
|
||||||
|
{
|
||||||
|
intensity += (24*24*100*tuple.c)/( (tuple.b.X - Game.viewport.Location.X) * (tuple.b.X - Game.viewport.Location.X)
|
||||||
|
+ (tuple.b.Y - Game.viewport.Location.Y) * (tuple.b.Y - Game.viewport.Location.Y) );
|
||||||
|
}
|
||||||
|
return Math.Min(intensity, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user