We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello pro brothers, I modified one of the game from proccessing game. But,now I want borders like this. http://i76.photobucket.com/albums/j5/Darius25/Borders problem_zpsbbwhzq2i.jpg But,how? I'm so noob and I just started to learn processing.Can you pro brothers help me out? Thank you.
Here are my lines in processing:
boolean gameover= false, right = false, left = false, up = false,down = false, d = false, a = false, w = false, s = false;
int topgoals=0;
int bottomgoals=0;
float changespeed=0;
Paddle bottom;
Ball football;
Paddle top;
void setup()
{
frameRate(100);
noStroke();
football= new Ball();
bottom=new Paddle();
top=new Paddle();
top.y=0;
bottom.y = 754;
size(720,760);
}
void keyPressed()
{
if (keyCode == LEFT)
{
left = true;
}
if (keyCode == RIGHT)
{
right = true;
}
if(keyCode == UP)
{
up = true;
}
if(keyCode == DOWN)
{
down = true;
}
if (key == 'a')
{
a=true;
}
if (key == 'd' )
{
d=true;
}
if (key == 'w')
{
w = true;
}
if (key == 's')
{
s = true;
}
}
void keyReleased()
{
if (keyCode == LEFT)
{
left = false;
}
if (keyCode==RIGHT)
{
right = false;
}
if (keyCode == UP)
{
up = false;
}
if (keyCode == DOWN)
{
down = false;
}
if (key=='a')
{
a=false;
}
if (key=='d')
{
d=false;
}
if (key == 'w')
{
w = false;
}
if (key == 's')
{
s = false;
}
}
void draw()
{
if (gameover==false)
{
background(#00760F);
fill(#FFFFFF);
rect(0,0,4,850);
rect(716,0,4,850);
bottom.show();
top.show();
if (left==true)
{
bottom.moveleft();
}
if (right==true)
{
bottom.moveright();
}
if (a==true)
{
top.moveleft();
}
if (d==true)
{
top.moveright();
}
football.move();
football.bounce();
football.show();
if (football.n<-8)
{
gameover=true;
bottomgoals++;
}
if (football.n>850)
{
gameover=true;
topgoals++;
}
}
else //gameover==true
{
background(0);
fill(255, 0, 0);
changespeed=0;
textSize(18);
text("Top Player's goals: "+topgoals, 15, 290);
text("Bottom Player's goals: "+bottomgoals, 15, 330);
textSize(36);
text("Game over! Click to restart.", 15, 250);
if (mousePressed==true)
{
football.m=int(random(200, 301));
football.n=int(random(200, 301));
int xdirection=int(random(2));
int ydirection=int(random(2));
if (xdirection==0)
{
football.right=true;
}
else //xidrection==1
{
football.right=false;
}
if (ydirection==0)
{
football.up=true;
}
else //ydirection==1
{
football.up=false;
}
gameover=false;
}
}
}
class Paddle
{
int x, y;
Paddle()
{
x=360;
}
void show()
{
fill(#038BFF);
rect(x, y, 80, 6);
}
void moveleft()
{
if (x>=0)
{
x -= 5;//speed
}
}
void moveright()
{
if (x<=635)
{
x += 5;//speed
}
}
}
class Ball
{
int m, n;
boolean up, right;
Ball()
{
m=425;
n=360;
up=true;
right=true;
}
void move()
{
if (up==true)
{
n=int(n-2-changespeed/2);
}
else //up==false
{
n=int(n+2+changespeed/2);
}
if (right==true)
{
m=int(m+2+changespeed/2);
}
else //right==false
{
m=int(m-2-changespeed/2);
}
}
void bounce()
{
if (get(int(m)-8, int(n))!=color(#00760F))
{
right=true;
}
if (get(int(m)+8, int(n))!=color(#00760F))
{
right=false;
}
if (get(int(m), int(n)-8)==color(#038BFF))
{
up=false;
}
if (get(int(m), int(n)+8)==color(#038BFF))
{
up=true;
changespeed+=1.0/4;
}
}
void show()
{
fill(#FF0324);
ellipse(m, n, 16, 16);
}
}
Answers
please format your code.
highlight, hit ctrl-o.
I didn't know that. Thank you. Now,can please help me?
I made an example for you. I changed the mechanics logic so there will be less code, but you can bring it back.
In order to understang what's going on here, I striktly recommend you to get into object-oriented programming. Here, we have 2 classes - for ball and borders they can interact with each other. Try adding more boxes or modifiying existing - you will see that we have a universal object that makes a ball bounce regardless of it's size and position.
Also feel free to ask any questions.