[Thread Prev] [Thread Next]
The following code was created by zehava, now I'll try to add comments with
///'s on the code to parts of the code that I understand of parts that I
don't, if anybody finds anything that I might have misunderstood please
correct me. Can someone please explain to me what some of the parts of the
code are doing. I'm trying to recreate the snake game, but I'm having
trouble understanding some parts. As I will need to make the newly created
turtle "tail" to make the snake look like its growing as it goes I will
attach what I have so far
to go
make "queue [] make "h 90
/// makes a variable named "queue" which assigns its value back to 0 or
nothing that's why it has the brackets since later on the code queue is made
into a list you have to assign it back so it has no value, also makes a
variable for heading
Cc
///Clears the command console, but why?
carefully[newturtle "head][]
///creates a new turtle if not yet added to the stage, if it has been added
it will create no error that's why it has the blank brackets
carefully [turtlesown "posh][]
/// creates a individual variable for each turtle, but why didn't head get
assigned this variable as well? Also i didn't know posh was position and
heading at the same time... why isn't in microworlds vocabulary?
Follow
/// launches a new procedure
forever[path]
/// same as above, except it's forever*
forever[direct]
/// *
end
to make.queue
dolist[i get "page1 "turtles]
/// creates a list and is assigned to a temporally variable "i" gets all the
turtles that are on page one
[tto :i
/// talks to all the turtles on the stage
make "queue lput list pos heading :queue]
/// creates a separate variable that is going to be used later in the final
output, "lput" puts the first x,y cord of the first turtle at the end of the
list?? Then creates a list? With position and heading? :queue??? What is
the final :queue for?
op bl :queue
/// outputs the list, excluding the last item? Of queue?
end
to follow
make "queue make.queue
/// this is going to redefine the value of "queue" once the procedure is
completed to create a new value, in this case a list
dolist[i bf get "page1 "turtles]
/// recreates the list to be used to set the position of each individual
turtle and runs for ever as below
[forever
[tto :i
setposh item bf :i :queue
/// sets the position of each item or turtle in this case excluding the
first which in microworlds would be head, :i??? :queue????
seth last posh setpos first posh
/// ??????????????????????????????????????????????
]
]
end
to path
head,
seth :h fd 15 wait 1
make "queue fput list pos heading bl :queue
end
Julio C. Dominguez
Attachment:
Snake_game.mw2
Description: Binary data
Previous by thread:
new OpenWorld Learning video!
Next by thread:
Re: explain
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|