Scrolling Game Development Kit Forum
SGDK Version 1 => Script => Topic started 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:
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.
-
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:
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
-
Oops, when I say "Dim x, spr" I mean "Dim x, sprT"
-
Another correction: replace this
ProjectObj.GamePlayer.rMap.MapLayer(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer)
with this
ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
-
This should be very helpful. Thanks once again.