
-----------------------------------
skier
Fri Oct 22, 2004 8:03 pm

help with polygons
-----------------------------------
this is for a pacman game. im trying to make the ghost so that it is easy to mave what am i doing wrong? i get an error    "compile time expression expected" :x 


heres the code:

View.Set ("graphics")

var x, y : int
x := 300
y := 200


var x1 : array 1 .. 11 of int := init (x - 8, x - 8, x - 6, x - 4, x - 2, x, x + 2, x + 4, x + 6, x + 8, x + 8)

var y1 : array 1 .. 11 of int := init (y, y - 20, y - 22, y - 20, y - 22, y - 20, y - 22, y - 20, y - 22, y - 22, y)

Draw.FillPolygon (x1, y1, 11, black)
Draw.FillOval (x, y, 8, 6, black)


-----------------------------------
skier
Fri Oct 22, 2004 8:10 pm


-----------------------------------
the last number for "x1" is 8 then )

-----------------------------------
skier
Fri Oct 22, 2004 8:16 pm


-----------------------------------
any body 




this is realy important



ergent

-----------------------------------
zylum
Fri Oct 22, 2004 9:37 pm


-----------------------------------
im assuming that x and y are variables.... thats why you get the error. when you initialize arrays you can only use constants or numbers. if your using variables, you need to manually input the data ie


x1(1) := x + 1
y1(1) := y + 1
x1(2) := x + 8
y1(2) := y + 8

//etc...


-----------------------------------
Tony
Fri Oct 22, 2004 9:48 pm


-----------------------------------
there also seems to be a pattern in your coordinates, so you might employ a forloop... or just copy paste (although that's a bad practice)

bottom line:
replace var x,y:int with

const x : int := 300
const y :int := 200


-----------------------------------
skier
Sat Oct 23, 2004 8:13 am


-----------------------------------
but to make this ghost move there must be an increase in the x's and y's.
if it is a constant i can not do so.

-----------------------------------
Cervantes
Sat Oct 23, 2004 9:36 am


-----------------------------------
as tony said, there is a pattern to your x1 and y1 array.  You can make use of that patter:

var x := 300
var y := 200

var x1 : array 1 .. 11 of int
for i : 2 .. 10
    x1 (i) := x + (i * 2 - 12)
end for
x1 (1) := x - 8
x1 (11) := x + 8

for j : 1 .. 11
    put x1 (j)
end for

That will be even more helpful because I imagine you are going to have to change the x1 array each time through the loop.
