Projectile
in
Programming Questions
•
10 months ago
Player p1;
int x = 0;
int y = 0;
int p = x;
int i = y;
int o = x;
void setup(){
size(400,400);
}
void draw() {
background(0);
p1 = new Player();
if(key == 'd' && keyPressed){
p++;
}
if(key == 'w' && keyPressed){
i--;
}
if(key == 's' && keyPressed) {
i++;
}
if(key == 'a' && keyPressed) {
p--;
}
if(key == 'f') {
Bullet();
}
}
class Player {
Player(){
rect(p,i,50,50);
}
}
void Bullet(){
rect(p+50,i+13,25,25);
o = o + 5;
}
So I'm making a game and I'm having trouble with projectiles. I can't seem to figure out a way to make the bullet start at the location of the player but move independently of the player. The bullet also disappears when the player moves and resumes at the last location when f is pressed again. Can anyone tell me how to fix these?
int x = 0;
int y = 0;
int p = x;
int i = y;
int o = x;
void setup(){
size(400,400);
}
void draw() {
background(0);
p1 = new Player();
if(key == 'd' && keyPressed){
p++;
}
if(key == 'w' && keyPressed){
i--;
}
if(key == 's' && keyPressed) {
i++;
}
if(key == 'a' && keyPressed) {
p--;
}
if(key == 'f') {
Bullet();
}
}
class Player {
Player(){
rect(p,i,50,50);
}
}
void Bullet(){
rect(p+50,i+13,25,25);
o = o + 5;
}
So I'm making a game and I'm having trouble with projectiles. I can't seem to figure out a way to make the bullet start at the location of the player but move independently of the player. The bullet also disappears when the player moves and resumes at the last location when f is pressed again. Can anyone tell me how to fix these?
1