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

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




PostPosted: Thu Dec 07, 2006 10:09 am   Post subject: pic rotate help

code:
setscreen ("offscreenonly")
var angle : int := 0
var velx, vely := 0
var chars : array char of boolean
var pic : int
pic := Pic.FileNew ("ship.bmp")

loop
    Input.KeyDown (chars)
    View.Update
    delay (30)
    cls
    Pic.Draw (pic , 100, 100, picCopy)
    pic := Pic.Rotate (pic, angle, 23, 33)
    if chars (KEY_LEFT_ARROW) then
        angle := 10
    elsif chars (KEY_RIGHT_ARROW) then
        angle := -10
    else
        angle := 0
    end if
end loop


when i run it, if i press the arrow key (other than the pic looking bad), it gives me an error after a few seconds it gives me this error
"illegal picID number "0" (probable cause picture was not successfully created)"

anyone know how to fix it?
Sponsor
Sponsor
Sponsor
sponsor
NikG




PostPosted: Thu Dec 07, 2006 3:44 pm   Post subject: Re: pic rotate help

shoobyman wrote:
code:
setscreen ("offscreenonly")
var angle : int := 0
var velx, vely := 0
var chars : array char of boolean
var pic : int
pic := Pic.FileNew ("ship.bmp")

loop
    Input.KeyDown (chars)
    View.Update
    delay (30)
    cls
    Pic.Draw (pic , 100, 100, picCopy)
    pic := Pic.Rotate (pic, angle, 23, 33)
    if chars (KEY_LEFT_ARROW) then
        angle := 10
    elsif chars (KEY_RIGHT_ARROW) then
        angle := -10
    else
        angle := 0
    end if
end loop

Your code is kinda all-over-the-place, and I'm almost positive that's why you're getting the error. Here's a cleaner (and probably less error prone) version:
code:
loop
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then
        angle := 10
        pic := Pic.Rotate (pic, angle, 23, 33)
    elsif chars (KEY_RIGHT_ARROW) then
        angle := -10
        pic := Pic.Rotate (pic, angle, 23, 33)
    else
        angle := 0
        pic := Pic.Rotate (pic, angle, 23, 33)
    end if

    Pic.Draw (pic , 100, 100, picCopy)
    View.Update
    delay (30)
    cls
end loop
Your order of command was weird. Why would you update an empty screen, delay, clear the screen, then draw the pic, then change the angle??? Also, notice how I made it change the angle only if there is input?
NikG




PostPosted: Thu Dec 07, 2006 3:47 pm   Post subject: (No subject)

Actually, now I know why you're gettin the error.
It's because of your else clause in the if statement. Remove it!

You shouldn't get the error with my code anymore, but it's not proper.
And it doesn't make sense to keep resetting the angle to 0 if there's no input.
shoobyman




PostPosted: Thu Dec 07, 2006 5:51 pm   Post subject: (No subject)

thanks, everything works (and I fixed the ungly picture problem)
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  [ 4 Posts ]
Jump to:   


Style:  
Search: