-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCursor.cs
86 lines (72 loc) · 2.7 KB
/
Cursor.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using GenserSprites;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace ConwaysGameOfLife
{
/// <summary>
/// Tracks the input from the user's cursor.
/// Created by: Ethan Genser
/// </summary>
public class Cursor : AdvancedSprite
{
#region _Variables_
public bool LMBdown { get; protected set; }
public bool RMBdown { get; protected set; }
public int activeTexture
{
get { return currentFrame; }
set { currentFrame = value; }
}
#endregion
// Constructor
public Cursor(int spriteSheetLength) : base(Vector2.Zero, 0f, spriteSheetLength, 1)
{
LMBdown = false;
RMBdown = false;
}
// Update
public override void Update(GameTime gameTime)
{
base.Update();
hitbox = new Rectangle((int)position.X - currentTexture.Width / 2, (int)position.Y - currentTexture.Height / 2, 1, 1);
// Following mouse position & screen bounderies
if (Mouse.GetState().X >= GraphicsDevice.Viewport.Width)
Mouse.SetPosition(GraphicsDevice.Viewport.Width, Mouse.GetState().Y);
if (Mouse.GetState().Y >= GraphicsDevice.Viewport.Height)
Mouse.SetPosition(Mouse.GetState().X, GraphicsDevice.Viewport.Height);
if ((Mouse.GetState().X > 0) && (Mouse.GetState().X < GraphicsDevice.Viewport.Width - 1))
position.X = Mouse.GetState().X;
else if (Mouse.GetState().X <= 0)
position.X = 0;
else position.X = GraphicsDevice.Viewport.Width - 1;
if ((Mouse.GetState().Y > 0) && (Mouse.GetState().Y < GraphicsDevice.Viewport.Height - 1))
position.Y = Mouse.GetState().Y;
else if (Mouse.GetState().Y <= 0)
position.Y = 0;
else position.Y = GraphicsDevice.Viewport.Height - 1;
}
// Pressing and releasing mouse buttons
public bool LMBpressed()
{
if (Mouse.GetState().LeftButton == ButtonState.Pressed)
LMBdown = true;
if ((Mouse.GetState().LeftButton == ButtonState.Released) && (LMBdown))
{
LMBdown = false;
return true;
}
else return false;
}
public bool RMBpressed()
{
if (Mouse.GetState().RightButton == ButtonState.Pressed)
RMBdown = true;
if ((Mouse.GetState().RightButton == ButtonState.Released) && (RMBdown))
{
RMBdown = false;
return true;
}
else return false;
}
}
}