-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.cs
More file actions
32 lines (27 loc) · 892 Bytes
/
Player.cs
File metadata and controls
32 lines (27 loc) · 892 Bytes
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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
public class Player : GameObject {
private float speed = 450f;
public Player(Game game, string pathToTexture, Vector2 position) : base(game, pathToTexture, position)
{}
public void Draw(SpriteBatch spriteBatch) {
spriteBatch.Draw(
this.texture,
this.position,
null,
Color.White,
0f,
Vector2.Zero,
Vector2.One,
SpriteEffects.None,
0f
);
}
public void Move(GameTime gameTime, KeyboardState keys, int width) {
if (keys.IsKeyDown(Keys.Right) && this.position.X + this.texture.Width < width)
this.position.X += this.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
if (keys.IsKeyDown(Keys.Left) && this.position.X > 0)
this.position.X -= this.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
}