The direction the sprite will shoot is determind on what angle your
charecter sprite is, I see what you are trying to do, in your case there a
only 4 possible angles : 90, 180, 270, 360/0. I think you need to look at
the other script 'the charecter shoot example' see how it works out what
angle the sprite is at....
search for 'Cannon and Bullet Behaviors '
at:
http://www.director-online.com
Stay Cool Matt

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Matt
Sent: 27 January 2001 08:20
To: [EMAIL PROTECTED]
Subject: <lingo-l> Sprite shooting


Dear everyone,
I hope someone can help on this:
I'm trying to design a little game where the player shoots monsters. I've
got the script down for him moving up, down, left & right (borrowed from
another game), but getting the character to shoot at the same time he moves
is another matter entirely. Can anybody help me modify my code and add a
shooting behaviour to it? I already have the graphics prepared. All I want
to do is make a succession of bullet sprites shoot out from the player's
gun.

Thanks, here's my code thus far:


property mys
property pInventory -- list of items owned
property pHaveKilled -- list of monsters killed
property pPoints -- number of points
property pPointsList -- list of points object gathered
property pSpeed -- speed of movement
property pAnimNum -- animation number
property pLastMove -- time of last move
property flag



on beginSprite me


  mys = me.spritenum
  angle = 0
  jet = float(0)
  myloch = sprite(mys).loch
  mylocv = sprite(mys).locv
  pSpeed = 5
  -- set animation properties
  pAnimNum = 1
  pLastMove = 0
  flag = 0
  -- set character properties
  pInventory = []
  pHaveKilled = []
  pPointsList = []
  pPoints = 0

  -- clear screen
  showPoints(me)
  sendSprite(66,#message,"")
end

on exitFrame me
  -- keyboard input
  if keyPressed(123) then
    move(me,-5,0) -- left
    sprite(me.spritenum).membernum=member"walk left"

  else if keyPressed(124) then
    move(me,5,0) -- right
    sprite(me.spritenum).membernum=member"walk right"

  else if keyPressed(125) then
    move(me,0,5) -- down
    sprite(me.spritenum).membernum=member"walk down"
  else if keyPressed(126) then
    move(me,0,-5) -- up
    sprite(me.spritenum).membernum=member"walk up"
  end if

  -- if standing still, reset character
  if the ticks > pLastMove + 5 then
    sprite(me.spriteNum).member = member("Stand")
  end if

  if keypressed (" ") then
    if flag = 1 then
      mymissile = getone(gmissile,0)

    end if
    flag = 0
  else
    flag = 1
  end if
end

end

-- move character
on move me, dx, dy
-- get current loc
loc = sprite(me.spriteNum).loc

-- determine largest rect needed
w = max(member("Stand").rect.width, sprite(me.spriteNum).rect.width)
h = max(member("Stand").rect.height, sprite(me.spriteNum).rect.height)
rect = rect(loc.locH-w/2-1,loc.locV-h/2-1,loc.locH+w/2+1,loc.locV+h/2+1)

-- move loc and rect
loc = loc + point(dx,dy)*pSpeed
rect = rect + rect(dx*pSpeed,dy*pSpeed,dx*pSpeed,dy*pSpeed)

-- safety check to make sure character stays on screen
if rect.left < 0 then exit
if rect.top < 0 then exit
if rect.right > (the stage).rect.width then exit
if rect.bottom > (the stage).rect.height then exit

-- check all objects for collisions
repeat with i = 80 down to 31
-- all "detectCollision"s return TRUE if character should not move
if sendSprite(i,#detectCollision,rect,dx,dy) then exit
end repeat

-- set new character location
sprite(me.spriteNum).loc = loc

pLastMove = the ticks
end

-- add object to inventory
on takeObject me, objectName
add pInventory, objectName -- add
showInventory(me) -- update screen
sendSprite(66,#message,objectName&&"Taken!") -- show message
end

-- place objects in inventory sprites
on showInventory me
-- seven spots available
repeat with i = 1 to 7
if i > pInventory.count then -- past end of list
sprite(10+i).memberNum = 0 -- remove sprite
else
sprite(10+i).member = member(pInventory[i]) -- show object
end if
end repeat
end

-- add monster to killed list
on killedMonster me, monsterName
sendSprite(66,#message,"You Killed the"&&monsterName&"!")
add pHaveKilled, monsterName
end

-- utility will return TRUE if player has an item
on haveItem me, objectName
return getOne(pInventory,objectName)
end

-- utility will return TRUE if player has killed a specific monster
on haveKilled me, monsterName
return getOne(pHaveKilled,monsterName)
end

-- when player encounters door
on enterDoor me, key, path, offset
-- remember the current frame
lastFrame = the frameLabel

-- see if no key is needed or the player has the key
if key = "" or getOne(pInventory,key) then
-- go to the new frame
go to frame path
-- look for opposite door
repeat with i = 80 down to 31
-- see if door will send you back to the previous room
if sendSprite(i,#getDoorPath) = lastFrame then
-- this is the opposite door
-- position player on other side of it
sprite(6).loc = sprite(i).loc - offset
-- make sure player is in the right position
updateStage
exit repeat
end if
end repeat

-- add points
on addPoints me, points
pPoints = pPoints + points -- add
showPoints(me) -- update screen
end

-- remember that points are already taken
on getPoints me, spriteNum
-- remember that this object has already given points
add pPointsList, [the frameLabel,spriteNum]
end

-- check to see if points have already been taken
on gotPoints me, spriteNum
return getOne(pPointsList,[the frameLabel,spriteNum])
end

-- display points on screen
on showPoints me
member("Score").text = string(pPoints)
end

end

The #1 FREE E-mail on the Internet at http://www.Gotmail.com. Your Gotmail
email address is available to you around the world anytime, all the time.

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to