FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Responsive Form, Games
(Moderator: REAS)
   Squong: SQuare pONG
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Squong: SQuare pONG  (Read 489 times)
David Mear


Squong: SQuare pONG
« on: Sep 1st, 2003, 1:52pm »

Here's an early WIP of a 4-sided pong game.
(Sorry about the sloppy code.)
Any comments or criticisms greatly appreciated.
http://www.davidmear.com/p55/squong/
 
benelek

35160983516098 WWW Email
Re: Squong: SQuare pONG
« Reply #1 on: Sep 1st, 2003, 2:06pm »

kewl. pong's the best.
 
i know it sounds strange, but from your sketch 4-sided pong seems easier than the norm; all you have to do is keep your mouse on the ball. maybe some wonky forces acting on the ball would pick the challenge up!
 
toxi

WWW
Re: Squong: SQuare pONG
« Reply #2 on: Sep 1st, 2003, 2:08pm »

hi david,
 
nice idea, but your code structure is slightly wrong and the game doesn't really work as a result. there's no need to load all the images every frame, only once. the best place to do that is inside setup(). amended code below:
 
Code:
// "Squong"
// Like... SQuare pONG.
// By David Mear
// Sorry for the pretty much non-existant commenting.
 
float angle = random (0, 360);
float xm = cos(angle)*2;
float ym = sin(angle)*2;
float xp = 150;
float yp = 150;
int cwidth = 10;
int cheight = 10;
float speedx;
float speedy;
float speedxtemp;
float speedytemp;
int xpos = 150;
int ypos = 150;
int cursorx = 150;
int cursory = 150;
 
BImage ballpic;
BImage hpad;
BImage vpad;
 
void setup() {
  size(300, 300);
  colorMode (HSB, 255);
  background(0, 0, 255);
  noStroke();
  ballpic = loadImage("ball.gif");
  hpad = loadImage("hpad.gif");
  vpad = loadImage("vpad.gif");
}
 
void mousePressed() {
  angle = random (0, 360);
  xm = cos(angle)*2;
  ym = sin(angle)*2;
  xp = 150;
  yp = 150;
}
 
void loop () {
  float halfwidth = width*0.5;
  float halfheight = height*0.5;
  //  paddles movement
  cursorx = mouseX;
  cursory = mouseY;
  xpos = cursorx-20;
  ypos = cursory-20;
  fill(0, 0, 0, 255);
  //  top paddle
  image (hpad, xpos, 0);
  //  right paddle
  image (vpad, width-5, ypos);
  //  bottom paddle
  image (hpad, xpos, height-5);
  //  left paddle
  image (vpad, 0, ypos);
 
  //  ball movement
  speedxtemp = (mouseX - pmouseX);
  speedytemp = (mouseY - pmouseY);
  speedx = constrain(speedxtemp, -1, 1);
  speedy = constrain(speedytemp, -1, 1);
  xp = xp + xm;
  yp = yp + ym;
  if (((xp < 5) || (xp > (width-15))) && ((cursory >= (yp-20)) && (cursory <= (yp+20)))){
    xm = -xm;
    ym = ym + speedy;
    xp = constrain(xp, 5, 285);
  } else if ((xp < -5) || (xp > (width-5))){
    delay(1000);
    xp = halfwidth;
    yp = halfheight;
    angle = random (0, 360);
    xm = cos(angle)*2;
    ym = sin(angle)*2;
  }
  if (((yp < 5) || (yp > (height-15))) && ((cursorx >= (xp-20)) && (cursorx <= (xp+20)))) {
    ym = -ym;
    xm = xm + speedx;
    yp = constrain(yp, 5, 285);
  } else if ((yp < -5) || (yp > (height-5))){
    delay(1000);
    xp = halfwidth;
    yp = halfheight;
    angle = random (0, 360);
    xm = cos(angle)*2;
    ym = sin(angle)*2;
  }
  image(ballpic, xp, yp);
}
 

http://toxi.co.uk/
David Mear


Re: Squong: SQuare pONG
« Reply #3 on: Sep 1st, 2003, 4:24pm »

Thanks toxi!
I knew that I shouldn't have put the image loading in there, but I didn't think to put it in setup.
This is the first p55 thing I've made, but hopefully I'll get more better at making correct code structure soon.
 
benelek:
I'm going to add something that limits the speed of the paddles, so that you have to anticipate the movement of the ball more.
Also, I'm thinking of making targets of some kind appear randomly around the window. This would give you something to aim the ball at (by moving the paddle as you hit the ball).
Perhaps something like powerups, such as larger or smaller paddles. (You'd have to try and avoid the "smaller paddles" one, rather than aim for it.)
 
But for the moment, I'm just going to try and get it to work properly and well.
 
David Mear


Re: Squong: SQuare pONG
« Reply #4 on: Sep 1st, 2003, 5:19pm »

http://www.davidmear.com/p55/squong/
 
I've uploaded a slightly updated version.
I fixed the image loading, thanks to toxi.
The paddles' speed is limited, and there are three difficulty levels.
(The difficulty levels are just temporary. I'll have to tweak them once people give me some feedback on how hard / easy it is.)
 
Pages: 1 

« Previous topic | Next topic »