-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
136 lines (128 loc) · 6.11 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace _1Pixor
{
class Player : Tile
{
public int widthCase { get; private set; }
public int heightCase { get; private set; }
public int nbrblock { get; private set; }
public Player(Rectangle rec, Color color, GraphicsDevice gd, int widthCase, int heightCase)
: base(rec, color, gd)
{
this.widthCase = widthCase;
this.heightCase = heightCase;
this.nbrblock = 0;
}
public void move(int flag, int speed, int nbrWidth, int nbrHeight, Terrain[,,] t)
{
if (flag == 0)
{
if (rec.Y - speed >= 0 && t[Game1.lvl, this.widthCase, this.heightCase - 1].getType != Terrain.Type.Rock)
{
rec.Y -= speed;
heightCase--;
}
}
if (flag == 1)
{
if (rec.X + speed < nbrWidth * speed && t[Game1.lvl, this.widthCase + 1, this.heightCase].getType != Terrain.Type.Rock)
{
rec.X += speed;
widthCase++;
}
}
if (flag == 2)
{
if (rec.Y + speed < nbrHeight * speed && t[Game1.lvl, this.widthCase, this.heightCase + 1].getType != Terrain.Type.Rock)
{
rec.Y += speed;
heightCase++;
}
}
if (flag == 3)
{
if (rec.X - speed >= 0 && t[Game1.lvl, this.widthCase - 1, this.heightCase].getType != Terrain.Type.Rock)
{
rec.X -= speed;
widthCase--;
}
}
}
public int changeLvl(Terrain[,,] t)
{
if (t[Game1.lvl, this.widthCase, this.heightCase].getType == Terrain.Type.Hole_Bot)
{
return 1;
}
if (t[Game1.lvl, this.widthCase, this.heightCase].getType == Terrain.Type.Hole_Top)
{
return 0;
}
return -1;
}
public Terrain[,,] put(int direction, int X, int Y, int taille, int nbrWidth, int nbrHeight, Terrain[, ,] t, GraphicsDevice gd)
{
if (direction == 1 && this.heightCase > 0 && t[Game1.lvl, X, Y - 1].getType == Terrain.Type.Air)
{
t[Game1.lvl, X, Y - 1] = new Terrain(new Rectangle(X * taille, Y * taille - taille, taille, taille), gd, Terrain.Type.Rock);
nbrblock--;
}
if (direction == 2 && this.widthCase < nbrWidth * taille && t[Game1.lvl, X + 1, Y].getType == Terrain.Type.Air)
{
t[Game1.lvl, X + 1, Y] = new Terrain(new Rectangle(X * taille + taille, Y * taille, taille, taille), gd, Terrain.Type.Rock);
nbrblock--;
}
if (direction == 3 && this.heightCase < nbrHeight * taille && t[Game1.lvl, X, Y + 1].getType == Terrain.Type.Air)
{
t[Game1.lvl, X, Y + 1] = new Terrain(new Rectangle(X * taille, Y * taille + taille, taille, taille), gd, Terrain.Type.Rock);
nbrblock--;
}
if (direction == 4 && this.widthCase > 0 && t[Game1.lvl, X - 1, Y].getType == Terrain.Type.Air)
{
t[Game1.lvl, X - 1, Y] = new Terrain(new Rectangle(X * taille - taille, Y * taille, taille, taille), gd, Terrain.Type.Rock);
nbrblock--;
}
return t;
}
public Terrain[,,] dig(int direction, int X, int Y, int taille, int nbrWidth, int nbrHeight, Terrain[,,] t, GraphicsDevice gd)
{
if (direction == 0)
{
if (t[0, X, Y].getType != Terrain.Type.Hole_Bot)
nbrblock++;
t[0, X, Y] = new Terrain(new Rectangle(X * taille, Y * taille, taille, taille), gd, Terrain.Type.Hole_Bot);
t[1, X, Y] = new Terrain(new Rectangle(X * taille, Y * taille, taille, taille), gd, Terrain.Type.Hole_Top);
}
if (direction == 1 && this.heightCase > 0 && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Top)
{
if (t[Game1.lvl, X, Y - 1].getType == Terrain.Type.Rock)
nbrblock++;
t[Game1.lvl, X, Y - 1] = new Terrain(new Rectangle(X * taille, Y * taille - taille, taille, taille), gd, Terrain.Type.Air);
}
if (direction == 2 && this.widthCase < nbrWidth * taille && t[Game1.lvl, X + 1, Y].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X + 1, Y].getType != Terrain.Type.Hole_Top)
{
if (t[Game1.lvl, X + 1, Y].getType == Terrain.Type.Rock)
nbrblock++;
t[Game1.lvl, X + 1, Y] = new Terrain(new Rectangle(X * taille + taille, Y * taille, taille, taille), gd, Terrain.Type.Air);
}
if (direction == 3 && this.heightCase < nbrHeight * taille && t[Game1.lvl, X, Y + 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y + 1].getType != Terrain.Type.Hole_Top)
{
if (t[Game1.lvl, X, Y + 1].getType == Terrain.Type.Rock)
nbrblock++;
t[Game1.lvl, X, Y + 1] = new Terrain(new Rectangle(X * taille, Y * taille + taille, taille, taille), gd, Terrain.Type.Air);
}
if (direction == 4 && this.widthCase > 0 && t[Game1.lvl, X - 1, Y].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X - 1, Y].getType != Terrain.Type.Hole_Top)
{
if (t[Game1.lvl, X - 1, Y].getType == Terrain.Type.Rock && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Top)
nbrblock++;
t[Game1.lvl, X - 1, Y] = new Terrain(new Rectangle(X * taille - taille, Y * taille, taille, taille), gd, Terrain.Type.Air);
}
return t;
}
}
}