×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Random bird

Random bird

Random bird

(OP)
Hi do you know which code i should use in order to make a bird fly around the screen randomly and without leaving the screen


Thanks a lot!!!

RE: Random bird

There are many ways, but here's one example:

CODE

-- Behaviour script attached to a Sprite
property pSprite
property pSpeed
property pIdle
property pStageWidth, pStageHeight
property pCounter
property pLimit
property pVector

on beginSprite me
  pSprite = sprite(me.spriteNum)
  pSpeed = 3
  pIdle = 30
  stageRect = _movie.stage.rect
  pStageWidth = stageRect[3]-stageRect[1]
  pStageHeight = stageRect[4]-stageRect[2]
  pCounter = 0
  setNewVector()
end beginSprite

on enterFrame me
  currentLoc = pSprite.loc
  if currentLoc[1] < pSpeed then reverseVector(1)
  if currentLoc[1] > (pStageWidth - pSpeed) then reverseVector(1)
  if currentLoc[2] < pSpeed then reverseVector(2)
  if currentLoc[2] > (pStageHeight - pSpeed) then reverseVector(2)
  if pCounter > pLimit then setNewVector()
  pSprite.loc = pSprite.loc + pVector
  pCounter = pCounter + 1
end enterFrame

on reverseVector arg
  pVector[arg] = -pVector[arg]
  pSprite.loc = pSprite.loc + pVector
end reverseVector

on setNewVector
  pCounter = 0
  pLimit = random(pIdle)
  pVector = point(random(3)-2, random(3)-2)*pSpeed
  if pVector = point(0, 0) then
    setNewVector()
  else
    return
  end if
end setNewVector
--
As you see I wrote this in such a way so that the Sprite moves about very randomly. (Not very "bird".) Adjusting "pSpeed" and "pIdle" value is the first place to tweak.

Kenneth Kawamoto
www.materiaprima.co.uk

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close