-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
141 lines (124 loc) · 4.19 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace AspectStar
{
class Player
{
public Texture2D Texture { get; set; }
private int currentFrame;
private int stallCount;
public Vector2 location;
public bool moving;
public Game1.Directions faceDir;
public Game1.Aspects aspect { get; set; }
Map currentMap;
public Player(Texture2D texture, Vector2 loc, Map map)
{
currentMap = map;
Texture = texture;
location = loc;
currentFrame = 0;
stallCount = 0;
faceDir = Game1.Directions.Down;
moving = false;
aspect = Game1.Aspects.Blue;
}
public void Update()
{
stallCount++;
if (stallCount == 10)
{
currentFrame++;
stallCount = 0;
}
if (currentFrame == 2)
currentFrame = 0;
if (moving == false)
currentFrame = 0;
if ((stallCount % 4 != 0) && (moving))
{
Vector2 move_dist = new Vector2(0, 0);
switch (faceDir)
{
case Game1.Directions.Down:
move_dist = new Vector2(0, 2);
break;
case Game1.Directions.Up:
move_dist = new Vector2(0, -2);
break;
case Game1.Directions.Left:
move_dist = new Vector2(-2, 0);
break;
case Game1.Directions.Right:
move_dist = new Vector2(2, 0);
break;
default:
break; // Something has gone wrong
}
this.Move(move_dist);
}
}
public Bullet Fire()
{
PlaySound.Pew();
Vector2 fire_dist = new Vector2(0, 0);
switch (faceDir)
{
case Game1.Directions.Down:
fire_dist = new Vector2(0, 16);
break;
case Game1.Directions.Up:
fire_dist = new Vector2(0, -16);
break;
case Game1.Directions.Left:
fire_dist = new Vector2(-16, 0);
break;
case Game1.Directions.Right:
fire_dist = new Vector2(16, 0);
break;
default:
break; // Something has gone wrong
}
return new Bullet(currentMap, this.location + fire_dist, this.faceDir, this.aspect);
}
private void Move(Vector2 move_vec)
{
Vector2 dest = location + move_vec;
//if (currentMap.isSolid(location + (move_vec * 8)))
if (currentMap.squareSolid(dest))
{
PlaySound.Thud();
}
else
{
location = dest;
Game1.Aspects test = currentMap.isAspect(location);
if ((test != Game1.Aspects.None) && (test != this.aspect))
{
this.aspect = test;
PlaySound.Aspect();
}
}
}
public void Draw(SpriteBatch spriteBatch, Color mask)
{
int dim = 32;
int column = ((int)faceDir * 2) + currentFrame;
int row = (int)aspect;
Vector2 screen_loc = location - new Vector2(dim / 2, dim / 2);
Rectangle sourceRectangle = new Rectangle(dim * column, dim * row, dim, dim);
Rectangle destinationRectangle = new Rectangle((int)screen_loc.X, (int)screen_loc.Y, dim, dim);
spriteBatch.Begin();
spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, mask);
spriteBatch.End();
}
public void Draw(SpriteBatch spriteBatch)
{
this.Draw(spriteBatch, Color.White);
}
}
}