Author Topic: multiple hits  (Read 302340 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
multiple hits
« Reply #45 on: 2005-11-18, 02:55:20 PM »
it doesn't matter if Terminate A is checked or not.  I tell you what I'll do though.  I'll whip up a quick project and see if I can debug this all in one go before sending the rest to you.
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
multiple hits
« Reply #46 on: 2005-11-18, 03:34:56 PM »
Okay, this works now on my test project (It gave me shivers when I saw it work :)).  Let me know how it works for you.  (If it works, it could easily be put into the scripting wizard)

Code: [Select]

Option Explicit

Class Hit
   Private hMap
   Private hSpriteName
   Private hHPs
   Public Sub Hit(Map, SpriteName, HPs)
      hMap = Map
      hSpriteName = SpriteName
      hHPs = HPs
   End Sub

   public function getMap()
      getMap = hMap
   End function

   public function getSprite()
      getSprite = hSpriteName
   End function

   public function getHPs()
      getHPs = hHPs
   end function

End Class

Sub Player_OnPlayInit()
   Dim i, oMap
   Dim oNewSpecial
   for i = 0 to ubound(Hits)
      Set oNewSpecial = NewSpecialFunction
      Set oMap = ProjectObj.Maps(Hits(i).getMap())
      oNewSpecial.FuncType = 7 ' SPECIAL_EVENT
      oNewSpecial.Flags = 8 ' INTFL_RAISEEVENT
      oNewSpecial.Name = "COL_" & Hits(i).getSprite()
      oMap.AddSpecial(hostObj.AsObject(oNewSpecial))
   Next
End Sub

Sub Player_OnSpecialFunction(SpecialObj)
   dim i, layer, idx, spr

   for i = 0 to UBound(Hits)
   spr = Hits(i).getSprite()
   if left(SpecialObj.Name,4 + len(spr)) = "COL_" & spr then
      set spr = FindSpriteByDef(spr,layer,idx)
      if spr.UserData > Hits(i).getHPs() or spr.UserData < 0 then spr.UserData = 0
      spr.UserData = spr.UserData + 1
      if spr.UserData = Hits(i).getHPs() then
         layer.RemoveSprite(idx)
      end if
   end if
next
End Sub

Function FindSpriteByDef(SpriteName, byref oLayer, byref oSprIndex)
   dim i, j, oMap
   With ProjectObj.GamePlayer.rMap
      for i = 0 to .LayerCount - 1
         for j = 0 to .MapLayer(i).SpriteCount() - 1
            if .MapLayer(i).Sprite(j).rDef.Name = SpriteName then
               set oLayer = .MapLayer(i)
               oSprIndex = j
               set FindSpriteByDef = oLayer.Sprite(j)
            end if
         next
      next
   End with
End Function

'-----Initialize Sprites-----
Dim Hits(16), i
for i = 0 to 3
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MJW" & i + 1,2
next
for i = 4 to 16
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MS" & i - 3,3
next
'-----End Initialization-----

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
multiple hits
« Reply #47 on: 2005-11-18, 04:05:18 PM »
And here's another version that doesn't use special functions, but acts directly using onSpritesCollide however this doesn't work as well as it could.  Unfortunately, if "Terminate A" is selected (and class A is the "bullet") then the script can't access the sprite because it's terminated before the script is called.  So you can't check to see what sprite is colliding with the enemy.  So if you uncheck that, it works, but then you have to destroy the sprite in the script (which is unfortunate if you want some sprites to be destroyed but want some sprites to remain, in which case another script class, Weapon, would have to be created)

However, it works fine if you're just using bullets.  Define a collision between a weapon (bullet) class and an enemy class (a and b respectively) and that's all you need.  Don't terminate either sprite, and you don't need to activate any special functions.

Oh, the good thing about this one is that it works for multiple instances of one sprite definition. (You also have to define the name of the weapon sprite at the bottom)

(Oh, and one thing, BlueMonk;  If you ever release another version of SGDK 1.x, or the Scripting documentation, change the description of the MapLayer function of the Map class to reflect the fact that you can pass the name of the layer rather than just the index)

Code: [Select]

Option Explicit

Class Hit
   Private hMap
   Private hSpriteName
   Private hHPs
   Public Sub Hit(Map, SpriteName, HPs)
      hMap = Map
      hSpriteName = SpriteName
      hHPs = HPs
   End Sub

   public function getMap()
      getMap = hMap
   End function

   public function getSprite()
      getSprite = hSpriteName
   End function

   public function getHPs()
      getHPs = hHPs
   end function

End Class

Sub Player_OnSpritesCollide(Name, ClsASprIdx, ClsBSprIdx, CollDefIdx)
   dim i, spr, sprName, atk
   set spr = ProjectObj.GamePlayer.rMap.MapLayer(Name).Sprite(ClsBSprIdx)
   atk = ProjectObj.GamePlayer.rMap.MapLayer(Name).Sprite(ClsASprIdx).rDef.Name

   for i = 0 to UBound(Weapons)
      if Weapons(i) = atk then exit for
   next

   if i > UBound(Weapons) then exit sub

   for i = 0 to UBound(Hits)
      sprName = Hits(i).getSprite()
      if spr.rDef.Name = sprName then
         ProjectObj.GamePlayer.rMap.MapLayer(Name).RemoveSprite(ClsASprIdx)
         if spr.UserData > Hits(i).getHPs() or spr.UserData < 0 then spr.UserData = 0
         spr.UserData = spr.UserData + 1
         if spr.UserData >= Hits(i).getHPs() then
            ProjectObj.GamePlayer.rMap.MapLayer(Name).RemoveSprite(ClsBSprIdx)
         end if
         exit sub
      end if
   next

End Sub

'-----Initialize Sprites-----
Dim Hits(16), Weapons(1), i
for i = 0 to 3
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MJW" & i + 1,2
next
for i = 4 to 16
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MS" & i - 3,3
next

Weapons(0) = "AttackLeft"
Weapons(1) = "AttackRight"
'-----End Initialization-----

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #48 on: 2005-11-18, 05:41:28 PM »
ok, i used hte first one, and it works great, for the MJW, but the MS is another story, 01-09 dont die when i shoot, nad when i shot 10, it crashed and gave me line 46 on char 7: object required: 'FindSpriteByDef(...)'

i'm thinking its because it's not MS1, but MS01. i would change the 01-09 to 1-9 but i'm not sure if that would create problems with the others, since hteyd both be starting the same, like MS10 would match MS1, you know?

line 46 is
Code: [Select]
     set spr = FindSpriteByDef(spr,layer,idx)


----edit----
ok, renamed the sprites 01-09 to 1-9, so now it gives error to all of them, so at least its checking hte script for them all now instead of just 10-13. i'll just hope there arent any problems between them :-[
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
multiple hits
« Reply #49 on: 2005-11-18, 09:53:35 PM »
Is there anything particularily strange about those sprites?  Like they're on a different layer, or they're scripted sprites, or are they possibly created after the start of the level (though that shouldn't make a difference)?

I don't know what to tell you.  I tried exactly the script I gave you with sprites MJW1, MJW2, MJW3, and MJW4 and MS1 through MS8 (because I didn't spend enough time to create all 13 sprites)

What it seems like is it's not finding the sprite.  Either the sprite is being destroyed somehow before it's supposed to be destroyed (like you told it to destroy in the Sprites collision dialog perhaps?) or it's not finding it for some other reason I can't think of.
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #50 on: 2005-11-18, 11:25:05 PM »
hmmm, its on the main layer.. (same as the MJW's), no colision classes are calling for termination, no special functions are being activated to delete them.., this is very strange. i guess i'll try deleting them and remaking them under a different name...
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #51 on: 2005-11-18, 11:49:22 PM »
Nice!!! It works! I remade all the sprites, new paths, new template name, new instance name, and it works! oh man that was nice to see! all thats left is merging this script with the script i had before (split screen, jump button, & forced scrolling for 2 levels).

Original Script
Code: [Select]
' ======== INITIAL STARTUP SCRIPT (Number 0) =========

Sub Player_OnPlayInit()
HostObj.StartScript=1
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

#Split == Runtime Script (Number 1)

Option Explicit

Dim XOff, YOff
Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo
Dim ScrollerSprite
ScrollerSprite = -1

Const nSprWidth = 41
Const nSprHeight = 75

Sub Display_KeyDown(KeyCode, Shift)
' E=69, S=83, D=68, F=70
If KeyCode = 69 Then P2Actions = P2Actions Or ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions Or ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions Or ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions Or ACTION_RIGHT
End Sub

Sub Display_KeyUp(KeyCode, Shift)
If KeyCode = 69 Then P2Actions = P2Actions And Not ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions And Not ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions And Not ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions And Not ACTION_RIGHT
End Sub

Sub Player_OnAfterMoveSprites()

if ProjectObj.GamePlayer.rMap.Name = "4-2SpaceFlight" and YOff = 0 then YOff = 15003 - ProjectObj.GamePlayer.rMap.ViewHeight 'ProjectObj.GamePlayer.rMap.HeightHeight

  Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
  Set oPlayer = ProjectObj.GamePlayer
  Set oMap = oPlayer.rMap


'Two Player Stuff
'If ProjectObj.GamePlayer.rMap.name = "0-4LevelSelect" or ProjectObj.GamePlayer.rMap.name = "map2" or ProjectObj.GamePlayer.rMap.name = "map3" or ProjectObj.GamePlayer.rMap.name = "map4" then

  If ProjectObj.GamePlayer.rMap.name <> "0-4LevelSelect" then
      intSprTwo = -1
oPlayer.ScrollMarginY = 185
  else
Set oLayer = oMap.MapLayer(1)
      If intSprTwo < 0 then
          For i = 0 to oLayer.SpriteCount - 1
              If oLayer.Sprite(i).rDef.Name = "Player2" then intSprTwo = i
          next
      End If
      With oLayer.Sprite(intSprTwo)
oPlayer.ScrollMarginY = 62
           If .ProcessAction(P2Actions) Then
              .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2)) _
                        + .rDef.Template.StateCount \ 2
              .CurFrame = .CurFrame Mod .rDef.StateFrameCount(.CurState)
           Else
              .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2))
           End If

          oMap.ViewTop = 240
          If P2OffsetX + oPlayer.ScrollMarginX > .X Then
              P2OffsetX = .X - oPlayer.ScrollMarginX
          End If
          If P2OffsetX + oMap.ViewWidth - oPlayer.ScrollMarginX < .X + nSprWidth Then
              P2OffsetX = .X - oMap.ViewWidth + oPlayer.ScrollMarginX + nSprWidth
          End If
          If P2OffsetY + oPlayer.ScrollMarginY > .Y Then
              P2OffsetY = .Y - oPlayer.ScrollMarginY
          End If
          If P2OffsetY + oMap.ViewHeight - oPlayer.ScrollMarginY < .Y + nSprHeight Then
              P2OffsetY = .Y - oMap.ViewHeight + oPlayer.ScrollMarginY + nSprHeight
          End If

          If P2OffsetX < 0 Then P2OffsetX = 0
          If P2OffsetY < 0 Then P2OffsetY = 0
           nLyrWid = oLayer.Columns * 32
           nLyrHgt = oLayer.Rows * 32
          If P2OffsetX > nLyrWid - oMap.ViewWidth Then P2OffsetX = nLyrWid - oMap.ViewWidth
          If P2OffsetY > nLyrHgt - oMap.ViewHeight Then P2OffsetY = nLyrHgt - oMap.ViewHeight
          oMap.Draw P2OffsetX, P2OffsetY, False
          oMap.ViewTop = 0
      End With
  End If

'Automatic Scrolling Stuff
  If ProjectObj.GamePlayer.rMap.name = "2-4BonusLevel" then
      XOff = XOff + 1
      With ProjectObj.GamePlayer
          if .PlayerSprite.X <= XOff then
              if .PlayerSprite.DX < 0 then .PlayerSprite.DX = 1
              .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
              if .PlayerSprite.X < XOff - .PlayerSprite.Width / 2 then
                  XOff = 1
              End if
          end if
          .rMap.Draw XOff, YOff
      End With
  End If


If ProjectObj.GamePlayer.rMap.name = "4-2SpaceFlight" then
oPlayer.ScrollMarginX = 5
oPlayer.ScrollMarginY = 5

   If ScrollerSprite < 0 Then
      ScrollerSprite = FindScrollerSprite
   End If

   If ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount <= ScrollerSprite Then
      ScrollerSprite = FindScrollerSprite
   End If

   If ScrollerSprite >= 0 Then
      If Left(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).rDef.Name, 8) <> "Scroller" Then
         ScrollerSprite = FindScrollerSprite
      End If
   End If

   With ProjectObj.GamePlayer
      .MapScrollX = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).X
      .MapScrollY = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).Y
      If .PlayerSprite.Y > .MapScrollY + .rMap.ViewHeight - .ScrollMarginY - .PlayerSprite.Height Then
         .PlayerSprite.DY = -.PlayerSprite.rDef.Template.MoveSpeed
      ElseIf .PlayerSprite.Y < .MapScrollY + .ScrollMarginY Then
         .PlayerSprite.DY = .PlayerSprite.rDef.Template.MoveSpeed
      End If

      If .PlayerSprite.X > .MapScrollX + .rMap.ViewWidth - .ScrollMarginX - .PlayerSprite.Width Then
         .PlayerSprite.DX = -.PlayerSprite.rDef.Template.MoveSpeed
      ElseIf .PlayerSprite.X < .MapScrollX + .ScrollMarginX Then
         .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
      End If
   End With

end if

End Sub

Function FindScrollerSprite()
   Dim I
   With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
      For I = 0 To .SpriteCount - 1
         If Left(.Sprite(I).rDef.Name, 8) = "Scroller" Then
            FindScrollerSprite = I
            Exit Function
         End If
      Next
   End With
   FindScrollerSprite = -1
End Function

Sub Player_OnControllerMove(OldActions, NewActions)

'Jumping Player
  With ProjectObj.GamePlayer.PlayerSprite
      If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
          If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
              .DY = - .rDef.Template.JumpHeight
          End If
      End If
  End With

End Sub

intSprTwo = -1
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.ConnectEventsNow()


with this

New Script
Code: [Select]
Option Explicit

Class Hit
   Private hMap
   Private hSpriteName
   Private hHPs
   Public Sub Hit(Map, SpriteName, HPs)
      hMap = Map
      hSpriteName = SpriteName
      hHPs = HPs
   End Sub

   public function getMap()
      getMap = hMap
   End function

   public function getSprite()
      getSprite = hSpriteName
   End function

   public function getHPs()
      getHPs = hHPs
   end function

End Class

Sub Player_OnPlayInit()
   Dim i, oMap
   Dim oNewSpecial
   for i = 0 to ubound(Hits)
      Set oNewSpecial = NewSpecialFunction
      Set oMap = ProjectObj.Maps(Hits(i).getMap())
      oNewSpecial.FuncType = 7 ' SPECIAL_EVENT
      oNewSpecial.Flags = 8 ' INTFL_RAISEEVENT
      oNewSpecial.Name = "COL_" & Hits(i).getSprite()
      oMap.AddSpecial(hostObj.AsObject(oNewSpecial))
   Next
End Sub

Sub Player_OnSpecialFunction(SpecialObj)
   dim i, layer, idx, spr

   for i = 0 to UBound(Hits)
   spr = Hits(i).getSprite()
   if left(SpecialObj.Name,4 + len(spr)) = "COL_" & spr then
      set spr = FindSpriteByDef(spr,layer,idx)
      if spr.UserData > Hits(i).getHPs() or spr.UserData < 0 then spr.UserData = 0
      spr.UserData = spr.UserData + 1
      if spr.UserData = Hits(i).getHPs() then
         layer.RemoveSprite(idx)
      end if
   end if
next
End Sub

Function FindSpriteByDef(SpriteName, byref oLayer, byref oSprIndex)
   dim i, j, oMap
   With ProjectObj.GamePlayer.rMap
      for i = 0 to .LayerCount - 1
         for j = 0 to .MapLayer(i).SpriteCount() - 1
            if .MapLayer(i).Sprite(j).rDef.Name = SpriteName then
               set oLayer = .MapLayer(i)
               oSprIndex = j
               set FindSpriteByDef = oLayer.Sprite(j)
            end if
         next
      next
   End with
End Function

'-----Initialize Sprites-----
Dim Hits(16), i
for i = 0 to 3
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MJW" & i + 1,2
next
for i = 4 to 16
   set Hits(i) = new Hit
   Hits(i).Hit "5-0TheMoon","MJS" & i - 3,3
next
'-----End Initialization-----

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
multiple hits
« Reply #52 on: 2005-11-19, 10:32:23 AM »
I don't know why the code is split into two parts where the first part does nothing, but this may or may not work (depending on if Player_OnPlayInit() is called in the second script or only the first one.

Code: [Select]
' ======== INITIAL STARTUP SCRIPT (Number 0) =========

Sub Player_OnPlayInit()
   HostObj.StartScript = 1
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

#Split == Runtime Script (Number 1)

Option Explicit

Dim XOff, YOff
Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo
Dim ScrollerSprite
Dim Hits(16), i
ScrollerSprite = -1
intSprTwo = -1

For i = 0 To 3
   Set Hits(i) = New Hit
   Hits(i).Hit "5-0TheMoon", "MJW" & i + 1, 2
Next
For i = 4 To 16
   Set Hits(i) = New Hit
   Hits(i).Hit "5-0TheMoon", "MJS" & i - 3, 3
Next

Const nSprWidth = 41
Const nSprHeight = 75

Sub Player_OnPlayInit()
   Dim i, oMap
   Dim oNewSpecial
   For i = 0 To UBound(Hits)
      Set oNewSpecial = NewSpecialFunction
      Set oMap = ProjectObj.Maps(Hits(i).getMap())
      oNewSpecial.FuncType = 7 ' SPECIAL_EVENT
      oNewSpecial.Flags = 8 ' INTFL_RAISEEVENT
      oNewSpecial.Name = "COL_" & Hits(i).getSprite()
      oMap.AddSpecial (HostObj.AsObject(oNewSpecial))
   Next
End Sub

Sub Display_KeyDown(KeyCode, Shift)
' E=69, S=83, D=68, F=70
If KeyCode = 69 Then P2Actions = P2Actions Or ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions Or ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions Or ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions Or ACTION_RIGHT
End Sub

Sub Display_KeyUp(KeyCode, Shift)
If KeyCode = 69 Then P2Actions = P2Actions And Not ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions And Not ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions And Not ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions And Not ACTION_RIGHT
End Sub

Sub Player_OnAfterMoveSprites()

    If ProjectObj.GamePlayer.rMap.Name = "4-2SpaceFlight" And YOff = 0 Then
        YOff = 15003 - ProjectObj.GamePlayer.rMap.ViewHeight
    End If

    Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
    Set oPlayer = ProjectObj.GamePlayer
    Set oMap = oPlayer.rMap

'Two Player Stuff

    If ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" Then
        intSprTwo = -1
        oPlayer.ScrollMarginY = 185
    Else
        Set oLayer = oMap.MapLayer(1)
        If intSprTwo < 0 Then
            For i = 0 To oLayer.SpriteCount - 1
                If oLayer.Sprite(i).rDef.Name = "Player2" Then intSprTwo = i
            Next
        End If
        With oLayer.Sprite(intSprTwo)
            oPlayer.ScrollMarginY = 62
            If .ProcessAction(P2Actions) Then
                .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2)) _
                            + .rDef.Template.StateCount \ 2
                .CurFrame = .CurFrame Mod .rDef.StateFrameCount(.CurState)
            Else
                .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2))
            End If
            oMap.ViewTop = 240
            If P2OffsetX + oPlayer.ScrollMarginX > .X Then
                P2OffsetX = .X - oPlayer.ScrollMarginX
            End If
            If P2OffsetX + oMap.ViewWidth - oPlayer.ScrollMarginX < .X + nSprWidth Then
                P2OffsetX = .X - oMap.ViewWidth + oPlayer.ScrollMarginX + nSprWidth
            End If
            If P2OffsetY + oPlayer.ScrollMarginY > .Y Then
                P2OffsetY = .Y - oPlayer.ScrollMarginY
            End If
            If P2OffsetY + oMap.ViewHeight - oPlayer.ScrollMarginY < .Y + nSprHeight Then
                P2OffsetY = .Y - oMap.ViewHeight + oPlayer.ScrollMarginY + nSprHeight
            End If
            If P2OffsetX < 0 Then P2OffsetX = 0
            If P2OffsetY < 0 Then P2OffsetY = 0
            nLyrWid = oLayer.Columns * 32
            nLyrHgt = oLayer.Rows * 32
            If P2OffsetX > nLyrWid - oMap.ViewWidth Then P2OffsetX = nLyrWid - oMap.ViewWidth
            If P2OffsetY > nLyrHgt - oMap.ViewHeight Then P2OffsetY = nLyrHgt - oMap.ViewHeight
            oMap.Draw P2OffsetX, P2OffsetY, False
            oMap.ViewTop = 0
        End With
    End If

'Automatic Scrolling Stuff
    If ProjectObj.GamePlayer.rMap.Name = "2-4BonusLevel" Then
        XOff = XOff + 1
        With ProjectObj.GamePlayer
            If .PlayerSprite.X <= XOff Then
                If .PlayerSprite.DX < 0 Then .PlayerSprite.DX = 1
                .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
                If .PlayerSprite.X < XOff - .PlayerSprite.Width / 2 Then
                    XOff = 1
                End If
            End If
            .rMap.Draw XOff, YOff
        End With
    End If

   
    If ProjectObj.GamePlayer.rMap.Name = "4-2SpaceFlight" Then
        oPlayer.ScrollMarginX = 5
        oPlayer.ScrollMarginY = 5
        If ScrollerSprite < 0 Then
            ScrollerSprite = FindScrollerSprite
        End If
       
        If ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount <= ScrollerSprite Then
            ScrollerSprite = FindScrollerSprite
        End If
   
        If ScrollerSprite >= 0 Then
            If Left(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).rDef.Name, 8) <> "Scroller" Then
                ScrollerSprite = FindScrollerSprite
            End If
        End If
   
        With ProjectObj.GamePlayer
            .MapScrollX = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).X
            .MapScrollY = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).Y
            If .PlayerSprite.Y > .MapScrollY + .rMap.ViewHeight - .ScrollMarginY - .PlayerSprite.Height Then
                .PlayerSprite.DY = -.PlayerSprite.rDef.Template.MoveSpeed
            ElseIf .PlayerSprite.Y < .MapScrollY + .ScrollMarginY Then
                .PlayerSprite.DY = .PlayerSprite.rDef.Template.MoveSpeed
            End If
            If .PlayerSprite.X > .MapScrollX + .rMap.ViewWidth - .ScrollMarginX - .PlayerSprite.Width Then
                .PlayerSprite.DX = -.PlayerSprite.rDef.Template.MoveSpeed
            ElseIf .PlayerSprite.X < .MapScrollX + .ScrollMarginX Then
                .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
            End If
        End With
    End If
End Sub

Function FindScrollerSprite()
   Dim i
   With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
      For i = 0 To .SpriteCount - 1
         If Left(.Sprite(i).rDef.Name, 8) = "Scroller" Then
            FindScrollerSprite = i
            Exit Function
         End If
      Next
   End With
   FindScrollerSprite = -1
End Function

Sub Player_OnControllerMove(OldActions, NewActions)

'Jumping Player
  With ProjectObj.GamePlayer.PlayerSprite
      If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
          If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
              .DY = -.rDef.Template.JumpHeight
          End If
      End If
  End With
End Sub

Class Hit
   Private hMap
   Private hSpriteName
   Private hHPs
   Public Sub Hit(Map, SpriteName, HPs)
      hMap = Map
      hSpriteName = SpriteName
      hHPs = HPs
   End Sub

   Public Function getMap()
      getMap = hMap
   End Function

   Public Function getSprite()
      getSprite = hSpriteName
   End Function

   Public Function getHPs()
      getHPs = hHPs
   End Function

End Class

Sub Player_OnSpecialFunction(SpecialObj)
   Dim i, layer, idx, spr

   For i = 0 To UBound(Hits)
   spr = Hits(i).getSprite()
   If Left(SpecialObj.Name, 4 + Len(spr)) = "COL_" & spr Then
      Set spr = FindSpriteByDef(spr, layer, idx)
      If spr.UserData > Hits(i).getHPs() Or spr.UserData < 0 Then spr.UserData = 0
      spr.UserData = spr.UserData + 1
      If spr.UserData = Hits(i).getHPs() Then
         layer.RemoveSprite (idx)
      End If
   End If
Next
End Sub

Function FindSpriteByDef(SpriteName, ByRef oLayer, ByRef oSprIndex)
   Dim i, j, oMap
   With ProjectObj.GamePlayer.rMap
      For i = 0 To .LayerCount - 1
         For j = 0 To .MapLayer(i).SpriteCount() - 1
            If .MapLayer(i).Sprite(j).rDef.Name = SpriteName Then
               Set oLayer = .MapLayer(i)
               oSprIndex = j
               Set FindSpriteByDef = oLayer.Sprite(j)
            End If
         Next
      Next
   End With
End Function

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
multiple hits
« Reply #53 on: 2005-11-19, 10:46:08 AM »
The script is split into 2 parts because the Display events cannot be connected until after OnPlayInit has been called.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #54 on: 2005-11-19, 10:25:15 PM »
mmm, it goes to the splash screen,. then goes to a full black screen, then doesnt do anything, so i tried alt+tab'ing it and it gave me the "method ~ of object ~ failed" message, and then: "error playing map: object variable or with blick variable not set" continuously untill i ctrl alt delete it
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #55 on: 2005-11-20, 12:24:37 AM »
..., wasn't this in teh general discusion? or am i just going crazy again...? (which is very likely ;) )
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
multiple hits
« Reply #56 on: 2005-11-20, 08:13:44 AM »
Yes.  I moved it for obvious reasons :).  You can still see the original topic marked as "Moved" in General Discussion.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #57 on: 2005-11-20, 09:25:08 AM »
I got it to work, but it
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #58 on: 2005-11-21, 05:43:13 PM »
I'll post 2 rar'ed versions later tonight, one wiht all files (approx 26mb compressed) and one with all but large sounds/videos (approx 8mb compressed)
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple hits
« Reply #59 on: 2005-11-21, 07:34:43 PM »
http://www.angelfire.com/ct3/billybob884/ChameleonMan_TRIMMED.rar

Open part 01 with winrar and itll put all three parts together (you probably already know all this)
http://h1.ripway.com/billybob884/ChameleonMan_FULL.part01.rar
http://h1.ripway.com/billybob884/ChameleonMan_FULL.part02.rar
http://h1.ripway.com/billybob884/ChameleonMan_FULL.part03.rar

[LINKS UNTESTED], also, give hte full one another hour to finish uploading, part 1 is done, and part 2 is like 1/2 way.

I think you can guess which is which (;))

-------------------

ok, all of them are uploaded, and they all work
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy