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

Username:   Password: 
 RegisterRegister   
 Keys
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
metachief




PostPosted: Sat Oct 11, 2008 11:56 am   Post subject: Keys

I have a problem with a shooter I am making. I am trying to make a pistol fire when I press the space bar, but instead of firing once it is continuous until I release the space bar. So how would I make it so that it only fires once when I press space bar ( or in other cases other keys as well ) ?
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Sat Oct 11, 2008 2:27 pm   Post subject: RE:Keys

Check to see if just before you would shoot the bullet, the spacebar (or whatever key you are using) was up (ie. not pressed). If it wasn't pressed during the last iteration of your loop, then check if it's down, if it is, shoot, otherwise, don't shoot. You'll also have to make sure that you have some variable that keeps track of pressed status.
metachief




PostPosted: Sat Oct 11, 2008 2:48 pm   Post subject: RE:Keys

I made it work, but I'm not sure if there is a better way of doing it. Mine's kinda long. If anyone has a shorter way, please tell me.

Turing:


setscreen ("offscreenonly")

var key : array char of boolean

var count : int := 0

var pressed : boolean := false

loop
    Input.KeyDown (key)

    pressed := key (' ')

    if key (' ') then
        count += 1
        if count < 10 then
            drawfilloval (maxx div 2, maxy div 2, 10, 10, green)
        end if
    end if

    if not pressed then
        count := 0
    end if

    View.Update
    cls
end loop

Clayton




PostPosted: Sat Oct 11, 2008 5:15 pm   Post subject: RE:Keys

play around with this:

Turing:

var pressed : boolean := false
var keys : array char of boolean

loop
    Input.KeyDown (keys)
   
    if keys (' ') and ~pressed then
        Draw.FillOval (maxx div 2, maxy div 2, 10, 10, Rand.Int (1, maxcolor))
        pressed := true
    elsif ~keys (' ') and pressed then
        pressed := false
    end if
end loop
metachief




PostPosted: Sat Oct 11, 2008 6:35 pm   Post subject: RE:Keys

Oh, thank you! That's much better.
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 1  [ 5 Posts ]
Jump to:   


Style:  
Search: