Author Topic: collision question  (Read 3440 times)

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
collision question
« on: 2006-02-26, 09:32:45 AM »
How do you reference a sprite collision in the script? What I mean is something like this:
Code: [Select]
Sub Player_OnSpritesCollide
If (collision between sword and boss1) then
'coding goes here'
End Sub
In addition, I want the code for collisions to be determined by sprite names, rather than templates or collision classes.

I have another question also. How do you create an 'itemlike' variable through scripting? So I have a letter like X, which starts out at a some value, and I can add or subtract to its amount. I know this could be done by using items, but I think it would be easier just to control variables through scripting.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: collision question
« Reply #1 on: 2006-02-26, 11:14:09 AM »
Code: [Select]
Sub Player_OnSpritesCollide(Name, ClsASprIdx, ClsBSprIdx, CollDefIdx)
   Dim Spr1, Spr2
   With ProjectObj.GamePlayer.rMap.MapLayer(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer)
      Spr1 = .Sprite(ClsASprIdx)
      Spr2 = .Sprite(ClsBSprIdx)
   End With
   Dim Spr1Name, Spr2Name
   Spr1Name = Spr1.rDef.Name
   Spr2Name = Spr2.rDef.Name
   If Spr1Name = "Sword" and Spr2Name = "Boss" then
      'Code here
   End If
End Sub

As for using variables, just use "dim x" like this:

Code: [Select]
Sub SomeRandomSubFunction(Sprite)
   Dim x, spr
   set sprT = Sprite.Template    'use Set instead of Let since it's an object, not a number
   x = ((1 + (25 - sprT.AnimSpeed)) * sprT.StateFrameCount(0)) - 1
   doSomethingWithVariable(x) 'Pass it to another function as a number.
End Sub
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: collision question
« Reply #2 on: 2006-02-26, 10:02:39 PM »
Oops, when I say "Dim x, spr" I mean "Dim x, sprT"
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: collision question
« Reply #3 on: 2006-02-27, 08:30:03 AM »
Another correction: replace this
Code: [Select]
ProjectObj.GamePlayer.rMap.MapLayer(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer)
with this
Code: [Select]
ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer

gwal

  • Regular
  • **
  • Posts: 69
  • Game Progress: Outer Space / Items
    • View Profile
Re: collision question
« Reply #4 on: 2006-02-27, 07:02:50 PM »
This should be very helpful. Thanks once again.