-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraEvent.cs
69 lines (65 loc) · 1.84 KB
/
CameraEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using Microsoft.Xna.Framework;
namespace Slip
{
public class CameraEvent
{
public const float speed = 10f;
private Vector2 targetPos;
public delegate void ActionEvent(Room room, Player player, int time);
public event ActionEvent DoAction;
private int actionLength;
public int timer = 0;
public int endAction
{
get
{
return 60 + actionLength;
}
}
public CameraEvent(Vector2 target, ActionEvent action, int length = 1)
{
this.targetPos = target;
this.DoAction = action;
this.actionLength = length;
}
public virtual bool Update(Room room, Player player, ref Vector2 camera)
{
if (timer == 0 && camera != targetPos)
{
Vector2 offset = targetPos - camera;
if (offset.Length() < speed)
{
camera = targetPos;
}
else
{
offset.Normalize();
offset *= speed;
camera += offset;
}
}
else if (timer < endAction)
{
timer++;
if (timer >= 30 && timer < 30 + actionLength)
{
DoAction(room, player, timer - 30);
}
}
else
{
Vector2 offset = player.position - camera;
if (offset.Length() < speed)
{
camera = player.position;
return true;
}
offset.Normalize();
offset *= speed;
camera += offset;
}
return false;
}
}
}