Author Topic: multiple 2-player maps  (Read 7895 times)

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
multiple 2-player maps
« 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.
"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
Re: multiple 2-player maps
« Reply #1 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
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #2 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
"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
Re: multiple 2-player maps
« Reply #3 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.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #4 on: 2006-01-30, 12:16:27 PM »
yep, that fixed 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
Re: multiple 2-player maps
« Reply #5 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?
"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
Re: multiple 2-player maps
« Reply #6 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.

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #7 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
"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
Re: multiple 2-player maps
« Reply #8 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
"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
Re: multiple 2-player maps
« Reply #9 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)

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #10 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
"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
Re: multiple 2-player maps
« Reply #11 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")

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #12 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?
"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
Re: multiple 2-player maps
« Reply #13 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?
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: multiple 2-player maps
« Reply #14 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).
« Last Edit: 2006-02-06, 08:39:11 PM by billybob884 »
"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