Author Topic: script "merging"  (Read 25978 times)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
script "merging"
« Reply #45 on: 2005-05-24, 01:02:33 AM »
That line couldn't really remove the 2-player ability.  Not possible, as such, unless you expect 2-player to work with no player sprites.  The problem must lie elsewhere.
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #46 on: 2005-05-24, 04:11:47 AM »
Quote from: "durnurd"
unless you expect 2-player to work with no player sprites.


i do have 2 player sprites on the leel select map, if that's what you mean.
heres the code i have so far, just for referrence
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



Option Explicit

Dim XOff, YOff

Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo

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()
    Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
    Set oPlayer = ProjectObj.GamePlayer
    Set oMap = oPlayer.rMap
    Set oLayer = oMap.MapLayer(0)

'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
    else
if oLayer.SpriteCount <= 0 Then Exit Sub
        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)
            .ProcessAction(P2Actions)

            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 * nSprWidth
            nLyrHgt = oLayer.Rows * nSprHeight
            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

End Sub

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()
"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
script "merging"
« Reply #47 on: 2005-05-24, 06:06:18 AM »
Ah, I was a bit hasty in my earlier assessment.  It looks like the real problem is that you're getting the wrong layer.  You can delete the line I told you to add before if you want.  Then change the line that sets oLayer to this:
Code: [Select]
Set oLayer = oMap.MapLayer(1)
And move it right before "If intSprTwo < 0 then" otherwise you will get errors when it tries to do that on maps where there is only 1 layer.  You were getting layer 0 instead of layer 1 before, and the sprites are on layer 1.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #48 on: 2005-05-24, 01:36:20 PM »
YES! It works!!! Now, for the final touches/tweaks. I noticed that the 2nd player only uses its drifting frames (probably due to the fact that its inert, right?), so the only non-scripting solution I can think of as a possibility is to not use the seperate states for accelerate/drifting, and to use that check box thats like animation with velocity or something (can't remember it exactly). Now (thankfully) my 2nd player wont need the animated drifting state, so all I have to do is find the right animation speed to make it look right. Now, my other problem is that I need to find a way to have a different horizontal/vertical scroll margin for the 2 player maps (since the window sizes are different).

So I'll try the 1st part and see what happens.

-----added-later-----
Ok, the velocity idea worked, so just the scroll margines left. I'm gonna go look through the scripting list to see if I can find anything that looks like it may be useful.

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

Oh wait, here we are:

Code: [Select]
ScrollMarginX
Integer
Get or set how close the edge of the player sprite can get to the edge of the map window before scrolling.
[Let] MyInteger = oPlayer.ScrollMarginX
[Let] oPlayer.ScrollMarginX = MyInteger


Code: [Select]
ScrollMarginY
Integer
Get or set how close the edge of the player sprite can get to the edge of the map window before scrolling.
[Let] MyInteger = oPlayer.ScrollMarginY
[Let] oPlayer.ScrollMarginY = MyInteger


ok, so by looking at these it looks like each one is the same thing except one forward n one backward, so its safe to assume you only need one line from each right? in that case, i should just use

oPlayer.ScrollMarginX = 298
oPlayer.ScrollMarginY = 62 'the numbers i found to work on the split screen w/ my sprites

but im not sure where they should go, everywhere ive tried so far causes teh game to go back to that TileDisplay error message
"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
script "merging"
« Reply #49 on: 2005-05-26, 06:13:21 AM »
Here are some changes I made to your script and the problems they fixed:

1) Changed the current .ProcessActions line to:
Code: [Select]
           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

This allows player 2 to handle drifting and accelerating without resorting to any other funny business.  The reason the .CurFrame line is there is because GameDev is animating the sprite based on the number of frames in the drifting state, and if I switch it to the accellerating state, I get an error if the current frame is larger than the number of frames in the animating state.  But with that in there, this works great so long as the number of frames in the drifting state is greater than or equal to the number of frames in the accelerating state.  I expect you wouldn't see the full animation if it were less.

2) Changed
Code: [Select]
           nLyrWid = oLayer.Columns * nSprWidth
            nLyrHgt = oLayer.Rows * nSprHeight
to
Code: [Select]
           nLyrWid = oLayer.Columns * 32
            nLyrHgt = oLayer.Rows * 32
We actually wanted the tile size in that calculation, not the sprite size.  This corrects the scrolling in the lower map display.

3) Added "oPlayer.ScrollMarginY = 185" after the first "intSprTwo = -1" and added "oPlayer.ScrollMarginY = 62" after "With oLayer.Sprite(intSprTwo)".  This dynamically adjusts the scroll margin that you care about changing.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
script "merging"
« Reply #50 on: 2005-05-26, 06:18:33 AM »
Oh, and keep up the good work!  8)

billybob884-no-login

  • Guest
script "merging"
« Reply #51 on: 2005-05-26, 09:32:07 AM »
Ok, here's what I got so far with the changes you told me to make.

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



Option Explicit

Dim XOff, YOff

Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo

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()
    Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
    Set oPlayer = ProjectObj.GamePlayer
    Set oMap = oPlayer.rMap
    Set oLayer = oMap.MapLayer(0)

'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
    else
if oLayer.SpriteCount <= 0 Then Exit Sub
        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
'----------this works great so long as the number of frames in the drifting state is greater than or equal to the number of frames in the accelerating state-------------
            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

End Sub

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
oPlayer.ScrollMarginY = 185
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.ConnectEventsNow()

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #52 on: 2005-05-26, 01:36:57 PM »
In the script I posted above, I put the oPlayer.ScrollMarginY = 185 in the wrong place, so ignore that mistake, but after I fixed it the script wouldn't work. The 2-player layer at the bottom of the level select map isn't being displayed, and the screen is shaking (presumably because the regular 1-player scroll margines are being used). I did make sure that the Player2 sprite has more frames in the drifting states than in the accelerating states, so thats not the problem.
"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
script "merging"
« Reply #53 on: 2005-05-27, 05:20:10 AM »
That's the wrong script -- you lost the changes for using MapLayer(1) instead of MapLayer(0), and the Exit Sub is still in there.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
script "merging"
« Reply #54 on: 2005-05-27, 05:48:52 AM »
Quote from: "bluemonkmn"
That's the wrong script -- you lost the changes for using MapLayer(1) instead of MapLayer(0), and the Exit Sub is still in there.


Oops, made the changes to a backup copy of the wrong script...
Ok, I'll make these changes to the RIGHT script when I get home ::) .

------
allright, works [again]!  :D
"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