Olen ohjelmoinut noin 10vuotta ja alunperin itseoppinut quick basic vääntäjä. Opiskelen ohjelmistotuotantoa tty:llä ja hallitsen noin puolen tusinaa kieltä. Muutama päivä sitten löysin cool basic vahingossa ja olin hyvin skeptinen kieleen. Yllätyin iloisesti kielen graafisista olioista ja niiden helppokäyttöisyydestä. Testatessani kielen perusominaisuuksia huomasin tunnin jälkeen tehneeni noin 150 rivillä(ilman optimointeja) tasohyppelypelin.
Edit:
Beta: Sisältö valmis. Paljon hiomista.
SpiderCow.
vasen-/oikeanuoli: liikkuminen/seinätarraus
ylöspäinuoli: hyppy
alaspäinnuoli: liito
m: musiikit on/off
s: äänet on/off
space: radan resetointi
pgUp: radan skippaus.
esc: lopetus
Code: Select all
FrameLimit 50 'limit game speed
SCREEN 800,600,0, 0
Smooth2D ON
Randomize Timer()
music=PlaySound ("media/game_06.xm", 50)
sheep=LoadSound("media/sheep.wav")
pop=LoadSound("media/pop.wav")
scream=LoadSound("media/scream1.wav")
whip=LoadSound("media/whip.wav")
aim = MakeObject()
painovoima As Float = 0.25
sounds As Byte = True
nopeusY As Float = 0
hyppy As Byte = True
tuplahyppy As Byte = False
taso As integer = 0
Gosub Alusta
Repeat
'Tarkistaa onko lehmä tatin kanssa päällekäin tai painetaanko page-up nappia
tile = GetMap(0, ObjectX(cow),ObjectY(cow))
tileAlla = GetMap(1, ObjectX(cow),ObjectY(cow) - 15)
If tile = 49 or KeyHit(201) Then
'Seuraavaa leveliä varten tehdään uusi kartta
taso = taso + 1
Gosub alusta
EndIf
'jos tippunut ulos ruudulta
If tile = 0 and nopeusY < -15 Then
Gosub alusta
End If
'jos lentohiekkaa
If (tileAlla >= 205 And tileAlla <= 208) Or (tileAlla >= 221 And tileAlla <= 224) Or (tileAlla >= 237 And tileAlla <= 240) Or (tileAlla >= 253 And tileAlla <= 256) Then
If sounds Then PlaySound whip, 50
karttaX As integer = koordinaatistaTileksiX(ObjectX(cow), MapWidth())
karttaY As integer = koordinaatistaTileksiY(ObjectY(cow)-15, MapHeight())
EditMap map, 1, karttaX, karttaY, 0
EditMap map, 2, karttaX, karttaY, 0
If nopeusY < 0 Then
nopeusY = 0.5
End If
tuplahyppy = False
EndIf
'jos laava
If (tile >= 35 And tile <= 38) Or (tile >= 51 And tile <= 54) Then
If sounds Then PlaySound scream, 50
Gosub Alusta
EndIf
If KeyHit(57) Then
Gosub alusta
EndIf
'Jos S näppäin niin äänet on/off
If KeyHit(31) Then
sounds = Not sounds
EndIf
'Jos M näppäin niin musiikit on/off
If KeyHit(50) Then
If SoundPlaying(music) Then
StopSound music
Else
music=PlaySound ("media/game_06.xm", 50)
EndIf
EndIf
'jos ylöspäin näppäin
If UpKey() Then
'Jos ei olla ilmassa ja viime hypystä on jo palauduttu
If hyppy = False And hyppytimer = 0
hyppytimer = 25 'seuraava hyppy vasta 20framen päästä
nopeusY = 5 'hyppyimpulssi
hyppy = True
If sounds Then PlaySound pop, 50
ElseIf tuplahyppy = False And hyppytimer = 0
hyppytimer = 25 'seuraava hyppy vasta 25framen päästä
nopeusY = 4 'hyppyimpulssi
tuplahyppy = True
If sounds Then PlaySound sheep
End If
End If
'Jos alapäin näppäintä niin liitää
If DownKey() Then
nopeusY = nopeusY * 0.93
End If
'Jos vasemmalle näppäin niin liikuta lehmää ja pyöritä animaatiota
If LeftKey()
TranslateObject cow, -3,0
PlayObject cow,2,3,0.25, OFF
PositionObject aim, ObjectX(cow) + Rnd(8)+30 ,ObjectY(cow) - 150
End If
'Jos oikella näppäin niin liikuta lehmää ja pyöritä animaatiota
If RightKey()
TranslateObject cow,3,0
PlayObject cow,0,1,0.25, OFF
'suunnataan lehmä alaspäin, hieman lepatellen
PositionObject aim, ObjectX(cow) + Rnd(8)-30 ,ObjectY(cow) - 150
End If
'Jos lehmä tippuu alaspäin ei olla kiinteällä pinnalla ja ei voida hypätä
If nopeusY < -1 Then
hyppy = True
'suunnataan lehmä alaspäin, hieman lepatellen
PositionObject aim, ObjectX(cow) + Rnd(8)-30 ,ObjectY(cow) - 150
End If
'Jos lehmä törmännyt tile kartaan
For i = 1 to CountCollisions(cow)
'ohjaa lehmän jalat alustaan mihin törmätty lattia/seinä/katto
PositionObject aim, CollisionX (cow, i), CollisionY(cow, i)
angle = CollisionAngle(cow,i)
'Jos lattiaan
If angle = 90 Then
If nopeusY <= 0
nopeusY = 0
EndIf
tuplahyppy=False
hyppy = False
End If
'Jos kattoon
If angle => 270 Then
nopeusY = 0
EndIf
'Jos seinään
If angle = 0 Or angle = 180 Then
tuplahyppy=False
'tarraa seinään jos on tippumassa mutta ei silloin kuin menossa ylöspäin
If nopeusY < 0 Then
nopeusY = nopeusY * 0.75
EndIf
End If
Next i
'siirretään korkeus akselilla nopeuden verran
TranslateObject cow,0, Int(nopeusY)
'Lisätään korkeusakselin vauhtiin painovoiman aiheuttama kiihtyvyys
nopeusY = nopeusY - painovoima
If hyppytimer > 0 Then
hyppytimer = hyppytimer -1
End If
PointObject cow,aim
TurnObject cow, 90
DrawScreen ON, ON
Until EscapeKey()
End
alusta:
ClearText
AddText "Level:" + taso
seuraava As String = "media\level" + taso + ".til"
If not FileExists(seuraava) Then
End
End If
If map Then
DeleteObject map
EndIf
map=LoadMap(seuraava,"media\tileset.bmp")
If cow Then
DeleteObject cow
End If
cow=LoadAnimObject ("media/animcow.bmp", 30, 25, 0, 4, 120)
SetupCollision cow,map,1,4,2
LoopObject map
PositionObject cow, -500,50
nopeusY = 0
hyppy= True
tuplahyppy = True
CameraFollow cow, 1, 35
Return
Function KoordinaatistaTileksiX(koordinaattiX, kartanleveys)
Return Int((koordinaattiX + 16 * kartanleveys) / 32 + 1)
End Function
Function KoordinaatistaTileksiY(koordinaattiY, kartankorkeus)
Return Int((16 * kartankorkeus - koordinaattiY) / 32 )+1
End Function
Edit2: Tiedosto+koodi versio uusittu.
Edit3. beta versio ladattavissa