Scrolling Game Development Kit Forum

SGDK Version 1 => Script => Topic started by: gwal on 2006-02-26, 09:32:45 AM

Title: collision question
Post by: gwal 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.
Title: Re: collision question
Post by: durnurd 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
Title: Re: collision question
Post by: durnurd on 2006-02-26, 10:02:39 PM
Oops, when I say "Dim x, spr" I mean "Dim x, sprT"
Title: Re: collision question
Post by: bluemonkmn 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
Title: Re: collision question
Post by: gwal on 2006-02-27, 07:02:50 PM
This should be very helpful. Thanks once again.