Creating my own pong game
Author |
Message |
adudeknownasz
|
Posted: Fri Sep 26, 2008 4:18 pm Post subject: Creating my own pong game |
|
|
Just started using turing a few weeks ago, and i started creating my own pong game last week. This game is a one player pong game. ive added obstacles, but there is problems when the ball hits the obstacle at a certain angle it goes through it. Any suggestions as to fixing the obstacles, and adding boundary to the paddles would be awesome thanks.
heres my code
setscreen ("graphics:vga")
var x, y, x2, y2, a2, b2, button, a1, b1, c1, d1, x1, y1, left, middle, right, x3, y3, a3, b3, x4, y4, a4, b4, x5, y5, a5, b5 : int
a1 := 4
b1 := 4
c1 := 10
d1 := 220
x1 := 10
y1 := 180
x2 := Rand.Int (0, maxx)
y2 := Rand.Int (0, maxy)
a2 := 2
b2 := 2
x3 := 245
y3 := 272
a3 := 3
b3 := 3
x4 := 456
y4 := 120
a4 := 4
b4 := 4
x5 := 550
y5 := 335
a5 := 6
b5 := 6
loop
drawfilloval (x2, y2, 10, 10, black)
drawfilloval (x3, y3, 40, 40, blue)
drawfilloval (x4, y4, 40, 40, blue)
drawfilloval (x5, y5, 40, 40, blue)
Draw.ThickLine (x1, y1, c1, d1, 10, 4)
delay (10)
drawfilloval (x2, y2, 10, 10, 0)
drawfilloval (x3, y3, 40, 40, blue)
drawfilloval (x4, y4, 40, 40, blue)
drawfilloval (x5, y5, 40, 40, blue)
Draw.ThickLine (x1, y1, c1, d1, 10, 0)
x2 := x2 + a2
y2 := y2 + b2
if y2 > 390 or y2 < 10
then
b2 := b2 * -1
end if
if x2 > 630
then
a2 := a2 * -1
end if
if y3 > 390 or y3 < 10
then
b3 := b3 * -1
end if
if x3 > 630
then
a3 := a3 * -1
end if
if y4 > 390 or y4 < 10
then
b4 := b4 * -1
end if
if x4 > 630
then
a4 := a4 * -1
end if
if abs (x2 - x3) < 50 and abs (y2 - y3) < 50 then
a2 := a2 * -1
end if
if abs (x2 - x4) < 50 and abs (y2 - y4) < 50 then
a2 := a2 * -1
end if
if abs (x2 - x5) < 50 and abs (y2 - y5) < 50 then
a2 := a2 * -1
end if
if abs (x1 - x2) < 10 and abs (y1 - y2) < abs (d1 - y1)
then
a2 := a2 * -1
end if
if x2 < 0
then
x2 := Rand.Int (0, maxx)
y2 := Rand.Int (0, maxy)
end if
Mouse.ButtonChoose ("multibutton")
Mouse.Where (x, y, button)
left := button mod 10
middle := (button - left) mod 100
right := button - middle - left
if left = 1 then
y1 := y1 + b1
d1 := d1 + b1
end if
if middle = 10 then
end if
if right = 100 then
y1 := y1 - b1
d1 := d1 - b1
end if
end loop |
|
|
|
|
|
Sponsor Sponsor
|
|
|
The_Bean
|
Posted: Fri Sep 26, 2008 7:29 pm Post subject: Re: Creating my own pong game |
|
|
1-Use code tags
2-Indent (Ctrl+i)
3-Name variables something that other will know what they mean (especially when asking for help)
I'm still trying to figure out which variable are which but I'm thinking it's because of the method your using to check for a collision. |
|
|
|
|
|
S_Grimm
|
Posted: Fri Sep 26, 2008 7:40 pm Post subject: RE:Creating my own pong game |
|
|
comment on the code please. and procedures will make it much easier to write (at least in my opinon)... |
|
|
|
|
|
The_Bean
|
Posted: Fri Sep 26, 2008 7:50 pm Post subject: Re: Creating my own pong game |
|
|
I'm assuming your variables are:
1's are for the paddle
2's are for the ball
3's,4's,5's are for the obstacles
a's,b's are velocities at which things are moving
you have velocities for obstacles which aren't moving
you check to see if the non-moving obstacles 3 and 4 have gone out of bounds
your only changing the speed of the ball on the x-plane when it collides with an obstacle
and your collision detection doesn't make sense and I'm assuming its for squares not circles. |
|
|
|
|
|
adudeknownasz
|
Posted: Mon Sep 29, 2008 9:20 am Post subject: RE:Creating my own pong game |
|
|
Yeah, i know i have some extra stuff, ive been experimenting with some of the obstacles and such. just havent gotten around to taking them out yet. as for the variables...
x1,y1,d1,c1 are all for the paddle.
x2,y2 are for the ball
the rest of the x and y variables are for the obstacles.
the a and b variables control the speeds.
im not sure what code tags are....
i havent learned procedures yet either...
and how woudl i change the collision detection?
thanks, sorry its so confusing... |
|
|
|
|
|
S_Grimm
|
Posted: Mon Sep 29, 2008 10:16 am Post subject: RE:Creating my own pong game |
|
|
code tags are just comments (%...) as in put the "%" then words. Look in the tutorials for procedures. they will be very useful in pong... will this game use AI or two player? |
|
|
|
|
|
Clayton
|
Posted: Mon Sep 29, 2008 11:58 am Post subject: Re: Creating my own pong game |
|
|
Not quite A/V.
Code tags are ingenious little pieces of BBCode that allow your code to be posted, without the forums automagically formatting it such that it loses it's indentation, etc.
Code/Syntax tags are used as such:
[code]
Place code in here.
[/code]
Alternatively, you can use syntax tags to enable highlighting for your code, although only a limited number of languages are supported:
[syntax="language"]
Place language-specific code here.
[/syntax]
Just make sure that the language name is all lower case. |
|
|
|
|
|
S_Grimm
|
Posted: Tue Sep 30, 2008 10:13 am Post subject: RE:Creating my own pong game |
|
|
sorry. i know that too. i was totally brain dead yesturday... what i posted was commenting, which should still be used |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|