-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.pde
141 lines (125 loc) · 2.8 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
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
int fireRate = 0;
boolean sFx = true;
boolean liber = true;
class Player
{
AudioPlayer fireSound;
AudioPlayer deathSound;
int playerX;
int playerY;
int damage = 0;
String name = "Player";
PImage playerImage;
PImage bulletImage;
int bulletSpeed = 3;
int life = 3;
//bullet Properties
IntList bulletX;
IntList bulletY;
int numBullets = 0;
int newWidth;
int newHeight;
int playerScore = 0;
Player(String name1, PImage img, PImage bullet, int fr, int dmg, String sp/*laser.mp3*/, String pD/*playerDeath.mp3*/)
{
name = name1;
playerImage = img;
bulletImage = bullet;
bulletX = new IntList();
bulletY = new IntList();
fireRate = fr;
damage = dmg;
fireSound = minim.loadFile(sp);// variabila minim se afla in sounds
deathSound = minim.loadFile(pD);
}
void drawPlayer()
{
if(life <= 0)
{
CurrentMenu = "over";
return;
}
textSize(24);
fill(255,0,0);
text("Score: " + playerScore, 0,25);
text("life: " + life, 0, 50);
text("level: " + (currentLevel + 1),0, 75);
noFill();
imageMode(CENTER);
image(playerImage, mouseX, playerY);
}
void updatePosition()
{
playerX = mouseX;
playerY = mouseY;
}
void playSound()
{
if(!sFx)
return;
fireSound.play();
fireSound.rewind();
}
void death()
{
if(!sFx)
return;
deathSound.play();
deathSound.rewind();
}
void shoot()
{
if(numBullets > 0)
if(fireRate > 0 && liber)
return;
playSound();
bulletX.append(mouseX);
bulletY.append(playerY);
numBullets++;
}
void fire()
{
for(int i = 0; i < numBullets; i++)
{
bulletY.set(i, bulletY.get(i) - bulletSpeed);
imageMode(CENTER);
image(bulletImage, bulletX.get(i), bulletY.get(i));
}
}
void deleteBullet()
{
for(int i = 0; i < numBullets; i++)
if(bulletY.get(i) < 0)
{
bulletX.remove(i);
bulletY.remove(i);
numBullets--;
}
}
void deleteBulletOnContact(int index)
{
bulletX.remove(index);
bulletY.remove(index);
numBullets--;
}
void clearAllBullets()
{
for(int i = 0; i < numBullets; i++)
deleteBulletOnContact(i);
}
}
void showPlayerImage(int nr,int x, int y)
{
player.playerImage = players2[nr];
image(players[nr],x,y);
}
void alocatePlayer()
{
PImage playerImg;
PImage bulletImg;
playerImg = loadImage("images/player/player1.png");
bulletImg = loadImage("images/player/bullet2.png");
player = new Player("Stefan", playerImg, bulletImg, 50,5,"sounds/gun/laser.mp3","sounds/player/playerDeath.mp3");
if(playerLifeAux > 0)
player.life = playerLifeAux;
}