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

Username:   Password: 
 RegisterRegister   
 [Tutorial] Character control on screen (Input.KeyDown)
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2, 3, 4, 5  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
harishmabish




PostPosted: Sat Mar 29, 2008 9:40 am   Post subject: Re: [Tutorial] Character control on screen (Input.KeyDown)

so how would you move a picture?
Sponsor
Sponsor
Sponsor
sponsor
Mackie




PostPosted: Sat Mar 29, 2008 10:03 am   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

Wow, old post. Use the same method. Instead of drawing a circle, you can draw an image.

code:
Draw.Oval(x, y, 4, 4, red)


code:
Pic.Draw (pictureID, x, y, picMerge)
tianxiao




PostPosted: Tue Jan 13, 2009 12:01 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

what is the name for spacebar in Input.KeyDown? like KEY_UP_ARROW is for up arrow key. What is it for spacebar?
corriep




PostPosted: Tue Jan 13, 2009 3:01 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

instead of key (KEY_UP_ARROW) just use key (' ')
Savage Reindeer




PostPosted: Tue Apr 28, 2009 2:34 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

I'm making a DDR game and when I hold the button down changes whether the user got a bad, good, perfect, or missed hit. How can I make it use whatever space it was in the instant that the key was pressed and no other?

perhaps I should make a help topic...
saltpro15




PostPosted: Tue Apr 28, 2009 2:39 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

yes, you definitely should instead of reviving old threads, put it in the Turing Help forum please
wadler64




PostPosted: Sun Mar 03, 2013 1:07 pm   Post subject: Re: [Tutorial] Character control on screen (Input.KeyDown)

i dont get the input.down thing
Insectoid




PostPosted: Sun Mar 03, 2013 1:22 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

chars is a special array of booleans that correspond to each key on the keyboard. When you call Input.KeyDown(chars), the booleans that correspond to the keys that are pressed are set to true. The unpressed keys are set to false. Remember that it doesn't update itself; it only shows the key states at the time Input.KeyDown was called.

Then you can check which keys are pressed by passing the key value or a character as the array index to chars. chars('a') returns 1 if a is pressed. chars('A') returns 1 if shift-a is pressed. chars(KEY_UP_ARROW) is the up arrow key.

Usually this is used in a loop. At the top of the loop, you call Input.KeyDown to get the key states. Then you reference chars to decide what to do. For example, if chars (KEY_UP_ARROW) = 1, move up 5 pixels.
Sponsor
Sponsor
Sponsor
sponsor
Insertname




PostPosted: Sat Mar 09, 2013 2:22 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

*Sorry if this post shouldn't be here, anyway...

Is there any way to move an object without clearing the screen constantly? For, let's say, a brickbreaker style game, or pong?

If so, how would one go about doing such a thing?

I've seen some people either draw over the box with the background colour or use some kind of special command that's alien to me, "Draw.Cls ()"

Thanks
Raknarg




PostPosted: Sat Mar 09, 2013 6:13 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

Im pretty sure Draw.Cls is the same as cls.

You could draw over the object if you wanted to. for instance:

Turing:

setscreen ("offscreenonly")

var dx : int := Rand.Int (-5, 5)
var dy : int := Rand.Int (-5, 5)
var x : int := Rand.Int (0, maxx)
var y : int := Rand.Int (0, maxy)

loop
    x += dx
    y += dy
   
    if x > maxx then
        dx *= -1
        x := maxx
    elsif x < 0 then
        dx *= -1
        x := 0
    end if
   
    if y > maxy then
        dy *= -1
        y := maxy
    elsif y < 0 then
        dy *= -1
        y := 0
    end if
   
    Draw.FillOval (x, y, 10, 10, brightblue)
    View.Update
    Draw.FillOval (x, y, 10, 10, white)
end loop


However usually it's a lot faster on the machine to just clear the screen rather than calculating object drawings each time, if you have enough objects. Boxes are much easier to draw than circles.
Insertname




PostPosted: Sat Mar 09, 2013 6:47 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

By clearing the screen, as shown in this tutorial, it would also clear other things that aren't meant to be cleared. For instance, Player 2's pong paddle or bricks in super breakout.

Would there be a way to use what was said in this tutorial, but without fully clearing the screen or redrawing everything constantly?

Is there a command that only clears certain objects at a time or certain areas of the screen?
I have a feeling View.UpdateArea will make an appearance. ?
Insectoid




PostPosted: Sat Mar 09, 2013 7:05 pm   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

You should be re-drawing everything every frame. With well-constructed draw procedures you just need to throw it all in the main loop and forget about it.

If your background is white and your character is a box or circle, it makes sense to just draw a white box/circle over where the character used to be. But if you have a more complicated scene with a background picture and lots of things moving around, this becomes impractical because A)you can't just draw a white box over the background picture. That looks terrible, and B), you'll inevitably end up drawing your white box over another moving thing, which also looks terrible. At this point, it really is much, much easier to clear everything and redraw the whole scene every frame.
jesse kazomi




PostPosted: Tue Jun 17, 2014 5:02 pm   Post subject: Re: [Tutorial] Character control on screen (Input.KeyDown)

This is so cool
klarakos




PostPosted: Fri Aug 01, 2014 5:17 am   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

hey, can sumone tell me a way of achieving a 'magnetic' sort of effect. For example, I have a object/picture which is under the control of the user, and when the user presses a certain button, i want the object/picture to automatically move to a set area, say one side of the screen.
Insectoid




PostPosted: Sun Aug 03, 2014 7:07 am   Post subject: RE:[Tutorial] Character control on screen (Input.KeyDown)

Sure. If the user pushes that button, just set the object's coordinates to whatever spot you want.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 4 of 5  [ 63 Posts ]
Goto page Previous  1, 2, 3, 4, 5  Next
Jump to:   


Style:  
Search: