-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingPlatform.cs
More file actions
69 lines (63 loc) · 1.68 KB
/
MovingPlatform.cs
File metadata and controls
69 lines (63 loc) · 1.68 KB
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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace ProgGame
{
public class MovingPlatform
{
public const float movingSpeed = 2f;
private bool isMoving = false;
private Texture2D texture;
public Vector2 position;
private GameLevel level;
private Vector2 startPosition;
private Rectangle localBounds;
public Rectangle Bounds
{
get
{
int left = (int)Math.Round(position.X - (texture.Width / 2)) + localBounds.X;
int top = (int)Math.Round(position.Y - texture.Height) + localBounds.Y;
return new Rectangle(left, top, localBounds.Width, localBounds.Height);
}
}
public MovingPlatform(GameLevel level, Vector2 position)
{
this.level = level;
startPosition = position;
this.position = startPosition;
texture = level.content.Load<Texture2D>("tiles/movingplatform");
int width = (int)texture.Width;
int left = (texture.Width - width) / 2;
int height = 1;
int top = texture.Height - height;
localBounds = new Rectangle(left, top, width, height);
}
public void Update()
{
if (isMoving)
position = new Vector2(position.X, position.Y - movingSpeed);
}
public void TriggerMove()
{
isMoving = true;
}
public void UnTriggerMove()
{
isMoving = false;
}
public void ResetPosition()
{
position = startPosition;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, position, null, Color.White, 0, new Vector2(texture.Width / 2, texture.Height / 4), 1.0f, SpriteEffects.None, 0.0f);
// Extentions.DrawRectangle(Bounds, spriteBatch);
}
}
}