Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
gamemaker
gamemaker's Profile
1
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
a pong game
[5 Replies]
20-Nov-2010 03:03 AM
Forum:
Programming Questions
hi
i've tried to make a pong game but when the ball bounces a secound time off the wall, it goes straigt through the bar!
here is the code:
int a = 670;
float xpos, ypos;
float xrectpos, yrectpos;
float xspeed = 0.1;
float yspeed = 0.03;
float rectspeed = 0.1;
int rectdirection = 30;
int xdirection = 20;
int ydirection = 20;
void setup () {
size (3*a/2,a);
background (255,255,255);
frameRate (30);
smooth ();
xpos = a*3/4;
ypos = a*3/4;
xrectpos = 14*a/10;
yrectpos = a/3;
}
void keyPressed () {
if (key == CODED) {
if (keyCode == UP) {
yrectpos = yrectpos + (rectdirection*rectspeed) * -1;
} else if (keyCode == DOWN) {
yrectpos = (yrectpos + (rectdirection*rectspeed));
}
}
}
void draw () {
xpos = xpos + (xspeed*xdirection);
ypos = ypos + (yspeed*ydirection);
stroke(255, 255, 255);
strokeWeight (10);
ellipse (xpos + a/200, ypos + a/200, a/40, a/40);
fill (#000000);
strokeWeight (7);
rect (xrectpos,yrectpos,a/50,a/5);
if ((xpos == xrectpos) && (ypos > yrectpos) && (ypos < (yrectpos + a/5))) {
xdirection *= -1.1;
xspeed = xspeed * 1.0001;
} else if (xpos < 0 ) {
xdirection *= -1.1;
xspeed = xspeed * 1.0001;
} else if (ypos < 0 || ypos > a) {
ydirection *= -1.1;
yspeed = yspeed *1.0002;
} else if (xpos > 3*a/2) {
println ("You've lost!");
exit ();
}
}
can somebody help me, please?
gamemaker
«Prev
Next »
Moderate user : gamemaker
Forum