Computer Science Canada

help with polygons

Author:  skier [ Fri Oct 22, 2004 8:03 pm ]
Post subject:  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" Mad


heres the code:
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)

Author:  skier [ Fri Oct 22, 2004 8:10 pm ]
Post subject: 

the last number for "x1" is 8 then )

Author:  skier [ Fri Oct 22, 2004 8:16 pm ]
Post subject: 

any body




this is realy important



ergent

Author:  zylum [ Fri Oct 22, 2004 9:37 pm ]
Post subject: 

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

code:

x1(1) := x + 1
y1(1) := y + 1
x1(2) := x + 8
y1(2) := y + 8

//etc...

Author:  Tony [ Fri Oct 22, 2004 9:48 pm ]
Post subject: 

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
code:

const x : int := 300
const y :int := 200

Author:  skier [ Sat Oct 23, 2004 8:13 am ]
Post subject: 

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.

Author:  Cervantes [ Sat Oct 23, 2004 9:36 am ]
Post subject: 

as tony said, there is a pattern to your x1 and y1 array. You can make use of that patter:
code:

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.


: