Scrolling Game Development Kit Forum

SGDK Version 1 => Script => Topic started by: billybob884 on 2006-01-29, 04:41:21 PM

Title: multiple 2-player maps
Post by: billybob884 on 2006-01-29, 04:41:21 PM
i need to change the beginning of this section so that it will recognize 4 maps as two player instead of recognizing every other map as not multiplayer.

Code: [Select]
'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

i tried changing this part

Code: [Select]
'Two Player Stuff

    If ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" Then
        intSprTwo = -1
        oPlayer.ScrollMarginY = 185
    Else

to this, but it kept giving me a syntax error

Code: [Select]
'Two Player Stuff

    If ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" or If ProjectObj.GamePlayer.rMap.Name <> "map1" or If ProjectObj.GamePlayer.rMap.Name <> "map2" or If ProjectObj.GamePlayer.rMap.Name <> "map3" Then
        intSprTwo = -1
        oPlayer.ScrollMarginY = 185
    Else

i kinda hada  feeling that this wouldn't work, but i gave it a shot anyway.
Title: Re: multiple 2-player maps
Post by: durnurd on 2006-01-29, 09:40:58 PM
I believe all you need to do is remove the subsequent "If"s.  So it should be

Code: [Select]
If ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" or ProjectObj.GamePlayer.rMap.Name <> "map1" or ProjectObj.GamePlayer.rMap.Name <> "map2" or ProjectObj.GamePlayer.rMap.Name <> "map3" Then
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-01-29, 10:11:35 PM
hmm, well that stopped the syntax error, but now none of the maps specified are being displayed as 2 player
Title: Re: multiple 2-player maps
Post by: bluemonkmn on 2006-01-30, 07:22:17 AM
I finally bothered to look up the name of the law being violated, but won't go into the messy details of DeMorgan's law.  To put it shortly, I think you have to change the "Or"s to "And"s.
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-01-30, 12:16:27 PM
yep, that fixed it!
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-01-31, 12:37:51 PM
heres something i just thought of. since its drawing the map twice, if i have any visible inventory on it, is it going to try to draw that twice as well?
Title: Re: multiple 2-player maps
Post by: bluemonkmn on 2006-01-31, 04:40:34 PM
If I recall correctly, drawing the inventory is a function of the player and not of the map, so drawing the map twice will not draw the inventory twice.  I believe the 2-player demo script that I posted had extra script code specifically for drawing player 2's inventory because it wasn't drawn with the map.
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-01-31, 04:59:20 PM
nah, player two wont have any inventory, there will just be 2 timers at the top, and each will be stopped when the corresponding player hits the "invisible" sprite at the finish line
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-02-05, 06:47:41 PM
ok, having a small problem with this. i've finally started working on the levels, and i changed the or's to ands like stated above, but the 3 subsequent maps wont work. when i open them it crashes and gives me the messages:

Error playing map: Tried to draw text when no drawing surface is available [OK]

Script stopped at line 99 on character 9: Subscript out of range [OK]

i believe line 99 is
        With oLayer.Sprite(intSprTwo)


---edit---

ok, i figured out the problem; in the level select, there is only 1 layer behing Main, and in the multi there are 2, so how do i change the number of layers behind the main (in the script)

Code: [Select]
'Two Player Stuff

If ProjectObj.GamePlayer.rMap.Name <> "7-1MultiButtRace" and ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" and ProjectObj.GamePlayer.rMap.Name <> "7-2MultiLawnMower" and ProjectObj.GamePlayer.rMap.Name <> "7-3MultiChainsawSkate" 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
Title: Re: multiple 2-player maps
Post by: bluemonkmn on 2006-02-06, 07:02:50 AM
I'm not entirely sure I understand, but I think I do, and I'm going to guess that you need to change this line:
Code: [Select]
Set oLayer = oMap.MapLayer(1)to something like this:
Code: [Select]
If oMap.Name = "0-4LevelSelect" Then Set oLayer = oMap.MapLayer(1) Else Set oLayer = oMap.MapLayer(2)
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-02-06, 07:44:01 AM
yea, thats probbly it, or i could just change it to 2 for all, then just put blank layers in on hte maps that dont need multiple bg's
Title: Re: multiple 2-player maps
Post by: bluemonkmn on 2006-02-06, 10:01:58 AM
By the way, you can also refer to the layer by name if you name the player layer the same thing on all your 2-player maps:
Code: [Select]
Set oLayer = oMap.MapLayer("Main")
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-02-06, 03:34:04 PM
there we go, thats what i needed. one more question, if i have a function that deletes the 2nd player sprite, will the script freak out and crash? becasue im probably gonna have 'inert' players at teh start for a little 3-2-1-GO at the beginning of each race, ya know?
Title: Re: multiple 2-player maps
Post by: durnurd on 2006-02-06, 04:24:25 PM
I think the easiest way to find out would be to try.  To get around that problem (if it does happen, which I think it will), you would probably have to catch that when it happens (in a Player_OnSpecialFunction event) and reset the sprite index.

The reason it will probably happen is because the player 2 sprite is kept track of my an integer index into the list of sprites.  Deleting that sprite and re-creating it later will change the index, even if the name stays the same (though I don't see how it could have the same name).  How exactly were you planning on having the script keep track of which sprite was the new player sprite?
Title: Re: multiple 2-player maps
Post by: billybob884 on 2006-02-06, 08:29:20 PM
well it was only going to switch once, originally there would be 2 sprites that didnt move, one for each player, then ater the GO sound played it would switch to the 2 player sprites that each player could move
i tried having a global modal sound play, which sort of works, but it stops any of hte map from being viewable (the whole thing shows up as black untill the sound is over, then it appears).
Title: Re: multiple 2-player maps
Post by: durnurd on 2006-02-06, 09:22:29 PM
There are several ways to make that work I believe.  One is to have an inventory item that increases by 1 automatically every frame (global function) and have a max of 1 or 2, initial of 0.  Then, another special function (global) activates that requires 1 (or 2) of the inventory and is removed on use, which plays the modal sound

OR, you could create an invisible sprite that has a 1-frame delay with an initial instance, and have it activate a special function at the end of the path that plays the modal sound (and deletes the sprite).  This requires no inventory to be added, happily enough.

Both of these don't use any script.  Also, it would be a good idea would be to put a short delay at the beginning of the audio file so it doesn't start playing too quickly.
Title: Re: multiple 2-player maps
Post by: bluemonkmn on 2006-02-07, 07:22:50 AM
I have a couple suggestions for a couple possibilities:
1. If you want to allow different sprites to act at the player 2 sprite, you should maybe settle on every player2 sprite starting with the word "Player2" and make sure no other sprites start with "Player2".  Then change this line:
Code: [Select]
If oLayer.Sprite(i).rDef.Name = "Player2" Then intSprTwo = ito this:
Code: [Select]
If Left(oLayer.Sprite(i).rDef.Name,7) = "Player2" Then intSprTwo = i
You might have to figure out a way to reset intSprTwo to -1 when player 2 switches sprites.  Maybe have the special function raise an event and in the Player_OnSpecialFunction function, set intSprTwo = -1.  For that matter you could probably just locate the index of the new player sprite right there instead.  There are many ways to handle it.

2. If there will ever be a time where there is no player 2 sprite active, add this line before the "With oLayer.Sprite(intSprTwo)":
Code: [Select]
If intSprTwo >= 0 Thenand add this after the End With:
Code: [Select]
End If