
-----------------------------------
who cares?
Sun Jul 06, 2003 4:49 pm

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.

-----------------------------------
krishon
Sun Jul 06, 2003 5:14 pm


-----------------------------------
which version of turing are u using?  that might be the problem, tho i doubt it

-----------------------------------
who cares?
Sun Jul 06, 2003 5:22 pm

I'm using...
-----------------------------------
I'm using version 4.0.4 c of Turing. I have the latest updates installed.

-----------------------------------
Asok
Sun Jul 06, 2003 5:26 pm


-----------------------------------
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
Sun Jul 06, 2003 5:28 pm


-----------------------------------
maybe it'll help if u put a procedure...i dunno if its necessary tho

-----------------------------------
Tony
Sun Jul 06, 2003 5:48 pm


-----------------------------------
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.

-----------------------------------
PaddyLong
Sun Jul 06, 2003 5:50 pm


-----------------------------------
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


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 = maxy - 4 then
        ychange := -ychange
    elsif y 