Posted: Tue Dec 04, 2007 9:18 pm Post subject: how to make ball start on paddle.
Heyu guys, ive changed my menu alot and it would be nice if the user to press spacebar to start the ball, with its beginning possition on the paddle...ive looked at other pong games, and most of them dont have it
I was wondering of how to do so...
Can anyone help me out?
Sponsor Sponsor
HeavenAgain
Posted: Tue Dec 04, 2007 9:29 pm Post subject: RE:how to make ball start on paddle.
its really easy..... just add ,
if the input key down is space then your game code here,
else if input key down is left, then move the ball + the paddle left,
else if input key down is right, then move the ball + the paddle right,
simple? yes!
gergysun
Posted: Tue Dec 04, 2007 9:54 pm Post subject: Re: how to make ball start on paddle.
ok, im moving the paddle with the mouse, does that make any difference..to what u just said?
im not sure how to start off the Input.Keydown thing, concidering ive never looked at it before.
what would i type?
HeavenAgain
Posted: Wed Dec 05, 2007 11:30 am Post subject: RE:how to make ball start on paddle.
Quote:
ok, im moving the paddle with the mouse, does that make any difference..to what u just said?
nope, no big difference
Turing:
var chars :arraycharofboolean Input.KeyDown(chars) if chars ('t')then put"The T key is pressed" endif
i copyed this straight from the f10 help, all you have to change is make the t into space, and replace "put "the T key is pressed" with your game code.
and elsif check mouse's x position, and move your paddle + ball
gergysun
Posted: Wed Dec 05, 2007 2:37 pm Post subject: Re: how to make ball start on paddle.
Awsome!
the only thing is that i have to hold down the space bar to continue the game...like what i mean is that the ball wont start until i press the spacebar (good) but i have to keep holding it for the game to run smoothly....im not sure if i explained that correctly or not...
HeavenAgain
Posted: Wed Dec 05, 2007 7:34 pm Post subject: RE:how to make ball start on paddle.
you have to keep on holding it? thats odd, you just have to add that if statment before the WHOLE game code, not somewhere in the game code
So it acts as a "gate keeper" before the player can acually start the game, is that they must press space at the beginninng, before they enter the game, get what i mean?
gergysun
Posted: Wed Dec 05, 2007 8:29 pm Post subject: Re: how to make ball start on paddle.
well, i got it somewhat fixed..i dont have to hold up arrow anymore, but what is done now is when you press it, it resets the ball into the centre...what i want it to do it that when i start the game, the ball is on the paddle and i have to press up arrow to start the ball moving. Using your method, how would i do that?
here is my code, if it makes u understand what i just said a bit better...
Code edited out at OP's request.
HeavenAgain
Posted: Wed Dec 05, 2007 8:47 pm Post subject: RE:how to make ball start on paddle.
ok, i have no idea why the up arrow is there in the first place, i mean, you dont even need to use up arrow to play pong.... so.... errr
ok, i wont look through your code, because i am lazy but i'll explain it this way, again
code:
loop
{
if space is pressed
{
your game code here
exit game's loop when player lose % so it goes back to the main loop
}
else if mouse or left right arrow is moved
{
move your paddle accordingly
}
}
Sponsor Sponsor
gergysun
Posted: Wed Dec 05, 2007 8:57 pm Post subject: Re: how to make ball start on paddle.
alright. And the reason i put the up arrow in there cause i 2 was lazy...to find the text for the spacebar so i used the up arrow.
and when u say mouse, u mean ( from my code) .......x - 40 and x + 40?
so.. like this..?
code:
loop %begins main loop
Input.KeyDown (chars)
if chars (KEY_UP_ARROW) then
% full game code
exit when score1 = scoremax
elsif x - 40 and x + 40 then
end if
end loop
HeavenAgain
Posted: Wed Dec 05, 2007 9:11 pm Post subject: RE:how to make ball start on paddle.
nop nop nop , that doesnt give you anything, you are checking for where the mouse is, i think the code is mousewhere, and check if the x value of the mouse changed from the orginal paddle's position, get the idea?
gergysun
Posted: Wed Dec 05, 2007 9:22 pm Post subject: Re: how to make ball start on paddle.
sooo i use
code:
Mouse.Where (x, y, button)
and i dont understand what you mean by "check if the x value of the mouse changed from the orginal paddle's position"
my paddle does not show up in my same spot everytime the game starts, it whereever ur cursor is on the window.
HeavenAgain
Posted: Wed Dec 05, 2007 10:02 pm Post subject: RE:how to make ball start on paddle.
OHH, well in that case... i have made some silly mistake in explainning... first, obviously you gotta draw out the stuffs.... and whenever mouse position changes, you have to update the paddle, if this makes more sense to you.... implement it in your code and see what happens; try first then if you dont understand then ask play around with your code and logic a bit, a great way to learn
Nick
Posted: Wed Dec 05, 2007 10:38 pm Post subject: RE:how to make ball start on paddle.
code:
var mx,my,oldx,oldy,b:int:=0
loop
Mouse.Where(mx,my,mb)
if mx not = oldx or my not = oldy then
mouse moved
end if
oldx:=mx
oldy:=my
end loop
gergysun
Posted: Thu Dec 06, 2007 3:21 pm Post subject: Re: how to make ball start on paddle.
ok, so do i put the key down thing before or after the mouswhere below?
and what would i tpye for "mouse moved" in the below code?
code:
var x,y,oldx,oldy,b:int:=0
loop
Mouse.Where(x,y,mb)
if x not = oldx or y not = oldy then
mouse moved
end if
oldx:=x
oldy:=y
end loop
Does oldy and oldx have to be present anywhere else in the code?
HeavenAgain
Posted: Thu Dec 06, 2007 5:26 pm Post subject: RE:how to make ball start on paddle.
if you are using mouse to play the game, there isnt much point for input key down, cept for the starting part (which i hope you get it)
and as for the old and new x and y, you certain will live without the old, because you are simply drawing the paddle base on your mouse's x and y right? (thats how i understands it) so just check mouse where, and draw the paddle according to the x and y, simple as that