Joo tolla on tosiaan kiva leikkiä. Itelläni tuolla löyty jotain koodia tyyliin p_stream$string, p_fcurrentdate#float jne.
E: Olin tekemässä tällaista peliä viikkokisaan, mutta mielenkiinto ei vain säilynyt. Koodi on melko kommentoitua, joten en ajattelin laittaa tämän avoimeksi lähdekoodiksi, jotta voisin sanoa itseäni open source kehittäjäksi.
Code: Select all
//
' Feel free to modify :)
//
SCREEN 800,620
SetWindow "Blox Blox"
//
// GAME DATA
//
' Variables for the blocks. They
' declares the position
Dim blockx(2)
Dim blocky(2)
' This is the blink timer for
' falling block
Global blinktimer
Global blinking
Global falltimer
blinktimer = Timer()
falltimer = Timer()
' This is data for undoing moves
' Note that 999 moves is the max!
Dim historyx(999)
Dim historyy(999)
Global datanow
' Type for all the blocks to
' the map. x, y declare position,
' d - declare the map data given
Type mdata
Field x
Field y
Field d
EndType
Global author$
Global lvlname$
Global resource$
Global level
level = 1
' Special data
Global activate
Global completed
Global needed
' Flash intro globals
Global Int_Dir
Global Int_Amount
Global font
font = LoadFont("arial",20)
SetFont font
//
// CALL MAIN FUNCTION
//
Main()
//
// FUNCTIONS
//
' This function gets the data
' of block. Eq. dat = GetData(10,4)
Function GetData(x,y)
Dim b.mdata
For b.mdata = Each mdata
If b\x = x And b\y = y Then Return b\d
Next b
EndFunction
' Neary same but this function sets
' the block data
Function SetData(x,y,d)
Dim b.mdata
For b.mdata = Each mdata
If b\x = x And b\y = y Then b\d = d
Next b
EndFunction
' Very close of the previous,
' but this creates a new block
Function PutData(x,y,d)
Dim b.mdata
b.mdata = New(mdata)
b\x = x
b\y = y
b\d = d
EndFunction
' Boolean. Are the blocks in
' a pile? Return true if is so,
' false as its not.
Function InPile()
Return ((blockx(1) = blockx(2)) And (blocky(1) = blocky(2)))
EndFunction
' Boolean. Is there block falling? True if so
Function Falling()
If GetData(Blockx(1),Blocky(1))=0 Or GetData(Blockx(2),Blocky(2))=0 Then
Return 1
Else
If GetData(Blockx(1),Blocky(1))=3 And Activate = 0 Then Return 1 Else Return 0
EndIf
EndFunction
' Draws player blocks. If they are in
' pile, show it to player with color
Function DrawPlayerBlocks()
If InPile() Then Color 255,255,0 Else Color 0,255,0
Box blockx(1)*20,blocky(1)*20,20,20
Box blockx(2)*20,blocky(2)*20,20,20
EndFunction
' Draws the game blocks
Function DrawGameBlocks()
Dim b.mdata
For b.mdata = Each mdata
Color cbsilver
'If b\d Then Box b\x*10,b\y*10,10,10
Select b\d
Case 1: WiseBlock(b\x,b\y,1)
Case 2: WiseBlock(b\x,b\y,2)
Case 3
If Activate Then WiseBlock(b\x,b\y,1) Else WiseBlock(b\x,b\y,4)
Case 4: WiseBlock(b\x,b\y,3)
Case 9
If completed = needed Then
If blinking Then WiseBlock(b\x,b\y,9)
Else
WiseBlock(b\x,b\y,9)
EndIf
EndSelect
Next b
EndFunction
' Level complete - portal
Function CompletePortal()
If both(4) Then
completed = completed + 1
SetData(blockx(1),blocky(1),1)
activate = Not activate
EndIf
EndFunction
' Loads the blocks from a
' file.
Function LoadBlocks$(res$)
Dim resf
Dim strl$
resf = OpenToRead(res)
Dim a
While Not EOF(resf)
strl = Left(ReadLine(resf),40)
Dim i
For i = 0 To Len(strl)
PutData(i,a,Int(Mid(strl,i+1,1)))
If Mid(strl,i+1,1) = 9 Then
blockx(1) = i
blockx(2) = i
blocky(1) = a
blocky(2) = a
EndIf
If Mid(strl,i+1,1) = 4 Then needed = needed + 1
Next i
a = a + 1
Wend
CloseFile(resf)
Return strl
EndFunction
' Moves the blocks
Function Move(dirx,diry)
If dirx <> 0 Or diry <> 0 Then
If InPile() Then
Blockx(1) = Blockx(1) + dirx*2
Blocky(1) = blocky(1) + diry*2
Blockx(2) = Blockx(2) + dirx
Blocky(2) = Blocky(2) + diry
Else
If blockx(1) = blockx(2) And dirx <> 0 Then
blockx(1) = blockx(1) + dirx
blockx(2) = blockx(2) + dirx
Else
If dirx = 1 Then
If blockx(1)<blockx(2) Then
blockx(1) = blockx(1) + 1
Else
blockx(2) = blockx(2) + 1
EndIf
ElseIf dirx = -1
If blockx(1)<blockx(2) Then
blockx(2) = blockx(2) - 1
Else
blockx(1) = blockx(1) - 1
EndIf
EndIf
EndIf
If blocky(1) = blocky(2) And diry <> 0 Then
blocky(1) = blocky(1) + diry
blocky(2) = blocky(2) + diry
Else
If diry = 1 Then
If blocky(1)<blocky(2) Then
blocky(1) = blocky(1) + 1
Else
blocky(2) = blocky(2) + 1
EndIf
ElseIf diry = -1
If blocky(1)<blocky(2) Then
blocky(2) = blocky(2) - 1
Else
blocky(1) = blocky(1) - 1
EndIf
EndIf
EndIf
EndIf
datanow = datanow + 1
historyx(datanow) = dirx
historyy(datanow) = diry
ActivateBridge()
EndIf
EndFunction
' This function shows a red box in
' the point where might be a falling
' block controlled by player
Function DropBlock()
Color Blinking*255,0,0
If Falling() Then
Box Blockx(1)*20,Blocky(1)*20,20,20
Box Blockx(2)*20,Blocky(2)*20,20,20
EndIf
EndFunction
' This allows player control the
' blocks
Function PlayerControl()
If Falling() = False Then Move(KeyHit(cbkeyright)-KeyHit(cbkeyleft),(KeyHit(cbkeydown)-KeyHit(cbkeyup)))
EndFunction
' Updates the blinking timer for
' drop block function
Function UpdateBlinkTimer()
If Timer()>Blinktimer+500 Then
Blinking = Not Blinking
Blinktimer = Timer()
EndIf
EndFunction
' Undo the move
' Return 0 if failed
Function Undo()
If datanow > 0 Then
datanow = datanow - 1
Move(historyx(datanow),historyy(datanow))
Else
Return 0
EndIf
EndFunction
' Redo the move
' Return 0 if failed
Function Redo()
If falling() = False And historyx(datanow+1)<>0 And historyy(datanow+1)<>0 Then
datanow = datanow + 1
Move(historyx(datanow),historyy(datanow))
Else
Return 0
EndIf
EndFunction
' This function checks is the
' block touching that type of
' gameblock
Function One(t)
Return (GetData(Blockx(1),Blocky(1))=t Or GetData(Blockx(2),Blocky(2))=t)
EndFunction
' Is both touching a block
Function Both(t)
Return (GetData(Blockx(1),Blocky(1))=t And GetData(Blockx(2),Blocky(2))=t)
EndFunction
' Activates the bridge
Function ActivateBridge()
If One(2) Then activate = Not activate
EndFunction
' This function handles the
' history given to the array
Function HandleHistory()
If KeyHit(cbkeyr) Then Redo()
If KeyHit(cbkeyu) Then Undo()
EndFunction
Function WiseBlock(x,y,t)
Select t
Case 1
Color 160,160,160
Box x*20,y*20,20,20
Color 130,130,130
Box x*20,y*20,20,20,0
Color 160,160,160
Box x*20+1,y*20+1,19,19
Case 2
Color 0,0,160
Box x*20,y*20,20,20
Color 0,0,130
Box x*20,y*20,20,20,0
Color 0,0,160
Box x*20+1,y*20+1,19,19
Case 3
Color 0,160,0
Box x*20,y*20,20,20
Color 0,130,0
Box x*20,y*20,20,20,0
Color 0,160,0
Box x*20+1,y*20+1,19,19
Case 9
Color 160,160,0
Box x*20,y*20,20,20
Color 130,130,0
Box x*20,y*20,20,20,0
Color 160,160,0
Box x*20+1,y*20+1,19,19
EndSelect
EndFunction
Function ClearBlocks()
Dim b.mdata
For b.mdata = Each mdata
Delete b
Next b
EndFunction
' This is not part of the game,
' but this let the splash look better :D
Function FlashIntro(Con$)
Int_Amount = 1
Int_Dir = 1
While True
If Int_Amount < 200 Then
Int_Amount = Int_Amount + (Int_Dir*10)
Else
Int_Amount = Int_Amount + (Int_Dir*2)
EndIf
If Int_Amount > 254 Then Int_Dir = -Int_Dir
If Int_Amount < 1 Then Exit
Color Int_Amount,Int_Amount,Int_Amount
CenterText ScreenWidth()/2,ScreenHeight()/2,Con$
DrawScreen
Wend
EndFunction
' Show bottom bar
Function BottomBar()
Color cbsilver
Text 5,ScreenHeight()-25,completed+"/"+needed+" "+datanow
EndFunction
' This function starts the current
' level over and clears the data
Function StartOver()
ClearBlocks()
datanow = 0
needed = 0
completed = 0
activate = 0
main()
EndFunction
' This goes to the next level
' and clears the data
Function NextLevel()
level = level + 1
ClearBlocks()
datanow = 0
needed = 0
completed = 0
activate = 0
main()
EndFunction
//
// TEH MAIN PROGRAM
//
Function Main()
resource = LoadBlocks("maps/"+level+".txt")
FlashIntro("Level "+Level)
While True
If falling() Then StartOver()
If Both(9) And completed = needed And needed > 0 Then NextLevel()
HandleHistory()
DrawGameBlocks()
DrawPlayerBlocks()
PlayerControl()
UpdateBlinkTimer()
BottomBar()
CompletePortal()
DrawScreen
Wend
EndFunction
Peli tarvitsee toimiakseen oma tekemiä karttoja Maps/ kansiossa tyyliin 1.txt, 2.txt, 3.txt jne. Joiden sisältö on esim. tällainen (Tätä voi käyttää testaamiseen)
0 tarkoittaa samaa kuin ei mitään, 1 tarkoittaa lattiaa, 9 on aloituspaikka, 3 on lattiaa joka ilmestyy kun kytkin on aktivoitu, joka merkitään 2. 4 taas on portaali, jotka täytyy painaa pohjaan, jotta palaamalla alkupaikkaan (9) pääsisi seuraavalle tasolle.
Kun on yksi keltainen palikka, ne ovat pinossa, ja silloin täytetään liikkuessa 2 paikkaa vihreillä palikoilla 4 eri suunnassa. Kun ei olla pinossa, täytetään 1 keltainen palikka, joka on liikesuunasta laskettuna uloimman vihreän palikan koordinaateissa. Sininen 2 kytkin tarvitsee vain vihreän palikan kosketuksen, kun taas 4 portaali ja 9 seuraavataso - portaali tarvitsevat keltaisen palikan.
E2: Ainiin, portaalit laittavat päälle / pois päältä ilmestyviä lattioita.
E3: Peli on tehty toimivaksi FVD:n kanssa.