Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to make ball start on paddle.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gergysun




PostPosted: 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
Sponsor
sponsor
HeavenAgain




PostPosted: 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! Smile
gergysun




PostPosted: 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




PostPosted: 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 : array char of boolean
        Input.KeyDown (chars)
        if chars ('t') then
            put "The T key is pressed"
        end if

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




PostPosted: Wed Dec 05, 2007 2:37 pm   Post subject: Re: how to make ball start on paddle.

Very Happy 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




PostPosted: 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




PostPosted: 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




PostPosted: 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 Smile 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
Sponsor
sponsor
gergysun




PostPosted: 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 Very Happy 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




PostPosted: 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




PostPosted: 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




PostPosted: 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 Wink play around with your code and logic a bit, a great way to learn Mr. Green
Nick




PostPosted: 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




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 29 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: