339 lines
8.8 KiB
Text
339 lines
8.8 KiB
Text
|
|
|||
|
Global nopeus, vihunopeus#, hyppypower, painovoima#, maxPV#, pisteet, raha_alue, gamebgmfile$, loser, plop, pling, taso
|
|||
|
|
|||
|
Type vihut
|
|||
|
Field obj
|
|||
|
EndType
|
|||
|
|
|||
|
Type vihurajat
|
|||
|
Field obj
|
|||
|
EndType
|
|||
|
|
|||
|
Type rahat
|
|||
|
Field obj
|
|||
|
EndType
|
|||
|
|
|||
|
Function game(lvl, score, spd)
|
|||
|
|
|||
|
//Asetetaan perusarvot
|
|||
|
nopeus = 2 * spd // Hahmon liikkumisnopeus
|
|||
|
vihunopeus = 1 * spd // Vihujen liikkumisnopeus
|
|||
|
hyppypower = 16 // Ponnistusvoima
|
|||
|
painovoima = 1.5 // Puoamiskiihtyvyys
|
|||
|
maxPV = 10 // Suurin putoamisnopeus
|
|||
|
pisteet = score
|
|||
|
taso = lvl
|
|||
|
raha_alue = 15
|
|||
|
|
|||
|
//Ladataan resurssit
|
|||
|
kentt<74> = LoadMap("lvl" + Str(taso) + ".til", "lvl" + Str(taso) + ".bmp")
|
|||
|
ukko = LoadAnimObject("ukko.bmp", 30, 25, 0, 4)
|
|||
|
vihu_kuva = LoadAnimObject("vihu.bmp", 32, 32, 0, 11)
|
|||
|
ShowObject vihu_kuva, OFF
|
|||
|
raha_kuva = LoadObject("score.bmp")
|
|||
|
ShowObject raha_kuva, OFF
|
|||
|
goal = LoadObject("maali.bmp")
|
|||
|
plop = LoadSound("plop.wav")
|
|||
|
pling = LoadSound("pling.wav")
|
|||
|
loser = LoadSound("lost.wav")
|
|||
|
|
|||
|
//Kartan l<>pik<69>ynti
|
|||
|
For x = 1 To MapWidth()
|
|||
|
For y = 1 To MapHeight()
|
|||
|
Select GetMap2(3, x, y)
|
|||
|
Case 1 //Pelaaja l<>ytyi
|
|||
|
ObjectToMap(ukko, kentt<74>, x, y)
|
|||
|
CloneCameraPosition ukko
|
|||
|
SetupCollision ukko, kentt<74>, 1, 4, 2
|
|||
|
ObjectFloat ukko, 0 //Putoamisvauhti 0
|
|||
|
ObjectInteger ukko, False //Jalat irti maasta
|
|||
|
Case 2 //Vihu l<>ytyi
|
|||
|
vihu.vihut = New(vihut)
|
|||
|
vihu\obj = CloneObject(vihu_kuva)
|
|||
|
ObjectString vihu\obj, Str(-1) //Suunta vasemmalle
|
|||
|
ObjectFloat vihu\obj, 0 //Putoamisvauhti 0
|
|||
|
ObjectInteger vihu\obj, False //Jalat irti maasta
|
|||
|
LoopObject vihu\obj, 0, 10, 0.1 * spd, OFF
|
|||
|
ObjectRange vihu\obj, ObjectSizeX(kentt<74>) / MapWidth(), ObjectSizeY(kentt<74>) / MapHeight()
|
|||
|
SetupCollision vihu\obj, kentt<74>, 1, 4, 2
|
|||
|
SetupCollision vihu\obj, ukko, 1, 1, 2
|
|||
|
SetupCollision ukko, vihu\obj, 1, 1, 2
|
|||
|
ObjectToMap(vihu\obj, kentt<74>, x, y)
|
|||
|
Case 3 //Piste l<>ytyi
|
|||
|
raha.rahat = New(rahat)
|
|||
|
raha\obj = CloneObject(raha_kuva)
|
|||
|
SetupCollision ukko, raha\obj, 1, 1, 2
|
|||
|
ObjectRange raha\obj, raha_alue, raha_alue
|
|||
|
ObjectToMap(raha\obj, kentt<74>, x, y)
|
|||
|
Case 4 //Vihollisen alueen raja l<>ytyi
|
|||
|
vihuraja.vihurajat = New(vihurajat)
|
|||
|
vihuraja\obj = MakeObject()
|
|||
|
ObjectRange vihuraja\obj, ObjectSizeX(kentt<74>) / MapWidth(), ObjectSizeY(kentt<74>) / MapHeight()
|
|||
|
ObjectToMap(vihuraja\obj, kentt<74>, x, y)
|
|||
|
Case 5 //Maali l<>ytyi
|
|||
|
SetupCollision ukko, goal, 1, 1, 2
|
|||
|
objecttomap(goal, kentt<74>, x, y)
|
|||
|
EndSelect
|
|||
|
Next y
|
|||
|
Next x
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
For vihuraja.vihurajat = Each vihurajat
|
|||
|
SetupCollision vihu\obj, vihuraja\obj, 1, 1, 2
|
|||
|
SetupCollision vihuraja\obj, vihu\obj, 1, 1, 2
|
|||
|
Next vihuraja
|
|||
|
Next vihu
|
|||
|
|
|||
|
CameraFollow ukko, 1, 5
|
|||
|
Color 255, 255, 255
|
|||
|
ClsColor 0, 0, 0
|
|||
|
|
|||
|
// S<><53>litt<74>v<EFBFBD> ruutunopeus, koska optimointi omalle heikolle koneelleni...
|
|||
|
FrameLimit 30
|
|||
|
|
|||
|
///P<><50>silmukka
|
|||
|
|
|||
|
Repeat
|
|||
|
|
|||
|
|
|||
|
//Nollataan maassa-muuttujat
|
|||
|
ObjectInteger ukko, False
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
ObjectInteger vihu\obj, False
|
|||
|
Next vihu
|
|||
|
|
|||
|
//Tarkistetaan ja k<>sitell<6C><6C>n t<>rm<72>ykset
|
|||
|
//Pelaaja:
|
|||
|
t<>rm<72>ykset = CountCollisions(ukko)
|
|||
|
|
|||
|
For i = 1 To t<>rm<72>ykset
|
|||
|
|
|||
|
//Tarkistetaan pelaajan ja kent<6E>n t<>rm<72>ykset
|
|||
|
If GetCollision(ukko, i) = kentt<74> Then
|
|||
|
If CollisionAngle(ukko, i) = 90 And (Not jumped) Then // Maa?
|
|||
|
ObjectInteger ukko, True
|
|||
|
ObjectFloat ukko, 0
|
|||
|
ElseIf CollisionAngle(ukko, i) = 270 Then // Katto?
|
|||
|
ObjectFloat ukko, 0
|
|||
|
EndIf
|
|||
|
EndIf
|
|||
|
|
|||
|
//Tarkistetaan pelaajan ja vihujen t<>rm<72>ykset
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
If GetCollision(ukko, i) = vihu\obj Then
|
|||
|
If CollisionAngle(ukko, i) > 45 And CollisionAngle(ukko, i) < 135 Then
|
|||
|
ObjectFloat ukko, hyppypower
|
|||
|
DeleteObject vihu\obj
|
|||
|
Delete vihu
|
|||
|
PlaySound plop
|
|||
|
pisteet = pisteet + 10
|
|||
|
Else
|
|||
|
lost()
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
EndIf
|
|||
|
Next vihu
|
|||
|
|
|||
|
//Tarkistetaan pelaajan ja rahojen t<>rm<72>ykset
|
|||
|
For raha.rahat = Each rahat
|
|||
|
If GetCollision(ukko, i) = raha\obj Then
|
|||
|
PlaySound pling
|
|||
|
DeleteObject raha\obj
|
|||
|
pisteet = pisteet + 1
|
|||
|
Delete raha
|
|||
|
EndIf
|
|||
|
Next raha
|
|||
|
Next i
|
|||
|
|
|||
|
//Tarkistetaan pelaajan maaliin saapuminen
|
|||
|
If GetCollision(ukko, i) = goal Then
|
|||
|
won()
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
|
|||
|
//Vihut:
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
|
|||
|
t<>rm<72>ykset = CountCollisions(vihu\obj)
|
|||
|
|
|||
|
For i = 1 To t<>rm<72>ykset
|
|||
|
|
|||
|
//Tarkistetaan vihun ja kent<6E>n t<>rm<72>ykset
|
|||
|
If GetCollision(vihu\obj, i) = kentt<74> Then
|
|||
|
If CollisionAngle(vihu\obj, i) = 90 Then //Maa
|
|||
|
ObjectInteger vihu\obj, True
|
|||
|
ObjectFloat vihu\obj, 0
|
|||
|
ElseIf CollisionAngle(vihu\obj, i) = 270 Then //Katto
|
|||
|
ObjectFloat vihu\obj, 0
|
|||
|
ElseIf CollisionAngle(vihu\obj, i) = 180 Then //Vasen?
|
|||
|
ObjectString vihu\obj, Str(-1)
|
|||
|
ElseIf CollisionAngle(vihu\obj,i) = 0 Then //Oikea?
|
|||
|
ObjectString vihu\obj, Str(1)
|
|||
|
EndIf
|
|||
|
EndIf
|
|||
|
|
|||
|
//Tarkistetaan vihujen ja vihurajojen t<>rm<72>ykset
|
|||
|
For vihuraja.vihurajat = Each vihurajat
|
|||
|
If GetCollision(vihu\obj, i) = vihuraja\obj Then
|
|||
|
If CollisionAngle(vihu\obj, i) >= 90 And CollisionAngle(vihu\obj, i) < 270 Then //Vasen?
|
|||
|
ObjectString vihu\obj, Str(-1)
|
|||
|
Else //Oikea?
|
|||
|
ObjectString vihu\obj, Str(1)
|
|||
|
EndIf
|
|||
|
EndIf
|
|||
|
Next vihuraja
|
|||
|
|
|||
|
//Tarkistetaan vihujen ja pelaajan t<>rm<72>ykset
|
|||
|
If GetCollision(vihu\obj, i) = ukko Then
|
|||
|
If CollisionAngle(ukko, i) < 45 And CollisionAngle(ukko, i) > 135 Then
|
|||
|
ObjectFloat ukko, hyppypower
|
|||
|
DeleteObject vihu\obj
|
|||
|
Delete vihu
|
|||
|
PlaySound plop
|
|||
|
pisteet = pisteet + 10
|
|||
|
Else
|
|||
|
lost()
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
EndIf
|
|||
|
Next i
|
|||
|
Next vihu
|
|||
|
|
|||
|
//N<>pp<70>inten tarkistukset
|
|||
|
If LeftKey() Or KeyDown(cbkeya) Then
|
|||
|
PlayObject ukko, 2, 3, 0.1 * spd, OFF
|
|||
|
MoveObject ukko, -nopeus
|
|||
|
ElseIf RightKey() or KeyDown(cbkeyd) Then
|
|||
|
PlayObject ukko, 0, 1, 0.1 * spd, OFF
|
|||
|
MoveObject ukko, nopeus
|
|||
|
EndIf
|
|||
|
If Keyhit(cbKeyQ) Then
|
|||
|
' won()
|
|||
|
' Return False
|
|||
|
Else
|
|||
|
FrameLimit 30
|
|||
|
EndIf
|
|||
|
If ObjectInteger(ukko) And (UpKey() Or KeyHit(cbkeyspace) Or Keyhit(cbkeyw)) Then
|
|||
|
ObjectFloat ukko, hyppypower
|
|||
|
'jumped = True
|
|||
|
EndIf
|
|||
|
|
|||
|
|
|||
|
//K<>sitell<6C><6C>n painovoima
|
|||
|
ObjectFloat ukko, ObjectFloat(ukko) - painovoima
|
|||
|
If ObjectFloat(ukko) < -maxPV Then ObjectFloat ukko, -maxPV
|
|||
|
TranslateObject ukko, 0, ObjectFloat(ukko)
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
ObjectFloat vihu\obj, ObjectFloat(vihu\obj) - painovoima
|
|||
|
If ObjectFloat(vihu\obj) < -maxPV Then ObjectFloat vihu\obj, -maxPV
|
|||
|
TranslateObject vihu\obj, vihunopeus * Int(ObjectString(vihu\obj)), ObjectFloat(vihu\obj)
|
|||
|
Next vihu
|
|||
|
|
|||
|
//Tarkistetaan, ettei pudottu liikaa
|
|||
|
If ObjectY(ukko) < ObjectY(kentt<74>) - ObjectSizeY(kentt<74>) / 2 Then
|
|||
|
lost()
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
|
|||
|
///Kaikki itsest<73><74>n selv<6C>, mik<69> nyt kuitenkin ON t<><74>ll<6C>
|
|||
|
AddText "Scr: " + Str(pisteet)
|
|||
|
DrawScreen
|
|||
|
ClearText
|
|||
|
Forever
|
|||
|
ClearObjects
|
|||
|
EndFunction
|
|||
|
|
|||
|
Function lost()
|
|||
|
|
|||
|
PlaySound loser
|
|||
|
Color 10, 10, 10
|
|||
|
ClsColor 255, 0, 0
|
|||
|
|
|||
|
//Poistetaan objektit
|
|||
|
ClearObjects
|
|||
|
|
|||
|
//Tyhjennet<65><74>n tyypit
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
Delete vihu
|
|||
|
Next vihu
|
|||
|
For raha.rahat = Each rahat
|
|||
|
Delete raha
|
|||
|
Next raha
|
|||
|
For vihuraja.vihurajat = Each vihurajat
|
|||
|
Delete vihuraja
|
|||
|
Next vihuraja
|
|||
|
|
|||
|
//Poistetaan napit
|
|||
|
Nappi_Poista()
|
|||
|
|
|||
|
//Lopetuskysymys
|
|||
|
AddText "H<>visit. Pisteesi: " + Str(pisteet)
|
|||
|
Nappi_Lisaa(mainmargin, ScreenHeight() / 2 - 10, ScreenWidth() - mainmargin * 2, 20, "Poistu")
|
|||
|
ClearKeys
|
|||
|
|
|||
|
Repeat
|
|||
|
|
|||
|
nimi$ = Input("Anna nimesi: ")
|
|||
|
Nappi_Piirra()
|
|||
|
If Nappi_Paivita() = "Poistu" Or KeyHit(cbkeyreturn) Then
|
|||
|
CloseInput
|
|||
|
If nimi = "" Then nimi = "Nimet<65>n"
|
|||
|
lisaahs(nimi, pisteet)
|
|||
|
sound = PlaySound("buttonhit.wav")
|
|||
|
ClsColor bgrr, bgrg, bgrb
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
|
|||
|
DrawScreen
|
|||
|
|
|||
|
Forever
|
|||
|
|
|||
|
EndFunction
|
|||
|
|
|||
|
Function won()
|
|||
|
|
|||
|
Color 10, 10, 10
|
|||
|
ClsColor 0, 255, 0
|
|||
|
|
|||
|
//Poistetaan objektit
|
|||
|
ClearObjects
|
|||
|
|
|||
|
//Tyhjennet<65><74>n Type-jutut
|
|||
|
For vihu.vihut = Each vihut
|
|||
|
Delete vihu
|
|||
|
Next vihu
|
|||
|
For raha.rahat = Each rahat
|
|||
|
Delete raha
|
|||
|
Next raha
|
|||
|
For vihuraja.vihurajat = Each vihurajat
|
|||
|
Delete vihuraja
|
|||
|
Next vihuraja
|
|||
|
|
|||
|
//Poistetaan napit
|
|||
|
Nappi_Poista()
|
|||
|
|
|||
|
//Lopetuskysymys
|
|||
|
AddText "Voitit. Pisteesi: " + Str(pisteet)
|
|||
|
Nappi_Lisaa(mainmargin, ScreenHeight() / 2 - 10, ScreenWidth() - mainmargin * 2, 20, "Poistu")
|
|||
|
ClearKeys
|
|||
|
|
|||
|
Repeat
|
|||
|
|
|||
|
nimi$ = Input("Anna nimesi: ")
|
|||
|
Nappi_Piirra()
|
|||
|
If Nappi_Paivita() = "Poistu" Or KeyHit(cbkeyreturn) Then
|
|||
|
CloseInput
|
|||
|
If nimi = "" Then nimi = "Nimet<65>n"
|
|||
|
lisaahs(nimi, pisteet)
|
|||
|
sound = PlaySound("buttonhit.wav")
|
|||
|
ClsColor bgrr, bgrg, bgrb
|
|||
|
nextlvl = taso + 1
|
|||
|
If FileExists("lvl" + nextlvl + ".til") Then game(taso + 1, pisteet, 3)
|
|||
|
Return False
|
|||
|
EndIf
|
|||
|
|
|||
|
DrawScreen
|
|||
|
|
|||
|
Forever
|
|||
|
|
|||
|
EndFunction
|