-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
90 lines (70 loc) · 2.16 KB
/
Player.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
87
88
89
90
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
// Animation.cs
//Using declaration
using Microsoft.Xna.Framework.Content;
namespace PlatformerProject
{
class Player : Collidable
{
// Animation representing the player
//public Texture2D PlayerTexture;
// Animation representing the player
public Animation PlayerAnimation;
// Position of the Player relative to the upper left side of the screen
public Vector2 Position;
public int Health;
// State of the player
public bool Active;
public Rectangle hitbox ;
// Get the width of the player ship
public int Width
{
get { return PlayerAnimation.FrameWidth; }
}
// Get the height of the player ship
public int Height
{
get { return PlayerAnimation.FrameHeight; }
}
// Initialize the player
public void Initialize(Animation animation, Vector2 position)
{
PlayerAnimation = animation;
// Set the starting position of the player around the middle of the screen and to the back
Position = position;
hitbox = new Rectangle((int)position.X, (int)position.Y, (int)this.Width, (int)this.Height);
// Set the player to be active
Active = true;
}
// Update the player animation
public void Update(GameTime gameTime)
{
PlayerAnimation.Position = Position;
PlayerAnimation.Update(gameTime);
}
// Draw the player
public void Draw(SpriteBatch spriteBatch)
{
hitbox = new Rectangle((int)Position.X, (int)Position.Y, (int)this.Width, (int)this.Height);
PlayerAnimation.Draw(spriteBatch);
}
public Vector2 getPosition()
{
return Position;
}
public int getWidth()
{
return Width;
}
public int getHeight()
{
return Height;
}
public Rectangle getHitbox()
{
return hitbox;
}
}
}