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

Username:   Password: 
 RegisterRegister   
 Pic.New doesn't work
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
who cares?




PostPosted: Sun Jul 06, 2003 4:49 pm   Post subject: Pic.New doesn't work

Hello,

I am trying to make a Pong game, and I am trying to use the Pic. New command in order to take a picture of the place where the ball is going to be, before it gets there and then paste it after the ball passes the place, so that I get a smooth motion, without having to clear the screen every time the ball moves. The problem is that when I use the Pic.New command, I get the message "Illegal pictured ID number '0'. (Probable cause: picture was not succesfully created.)." Here is my program:

-----------------------------------------------

setscreen ("graphics")

var x, y : int
var xchange, ychange : int
var pic1 : int

x := 0
y := 0
xchange := 1
ychange := 1

Draw.FillBox (0, 0, maxx, maxy, black)

loop
if
x > 639
then
xchange := -xchange
elsif
x < 0
then
xchange := -xchange
end if
if
y > 399
then
ychange := -ychange
elsif
y < 0
then
ychange := -ychange
end if
x := x + xchange
y := y + ychange
pic1 := Pic.New (x - 4, y - 4, x + 4, y + 4)
Draw.FillBox (x - 4, y - 4, x + 4, y + 4, white)
Pic.Draw (pic1, x, y, picCopy)
delay (5)
end loop

-----------------------------------------------

Any help would be appreciated. Thank you very much.
Sponsor
Sponsor
Sponsor
sponsor
krishon




PostPosted: Sun Jul 06, 2003 5:14 pm   Post subject: (No subject)

which version of turing are u using? that might be the problem, tho i doubt it
who cares?




PostPosted: Sun Jul 06, 2003 5:22 pm   Post subject: I'm using...

I'm using version 4.0.4 c of Turing. I have the latest updates installed.
Asok




PostPosted: Sun Jul 06, 2003 5:26 pm   Post subject: (No subject)

k Pic.New shouldn't be in the loop, because the picture is a constant. only the location (Pic.Draw) changes.

The whole thing needs to be restructured. Store the pic then draw it.
krishon




PostPosted: Sun Jul 06, 2003 5:28 pm   Post subject: (No subject)

maybe it'll help if u put a procedure...i dunno if its necessary tho
Tony




PostPosted: Sun Jul 06, 2003 5:48 pm   Post subject: (No subject)

might be faster if you keep the whole background in the memory, this way you dont have to use Pic.New inside the loop and should also speed up your game.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
PaddyLong




PostPosted: Sun Jul 06, 2003 5:50 pm   Post subject: (No subject)

well unless you are going to have something in the background other than just black, it would likely be easier to simply draw a small black box over it rather than using Pic

any way... here is what you want if you want to use the Pic method
(also note I started the ball at 10,10 rather than 0,0 this is because you are trying to take a pic at x - 4 and y - 4 so it would be trying to take a pic from -4,-4 to 4,4) I also modified your if statements for changing the directions so that they'll work better and also commented the stuff for the drawing/erasing so hopefully you can understand what is going on with it

code:

setscreen ("graphics")

var x, y : int
var xchange, ychange : int
var pic1 : int

x := 10
y := 10
xchange := 1
ychange := 1

Draw.FillBox (0, 0, maxx, maxy, black)
pic1 := Pic.New (x - 4, y - 4, x + 4, y + 4)
Draw.FillBox (x - 4, y - 4, x + 4, y + 4, white)
loop
    if x >= maxx - 4 then
        xchange := -xchange
    elsif x <= 4 then
        xchange := -xchange
    end if
    if y >= maxy - 4 then
        ychange := -ychange
    elsif y <= 4 then
        ychange := -ychange
    end if
    Pic.Draw (pic1, x - 4, y - 4, picCopy) %erase the ball BEFORE changing the x and y
    x := x + xchange
    y := y + ychange
    Pic.Free (pic1) %free the old image
    pic1 := Pic.New (x - 4, y - 4, x + 4, y + 4) %take a new image
    Draw.FillBox (x - 4, y - 4, x + 4, y + 4, white) %draw the ball
    delay (5)
end loop
PaddyLong




PostPosted: Sun Jul 06, 2003 5:56 pm   Post subject: (No subject)

also, if you want it to run smoother add in setscreen("offscreenonly")
and after
code:

 Â  pic1 := Pic.New (x - 4, y - 4, x + 4, y + 4) %take a new image
    Draw.FillBox (x - 4, y - 4, x + 4, y + 4, white) %draw the ball

but before the delay put in View.Update

this will elminate the small flickering of the ball that you notice
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Sun Jul 06, 2003 7:40 pm   Post subject: (No subject)

doesn't turing only allow so many pics to be declared? then if you declare it in a loop, then it's going to run out of space, and you get an error that way...
who cares?




PostPosted: Sun Jul 06, 2003 8:20 pm   Post subject: Thank you

Thank you all for your help. I have found a way to do it, but your code is better. Thank you for it. Oh well, I am just a begginer in Turing. Thank you all for your help.
PaddyLong




PostPosted: Sun Jul 06, 2003 10:17 pm   Post subject: (No subject)

yes Asian, that's why the Pic.Free is there
AsianSensation




PostPosted: Mon Jul 07, 2003 8:26 am   Post subject: (No subject)

oh, heh heh, didn't see it....

oh well, sorry about 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 1  [ 12 Posts ]
Jump to:   


Style:  
Search: