Something i dont understand, my teacher cant help
Author |
Message |
Meroku
|
Posted: Tue Jun 13, 2006 8:19 am Post subject: Something i dont understand, my teacher cant help |
|
|
My friend send me a pacman program in Turing just for fun.
I really like to know how he did it his very good at Turing,
So i have some codes here i tried everythnig i just have no idea how he did it.
Could you do help me understand this, someone explain it to me i would greatly appreciat that.
%Draw Walls
var box1x : array 1 .. 49 of int := init (0, 0, 0, 490, 0, 480, 50, 140, 190, 240, 290, 340, 0, 440, 50, 90, 140, 290, 390, 390, 0, 90, 0, 140, 190, 240, 340, 390, 390, 400, 0, 90, 0, 390, 390, 390,
Ok so i dont know if u can see this but he basicly made 4 Arrays like this one. This is an Array with very long numbers. and this part drwas the walls in the pacman game the walls look very nice and just like in the real game.
how did he draw a wall from using a number array?
Thanks for reading my post i appreciat any help i can get |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Omnipotence
|
Posted: Tue Jun 13, 2006 8:47 am Post subject: (No subject) |
|
|
I assume that your friend used Draw.Polygon to draw the walls? ASSUMING that it was done using Draw.Polygon
there should be a line that looks something like
Draw.Polygon (firstarray, secondarray, arraysize, color)
Basically, the array you posted contains a long list of coordinates. Using two arrays, he could draw a line that goes in different directions corresponding to the many different coordinates. I assume he used 4 arrays to make two of such lines.
e.g
var box1x : array 1 .. 49 of int := init (0, 0, 0, 490, 0, 480, 50, 140, 190, 240, 290, 340, 0, 440, 50, 90, 140, 290, 390, 390, 0, 90, 0, 140, 190, 240, 340, 390, 390, 400, 0, 90, 0, 390, 390, 390,
var box1y : array 1 .. 49 of int := init (0, 0, 0, 490, 0, 480, 50, 140, 190, 240, 290, 340, 0, 440, 50, 90, 140, 290, 390, 390, 0, 90, 0, 140, 190, 240, 340, 390, 390, 400, 0, 90, 0, 390, 390, 390,
Draw.Polygon (box1x, box1y, 49, black)
box1x has the long list of xcoordinates and box1y has the long list of ycoordinates. The draw would go through all of these and draw lines from one point to the other. |
|
|
|
|
|
Meroku
|
Posted: Tue Jun 13, 2006 11:41 am Post subject: (No subject) |
|
|
Thanks a bunch i get it now the 2 lines of arrays form a box
and he used 4 arrays so that makes up the whole pacman maze. Ill draw this way now the results look very nice |
|
|
|
|
|
Meroku
|
Posted: Tue Jun 13, 2006 11:50 am Post subject: (No subject) |
|
|
Theres another this in the program I'de like to figure out. Thanks again for helping me with the number array. But this one is different, this next thing im going to show you is the best thing in my pacman program. It makes the pacman open and cloth his mouth as he moves its amazing.
%Draw mouth close
procedure drawMouthClose (x : int, y : int)
MouthAngle := MouthAngle mod 45 + 1
drawfillarc (x, y, PACMAN_RADIUS, PACMAN_RADIUS, MouthAngle + direction, -MouthAngle + direction, 14)
end drawMouthClose
short line of codes but how did he make the pacman open and close his mouth?
if you can help me with this i would apprecia it |
|
|
|
|
|
Omnipotence
|
Posted: Tue Jun 13, 2006 12:41 pm Post subject: (No subject) |
|
|
procedure drawMouthClose (x : int, y : int)
MouthAngle := MouthAngle mod 45 + 1
drawfillarc (x, y, PACMAN_RADIUS, PACMAN_RADIUS, MouthAngle + direction, -MouthAngle + direction, 14)
end drawMouthClose
The procedure here works with something else probably. Your friend would call on the procedure with the coordinates of the pac man, for example drawMouthClose (50, 50). Once the program knows where the pac man is, it will draw a filled in arc over the circle pac man. The arc would probably be the same colour as the background thus making it look as though the circle pacman is missing a part, thus its mouth.
So the program would switch between drawing the full circle and then drawing this arc over the circle making the illusion that the mouth is opening and closing.
It would go like this:
Draw Pac Man
(Some form of delay)
Draw Filled in Arc over Pac Man (Will look like mouth opens)
(Some form of delay)
Move Pac Man
Repeat
As for the MouthAngle, that just tells the program how big an arc to draw over the pacman and in which direction it would draw. |
|
|
|
|
|
Meroku
|
Posted: Tue Jun 13, 2006 12:55 pm Post subject: (No subject) |
|
|
You sir are my Turing hero thank you again |
|
|
|
|
|
Remm
|
Posted: Tue Jun 13, 2006 1:06 pm Post subject: (No subject) |
|
|
Okay, lucky I accidentally backspaced and deleted everything I had written before, because I read it again and have a better understanding of what your doing.
However, my first point still sticks. If you need to know how to do somthing / how someone else did somthing, check out the Turing Walkthrough first. If you need to know how he did it, you might as well find out how the heck the stuff works in itself. Not sure if you already checked there, but if you havnt, you should. It may answer some questions that are coming up so you arnt continuously searching through your friends code with a firm frown. |
|
|
|
|
|
Clayton
|
Posted: Tue Jun 13, 2006 4:39 pm Post subject: (No subject) |
|
|
also plz use [code ][/code] tags when posting code to make it easier to read. Also you should check out the [Turing FAQ] as it contains some answers to common questions, see if that helps you with anything and yes check the Turing Walkthrough for things that you dont understand (ex. arrays ) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|