We are about to switch to a new forum software. Until then we have removed the registration on this forum.
its a shotter game you shhoot bala (bullet) and kill soldat (soldier)
ArrayList bales; Bala bala1; PImage img;
void setup() {
size(800, 450);
stroke(255);
fill(255, 255, 255);
bales = new ArrayList();
bala1 = new Bala();
img = loadImage("pa.jpg");
bales.add( bala1 );
}
void draw() {
image(img, 0, 0);
line(400, 450, mouseX, 2 * mouseY);
strokeWeight(mouseY/10);
for ( int i = 0; i < bales.size(); i++) {
bala1 = (Bala)bales.get(i);
bala1.balesmoviment();
}
}
class Bala {
float balapx, balapy;
float baladx, balady;
Bala() {//creamos una bala
balapx = width/2.0;
balapy = height;
baladx = map(mouseX, 0, width, -10, 10);
balady = -10;
}
void balesmoviment() {
balapx += baladx;
balapy += balady;
ellipse( balapx, balapy, 2, 2);
}
}
void mousePressed() {
if ( bales.size() > 9 ) bales.remove(0);
bales.add( new Bala() );
}
{
ArrayList soldats;
Soldat soldat1;
{
void setup() {
soldats= new ArrayList();
soldat1 = new Soldat();
soldats.add (soldat1);
}
void draw() {
for ( int i = 0; i < bales.size(); i++) {
soldat1 = (Soldat)soldats.get(i);
soldat1.soldatsmoviment();
}
boolean choque( float balaX, float balaY, float balaR, float soldatX, float soldatY, float soldatW, float soldatH ) {
if (balaX==soldatX)&&(balaY==soldatY)&&(balaR==(soldatW*soldatH)) {//collision of 2 bullets
choque=true;
else() {
choque= false;
}
}
class Soldat { // Here the problem, how to make rectangles that move and avance in the map
float soldatpx, soldatpy;
float i;
Soldat() {//creamos unsoldat
soldatpx = width+i;
soldatpy = 0;
}
void soldatsmoviment() {
soldatpx +=i;
rect( soldatpx, balapy, 10, 20);
}
}
}
}
}
}
Answers
still not finished, i see...
Sigh. I said I was done. But I can still run your mess of code through the cleaner without doing your collision function for you. So look at this:
This is missing two things. First, the body of the collision function. To fill it in, check out this link:
http://www.jeffreythompson.org/collision-detection/circle-rect.php
Second, it is missing what should happen when there is a collision. Maybe you remove the Soldat
s
and make the Balab
bounce? Or remove it too? Whatever. That's up to you.I also commented out your background image because I don't have the image. Leave this commented out so it is easier for us to help you.
for ( Bala b : bales ) {
this function? ok
this is the image
What are you asking? What function? That's a loop. It loops over each Bala in the bales ArrayList.
Your image is not the issue here. How are you getting along with the collisions?
yesyes
i'm doing, you will hallucinate
what it means this loop?
I will write in the top of the code this //developed with the help of the TfGuy of the processing forum.
// ----- Global Variables -----
Why in the first page of the game to click start, don't work the stat 1 and 0. If YOU CLICK on the zone that I write, draw de void game.
//developed with the help of the TfGuy of the processing forum. ArrayList bales = new ArrayList(); ArrayList soldats = new ArrayList(); PImage img;
PImage pantinici; int joc; int estat;
jugar is play
Alright. One note: The loops on line 95 to 102 aren't doing anything, and can be removed. You have your collision checking elsewhere now.
and why don' t do the void joc? when I click on play
Sorry,this
with out print ln
No one, myself included, has any idea what you are talking about. What are you asking? What code is that? Is that a different sketch?
nono, look at your gmail, execute the code, and you will understand, is the first page of the game when you click on play and the game run
I personally have accepted ppp as our lord and savior
what?
tfguy, is the last question
Tf Guy, in the email you have the images to understand what I have talk to you
But where I talk to you? The mail is for you to understan what im doing. When you play a game first there is a first page where put play, you click on play and then the game start. I wanna do this.
Well, jugar is play, and when i click in the zone of jugar(play), the estat is 1 and then execute void joc (that is the game execute the game.
How I can start a new discussion with this problem? Because this is so long
Oh, okay, I think I get what you're trying to do. You want a start screen with a play button, and when you click the play button, then the game starts.
So you will need a variable to remember which state your sketch is in.
Initially, your sketch will be in state #0, the start screen state.
Now in draw(), you will need to either do the start screen (if the state is 0) or run the game (if the state is 1).
Finally, you will need to check if the start button is clicked.
If you can explain what you want to do with words first, it is much easier to be able to write the code that does it! Please learn how to describe things better!
yes, is this, but i do this and don't work
This was I did, first (if the state is 0) draw pantinici and if estate is 1 execute joc(joc means game) so execute the game. And in the mousePressed, i locate the rectangle of the button Play (300,400,400,420)
i Draw the int and nothing, I don't know
For these reason i pass the images in mail, for you to understan the botton for play(I don't know if I'm doing incorrectly the position of the botton play(in spanish jugar)
There is a difference between
mousePressed
(the boolean) andmousePressed()
(the function). Use the function.What? but I do this with the exception of the state0 and state1 I write pantinici and joc
And in the mousePressed I need to to the bolean because the mouse must clik on the button play
The difference is that my code shows the global state variable, and closes the functions. The code snippet you have posted looks like you grabbed a chunk out of the middle of something.
Please always post complete examples. That way we can copy, paste, and run them easily.
I do this int state;
The example is long // ----- Global Variables ----- //developed with the help of TfGuy
}
//void game over() {
Ctrl + t is your friend. It will auto-format your code. That way you can hopefully realize that you are defining your joc() function inside your pantinici() function. You MUST learn to put closing brackets where they belong!
camon, there is the last question and you will never see me aagain, please help mee
I've already told you what's wrong. You can fix it.
I don't want to never see you again. I want you to get good at programming and stick around to help other people learn.
yes, i help my friends an another people
// ----- Global Variables ----- //developed with the help of TfGuy
ArrayList bales = new ArrayList(); ArrayList soldats = new ArrayList(); PImage img;
PImage pantinici; int joc; int estat; //int game over;
The button and the first image appears, but he don't execute the void game
The mouseY variable can never satisfy both of these conditions at the same time. Any number greater than 440 will never also be less than 420.
ouuuuu yesyes
if (mouseX >=400 && mouseX <=370 && mouseY >=420 && mouseY <= 430) {