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

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




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
skier




PostPosted: Fri Oct 22, 2004 8:10 pm   Post subject: (No subject)

the last number for "x1" is 8 then )
skier




PostPosted: Fri Oct 22, 2004 8:16 pm   Post subject: (No subject)

any body




this is realy important



ergent
zylum




PostPosted: Fri Oct 22, 2004 9:37 pm   Post subject: (No 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...
Tony




PostPosted: Fri Oct 22, 2004 9:48 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
skier




PostPosted: Sat Oct 23, 2004 8:13 am   Post subject: (No 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.
Cervantes




PostPosted: Sat Oct 23, 2004 9:36 am   Post subject: (No 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.
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  [ 7 Posts ]
Jump to:   


Style:  
Search: