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

Username:   Password: 
 RegisterRegister   
 Help with Sprites and Getch
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MichaelM




PostPosted: Thu Jun 21, 2007 2:32 pm   Post subject: Help with Sprites and Getch

Im making a game with a helicopter that'll move around when you press w,a,s,d. In the animation, the sprite moves up and down to give a better helicopter effect
as it bobs up and down. However, I cant figure out how to get it to move like that even when you arent pressing anything. Heres the code, right now it moves left only.
code:

setscreen ("graphics:1024;768")
var left1, left2, x : int
x := 0
var sprite : int
var ch : string (1)

left1 := Pic.FileNew ("heli-left1.bmp")
left2 := Pic.FileNew ("heli-left2.bmp")

sprite := Sprite.New (left1)

Sprite.SetPosition (sprite, 100, 100, true)
Sprite.SetHeight (sprite, 1)

Sprite.Show (sprite)


loop
    if hasch then
        getch (ch)
        if ch = "a" then
            x := x + 10
            delay (500)
            Sprite.Animate (sprite, left2, 100 - x, 100, false)
            delay (500)
            Sprite.Animate (sprite, left1, 100 - x, 102, false)
        end if
    end if
end loop

Could someone please show me how to do this, and were to put it in this code, thanks! Smile
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jun 21, 2007 4:10 pm   Post subject: RE:Help with Sprites and Getch

Well the problem is that your entire animation is wrapped in if hasch, so nothing will happen if no keys are pressed.

Normally Input.KeyDown is recommended for handling input. At least take the animation out of the if structure and run it every time, but if no keys are pressed, x will simply remain itself.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MichaelM




PostPosted: Thu Jun 21, 2007 4:32 pm   Post subject: Re: Help with Sprites and Getch

thanks, ill try that, but im running Turing 3.1 or something, so Input.KeyDown and stuff might not work, but ill try it out
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  [ 3 Posts ]
Jump to:   


Style:  
Search: