New to Processing, can't figure this out at all.
in
Programming Questions
•
2 years ago
Hey guys! I'm really new to Processing and I have a possibly very stupid question to ask.
I don't have any prior programming experience. The most coding experience I have in any language is HTML/CSS and JavaScript. (processing.js was what caught my eye)
Anyway, enough about my life's story, lol.
I read through all the tutorials in the Learning section and realized I could probably make a game with Processing.
I decided to try to make a really simple top-view shoot-em-up, kinda like the arcade game 1942.
I haven't even bothered to try coding collisions or independent enemy movements, for now I just want to get the very basics working.
And I am almost literally being driven up the wall by the basics.
I can't for the life of me figure out how to shoot a proper bullet on a mouseclick.
If any of you could be so kind as to look at my code and maybe give me a nudge in the right direction, I would appreciate your help endlessly.
It's probably really messy and illogical, even though I tried my hardest to use logic and combine what I learned from the tutorials.
Again, thanks so much to whoever has the time/is willing to help me.
I don't have any prior programming experience. The most coding experience I have in any language is HTML/CSS and JavaScript. (processing.js was what caught my eye)
Anyway, enough about my life's story, lol.
I read through all the tutorials in the Learning section and realized I could probably make a game with Processing.
I decided to try to make a really simple top-view shoot-em-up, kinda like the arcade game 1942.
I haven't even bothered to try coding collisions or independent enemy movements, for now I just want to get the very basics working.
And I am almost literally being driven up the wall by the basics.
I can't for the life of me figure out how to shoot a proper bullet on a mouseclick.
If any of you could be so kind as to look at my code and maybe give me a nudge in the right direction, I would appreciate your help endlessly.
It's probably really messy and illogical, even though I tried my hardest to use logic and combine what I learned from the tutorials.
Again, thanks so much to whoever has the time/is willing to help me.
- Player ship;
Projectile bullet[];
int enemySize = 10;
int randx() {
return int(random(30,770));
}
float[] enemyXlocation = { randx(), randx(), randx(), randx(), randx()};
float[] enemyYlocation = { 0, 0, 0, 0, 0 };
int bNum = 0;
float projSpeed = 3;
float projHomeX;
float projHomeY;
float projX;
float projY;
float projY_;
void setup() {
size(800,600);
ship = new Player (color(100,100,150));
}
void draw() {
background(127);
fill(255);
text(frameCount, 0, 10);
ship.movement();
ship.display();
enemyHappen();
bullet[bNum] = new Projectile(color(100,150,100));
bullet[bNum].shoot();
}
void enemyHappen() {
stroke(0);
fill (150,100,100);
rectMode(CENTER);
for (int i=0; i<5; i++) {
enemyXlocation[i]=enemyXlocation[i];
enemyYlocation[i]=enemyYlocation[i]+1;
rect(enemyXlocation[i], enemyYlocation[i], enemySize, enemySize);
}
}
class Player {
color c;
float xpos;
float ypos;
Player(color tempC) {
c = tempC;
}
void display() {
stroke(0);
fill(c);
rectMode(CENTER);
rect(xpos,ypos,30,50);
}
void movement() {
xpos=mouseX;
ypos=mouseY;
if (ship.ypos <= ((height/3)*2)) {
ship.ypos = ((height/3)*2);
}
}
}
class Projectile {
color c;
Projectile(color tempC) {
c = tempC;
projX = projHomeX;
projY = projY_;
projHomeX=mouseX;
projHomeY=mouseY+30;
projY_=projHomeY+projSpeed;
}
void shoot() {
if (mousePressed == true) {
for (bNum = 0; bNum > height; bNum++){
projY_=projHomeY+projSpeed;
stroke(0);
fill(100,150,100);
ellipse (projX, projY, 5, 5);
}
}
}
}
1