[Thread Prev] [Thread Next]
<?xml version="1.0" encoding="ISO-8859-1"?>
Hi,
The problem is (probably) that ?heading? is reporting the heading of the
?current? turtle, which is
* the last turtle that you have created
* or the last turtle that you clicked on
* or the last turtle that you?ve ?talked to? using ?tell? or the ?comma?
syntax (t1,)
To solve this, you can use ?ask? which will address the turtle that you
specify, without changing the ?current? turtle. That?s the big diff between
?ask? and ?tell?.
Try this (given that the ball?s name is ?ball?)
make "ballheading ask ?ball [heading]
Or, just for the sake of testing this theory, type
show heading
show ask ?ball [heading]
The first instruction should show the heading of the current turtle. The
second instruction? you guessed right.
Good luck
A
-----Original Message-----
From: mwforum-admin@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
[mailto:mwforum-admin@xxxxxxxxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Doug
Alexander
Sent: Wednesday, November 14, 2007 3:24 PM
To: MWForum@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Subject: Coding breakout paddle
A student and I are attempting to code a breakout game, but we're running
into a couple of issues with the bouncing code.
With the paddle, we've divided it into three sections, each one a turtle -
left, center, and right. The left and right paddles need to reverse the
ball's heading plus angle it a bit more toward the horizontal, while the
center does a standard reflection of the heading. However, we want to test
the ball's heading when it hits the left paddle (for example) so that if
it's approaching on a heading of 95-180, it gets reversed back toward the
wall and then some, but if it approaches from the right or too shallowly
from the left, it just reflects. The code we have looks like:
to bounceLeftPaddle
make "ballheading heading
ifelse and (greater? ballheading 95) (less? ballheading 180)
[ball, seth 90 - (ballheading - 350)]
[ball, seth 90 - (ballheading - 45)]
end
Trouble is, saving the ball's heading to a variable "ballHeading" isn't
working. What's the right syntax? Do you think this approach could be
improved altogether?
Thanks,
Doug
--
Doug Alexander
Director of Academic Technology
Lincoln School
401-331-9696 x3137
Previous by thread:
Coding breakout paddle
Next by thread:
RE: Whack a mole
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.
|