-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cs
More file actions
57 lines (50 loc) · 1.27 KB
/
Enemy.cs
File metadata and controls
57 lines (50 loc) · 1.27 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
using System.Collections.Specialized;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Pong
{
class Enemy
{
private Texture2D EnemyTexture;
private Vector2 _pos;
public Enemy()
{
}
public void SetContent(Texture2D enemy)
{
EnemyTexture = enemy;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(EnemyTexture,
_pos,
null,
Color.White,
0f,
new Vector2(EnemyTexture.Width / 2, EnemyTexture.Height / 2),
Vector2.One,
SpriteEffects.None,
0f);
}
public void Update(Vector2 playerPos)
{
if (_pos.X < playerPos.X)
{
_pos.X = _pos.X + 1;
}
if (_pos.X > playerPos.X)
{
_pos.X = _pos.X - 1;
}
if (_pos.Y < playerPos.Y)
{
_pos.Y = _pos.Y + 1;
}
if (_pos.Y > playerPos.Y){
_pos.Y = _pos.Y - 1;
}
}
}
}