-
Notifications
You must be signed in to change notification settings - Fork 3
/
Player.pde
107 lines (103 loc) · 3.41 KB
/
Player.pde
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
int north, south, west, east; /*Direcciones del jugador*/
class Player {
int x, y, z, pS; /*Position, pS = player spriteSize*/
float spriteCount = 0, spriteSpeed = 0.2; /*Sprite frame visualization control value*/
PImage sprite = new PImage(); /*Sprite complete Image*/
ArrayList<PImage> sp = new ArrayList<PImage>(); /*Sprite div of `PImage sprite` in an arrayList*/
/**/ /*Initialization of the object, arg "k" = (key of keyListener)*/
void init(int k) {
sprite = loadImage("Sprites/Sprite 2.png");
sp.clear();
while (mapT.map.getFloat((x+mapT.mapSize/2)+"-"+(z+mapT.mapSize/2)) != 0) {
x = (int)random(15-mapT.mapSize/2, mapT.mapSize/2-15);
z = (int)random(15-mapT.mapSize/2, mapT.mapSize/2-15);
}
mapT.pX = this.x;
mapT.pY = this.z;
for (int j = 512; j<767; j+=64) { /*Sprite movement section*/
for (int i = 0; i<575; i+=64)
sp.add(sprite.get(i, j, 64, 64));
}
}
void paint() {
spriteCount = spriteCount>=8? 0: spriteCount+spriteSpeed;
pushMatrix();
imageMode(CENTER);
rotateX(PI/2);
translate(x*pS, z*pS, 1);
if (south - north == -1)
image(sp.get( 0+(int)spriteCount), 0, 0, pS, pS);
else if (east - west == -1)
image(sp.get( 9+(int)spriteCount), 0, 0, pS, pS);
else if (east - west == 1)
image(sp.get(27+(int)spriteCount), 0, 0, pS, pS);
else if (south - north == 1)
image(sp.get(18+(int)spriteCount), 0, 0, pS, pS);
else
image(sp.get(18), 0, 0, pS, pS);
popMatrix();
}
/*<--Start Test-->*/
void move(Terrain m) {
int tx = x, tz = z; /*Temporal values of position*/
tx += x<m.mapSize/2 && x>-m.mapSize/2?east - west:0;
tz += z<m.mapSize/2 && z>-m.mapSize/2?south - north:0;
/**/ /*Rewrite position values just if is permitted*/
if((tx != x || tz != z) && chance(2.5)){
dialogue = "Battle";
mode = 'b';
}
if (m.map.getFloat((tx+m.mapSize/2)+"-"+(tz+m.mapSize/2))!=1) {
m.pX = x = tx;
m.pY = z = tz;
}
for (int i = 0; i < 9; i++) {
if (m.map.getFloat((tx+m.mapSize/2)+"-"+(tz+m.mapSize/2))==10*(i+1)) {
dialogue = "Dungeon"+(i+1);
mapTD[i+1] = new TerrainDungeon(""+(i+1));
filenames = file.list();
if(filenames.length > 1){
mode = 't';
m.pY += 1; /*<needs to improve>*/
numDungeon = i+1;
}
}
}
}
int chest = 0;
void move(TerrainDungeon m) {
int tx = x, tz = z; /*Temporal values of position*/
tx += x<m.mapSize/2 && x>-m.mapSize/2?east - west:0;
tz += z<m.mapSize/2 && z>-m.mapSize/2?south - north:0;
/**/ /*Rewrite position values just if is permitted*/
if((tx != x || tz != z) && chance(2.5)){
dialogue = "Battle";
mode = 'b';
}
else if((tx != x || tz != z) && chance(0.25) && chest++ < 3)
dialogue = "Chest";
if (!m.map.isNull((tx+m.mapSize/2)+"-"+(tz+m.mapSize/2))) {
m.pX = x = tx;
m.pY = z = tz;
}
}
/*<--End Test-->*/
/**/ /*k = keyListener, spd if 1 "true" direction: stop*/
void setDirection(int k, int spd) {
if (k == 'W')
north = spd;
else if (k == 'S')
south = spd;
else if (k == 'A')
west = spd;
else if (k == 'D')
east = spd;
}
Player() {
this.x = (int)random(15-mapT.mapSize/2, mapT.mapSize/2-15);
this.y = 0;
this.z = (int)random(15-mapT.mapSize/2, mapT.mapSize/2-15);
this.pS = mapT.mapSquareSize;
init((int)'1'); /*Player Initialization, arg = key*/
}
}