Some questions with my project!
in
Programming Questions
•
9 months ago
Hello, I'm new to processing and we're using it for a school project. (Please keep in mind English is not my first language)
We are making a space invaders type game. With very basic shapes we had to make our own "monsters"
Eventually these have to move across the screen. (Start from random position on the top of the screen and diagonally make their way down bouncing of the side of the screen and go the other horizontal way while remaining their downwards trajectory)
Question 1: How do I "group" the RECT's I used to create the monster in 1 group so that I can simply make that group move instead of coding all the RECT's individually. There probably are multiple ways. But if someone can explain me how to incorporate this with OOP i'dd appreciate it!
Question 2: I know how to "bounce" something from left to right.
But how do I make it go down diagonally as well?
Question 3: I want to make new monsters on a regular interval which keeps increasing in speed.
For instance start with one, add another one 5 seconds later, then 4.8, 4,6 etc.
They also have to appear 'randomly' on the top of the screen. For example lets number the top of the screen 1/10 and have the monsters spawn not only at 1 or 10 but also the numbers (positions ) in between.
If someone can provide me with the answers to these questions I think I can get alot further in my programming on my own after that. I really appreciate any help you guys can give me!
Here is the code I have so far to build my "monster" and some basic setup.
We are making a space invaders type game. With very basic shapes we had to make our own "monsters"
Eventually these have to move across the screen. (Start from random position on the top of the screen and diagonally make their way down bouncing of the side of the screen and go the other horizontal way while remaining their downwards trajectory)
Question 1: How do I "group" the RECT's I used to create the monster in 1 group so that I can simply make that group move instead of coding all the RECT's individually. There probably are multiple ways. But if someone can explain me how to incorporate this with OOP i'dd appreciate it!
Question 2: I know how to "bounce" something from left to right.
- Example: float x = 100;
float y = 1;
float speed = 1;
void setup() {
size(200, 200);
}
void draw() {
background(255);
x = x + speed;
if ((x>width) || (x<0)) {
speed = speed*-1;
}
stroke(0);
fill(175);
ellipse(x, 100, 32, 32);
}
But how do I make it go down diagonally as well?
Question 3: I want to make new monsters on a regular interval which keeps increasing in speed.
For instance start with one, add another one 5 seconds later, then 4.8, 4,6 etc.
They also have to appear 'randomly' on the top of the screen. For example lets number the top of the screen 1/10 and have the monsters spawn not only at 1 or 10 but also the numbers (positions ) in between.
If someone can provide me with the answers to these questions I think I can get alot further in my programming on my own after that. I really appreciate any help you guys can give me!
Here is the code I have so far to build my "monster" and some basic setup.
- //Int
int StartMonsterPix5X;
int StartMonsterPix5Y;
int PixSizePix5;
//Page
void setup(){
size(900,700);
noCursor();
}
void draw(){
background(0,0,0);
//StartValue Monster Pix5
StartMonsterPix5X = 150;
StartMonsterPix5Y = 150;
PixSizePix5 = 5;
noStroke();
fill(255,100,0);
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 0,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 1 (oor-links) X + 2 Y + 0
rect(StartMonsterPix5X + PixSizePix5 * 6,StartMonsterPix5Y + PixSizePix5 * 0,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 1 (oor-rechts) X + 6 Y + 0
rect(StartMonsterPix5X + PixSizePix5 * 3,StartMonsterPix5Y + PixSizePix5 * 1,PixSizePix5 * 3,PixSizePix5 * 1); //lijn 2 (hoofd) X + 3 Y + 1
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 2,PixSizePix5 * 5,PixSizePix5 * 1); //lijn 3 (voorhoofd) X + 2 Y + 2
rect(StartMonsterPix5X + PixSizePix5 * 0,StartMonsterPix5Y + PixSizePix5 * 3,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 4 (hand-links) X + 0 Y + 3
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 3,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 4 (oog-links) X + 2 Y + 3
rect(StartMonsterPix5X + PixSizePix5 * 4,StartMonsterPix5Y + PixSizePix5 * 3,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 4 (oog-midden) X + 4 Y + 3
rect(StartMonsterPix5X + PixSizePix5 * 6,StartMonsterPix5Y + PixSizePix5 * 3,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 4 (oog-rechts) X + 6 Y + 3
rect(StartMonsterPix5X + PixSizePix5 * 8,StartMonsterPix5Y + PixSizePix5 * 3,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 4 (hand-rechts) X + 8 Y + 3
rect(StartMonsterPix5X + PixSizePix5 * 1,StartMonsterPix5Y + PixSizePix5 * 4,PixSizePix5 * 7,PixSizePix5 * 1); //lijn 5 (neus) X + 1 Y + 4
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 5,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 6 (mond-links) X + 2 Y + 5
rect(StartMonsterPix5X + PixSizePix5 * 6,StartMonsterPix5Y + PixSizePix5 * 5,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 6 (mond-rechts) X + 6 Y + 5
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 6,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 7 (mond-links) X + 2 Y + 6
rect(StartMonsterPix5X + PixSizePix5 * 6,StartMonsterPix5Y + PixSizePix5 * 6,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 7 (mond-rechts) X + 6 Y + 6
rect(StartMonsterPix5X + PixSizePix5 * 3,StartMonsterPix5Y + PixSizePix5 * 7,PixSizePix5 * 3,PixSizePix5 * 1); //lijn 8 (kaak) X + 3 Y + 7
rect(StartMonsterPix5X + PixSizePix5 * 2,StartMonsterPix5Y + PixSizePix5 * 8,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 9 (knie-links) X + 2 Y + 8
rect(StartMonsterPix5X + PixSizePix5 * 6,StartMonsterPix5Y + PixSizePix5 * 8,PixSizePix5 * 1,PixSizePix5 * 1); //lijn 9 (knie-rechts) X + 6 Y + 8
rect(StartMonsterPix5X + PixSizePix5 * 0,StartMonsterPix5Y + PixSizePix5 * 9,PixSizePix5 * 2,PixSizePix5 * 2); //lijn 10 (voet-links) X + 0 Y + 9
rect(StartMonsterPix5X + PixSizePix5 * 7,StartMonsterPix5Y + PixSizePix5 * 9,PixSizePix5 * 2,PixSizePix5 * 2); //lijn 10 (voet-rechts)X + 7 Y + 9
//Crosshair
stroke(255,0,0);
noFill();
ellipse(mouseX, mouseY,5,5);
noFill();
stroke(255,0,0);
ellipse(mouseX, mouseY,30,30);
line(mouseX -10,mouseY,mouseX -20, mouseY); //Crosshair left line
line(mouseX +10,mouseY,mouseX +20, mouseY); //Crosshair right line
line(mouseX,mouseY -10,mouseX, mouseY -20); //Crosshair upper line
line(mouseX,mouseY +10,mouseX, mouseY +20); //Crosshair lower line
}
1