KonsolScript:Tutorials:Pong:1 CreatingPaddle

From GPWiki
Jump to: navigation, search

Making your own Pong

Part 1 of Making your own Pong series.

Screenshot of the sample program.

Creating the Paddles and a Ball

It is possible to draw a paddle in a BMP file then use Image:Load command. But our concern here is making a game. And believe me, making images for use in a game is somewhat fun but could be much more frustrating.

In this Making your own Pong, we will utilize the Draw class of KonsolScript. We will need the Circ and Rect functions.

The Ball

For the ball, we will simply draw a circle at a certain radius. For this, we will use the Draw:Circ command that draws a circle.

Below is the syntax of Draw:Circ command. //syntax of Draw:Circ

 Draw:Circ(x, y, radius, color)

The Draw:Circ command, has four parameters. The first two, needs to know where we want to draw the circle -- x is the horizontal location and y is the vertical location.

Next, we have the radius parameter for the radius of the circle we want to draw.

And lastly, we have color parameter for the color of the circle we want to draw. Pretty simple, right?

Let us try that out. Copy the code below and execute it. function main() {

 Screen:Show()
 
 Draw:Circ(80, 20, 5, 24242424)
 
 while (B1 EQ false) { Screen:Render() }

} The color value 24242424 is just some random number I typed. I really do not have an idea what specific color it will produce. Try to change it to whatever suits you.

If you ask me, just settle for that right now. Do not care if we have an ugly ball -- at least we have one now; there is more to be done.

The Paddles

For the paddles, we will also simply draw a rectangle with a certain dimension. For this, we will use the Draw:Rect command that draws a rectangle.

Below is the syntax of Draw:Rect command. //syntax of Draw:Rect

 Draw:Rect(x, y, width, height, color)

The Draw:Rect command, has five parameters. The first two, needs to know where we want to draw the rectangle, same as the Draw:Circ.

The next two, we have the width and height parameter for the dimension of the rectangle we want to draw.

And lastly, we have color parameter for the color of the rectangle we want to draw.

Let us try that out. Copy the code below and execute it. function main() {

 Screen:Show()
 
 Draw:Rect(10, 95, 5, 50, 654897)
 Draw:Rect(300, 95, 5, 50, 12345678)
 
 while (B1 EQ false) { Screen:Render() }

} The color values 654897 and 12345678 are also some random numbers I typed. I, once again, do not have an idea what specific color would it produce.


Last Words

For the reason that KonsolScript do not draw a filled circle we just have to settle with Draw:Circ. But KonsolScript does know hot to draw a filled rectangle -- why not use it. And luckily, RectFill has the same parameter needs as Rect does. Simply change Rect to RectFill.

Below, is a joint code of drawing a circle and two filled rectangles which will be our Ball and Paddles. function main() {

 Screen:Show()
 
 Draw:Circ(80, 20, 5, 24242424)
 
 Draw:RectFill(10, 95, 5, 50, 654897)
 Draw:RectFill(300, 95, 5, 50, 12345678)
 
 while (B1 EQ false) { Screen:Render() }

}

Continue to Moving the Paddles.


~creek23~