Scrolling Game Development Kit Forum
SGDK Version 1 => Script => Topic started 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.
'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
'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
'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.
-
I believe all you need to do is remove the subsequent "If"s. So it should be
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
-
hmm, well that stopped the syntax error, but now none of the maps specified are being displayed as 2 player
-
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.
-
yep, that fixed it!
-
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?
-
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.
-
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
-
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)
'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
-
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:
Set oLayer = oMap.MapLayer(1)
to something like this:
If oMap.Name = "0-4LevelSelect" Then Set oLayer = oMap.MapLayer(1) Else Set oLayer = oMap.MapLayer(2)
-
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
-
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:
Set oLayer = oMap.MapLayer("Main")
-
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?
-
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?
-
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).
-
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.
-
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:
If oLayer.Sprite(i).rDef.Name = "Player2" Then intSprTwo = i
to this:
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)":
If intSprTwo >= 0 Then
and add this after the End With:
End If