Code: Select all
# asetetaan näyttö
Screen.Set(800,600)
# muutamia muuttujia
Var screenw = 800
Var screenh = 600
Var delta_time As Float = 0.0
Var mapOp As Float = 0.5
Var textOp As Float = 1.0
Var cowOp As Float = 1.0
# lehmä-luokka
Class Cow
# jäsenmuuttujat - julkisia
Var pos, vel As Vector
Var img As Image
Var scale, tempScale, dScale As Float
# alustusfunktio
Function Init( Var _pos As Vector, Var _vel as Vector, Var i As Image, Var _rot As Float, Var _scale As Float ) As Void
pos = _pos
vel = _vel
img = i
scale = _scale
tempScale = _scale
dScale = 0.2
EndFunction
# päivitysfunktio
Function Update() As Void
pos += vel * delta_time
If pos.x < 0 Or pos.x > screenw Then vel.x = -vel.x
If pos.y < 0 Or pos.y > screenh Then vel.y = -vel.y
tempScale += dScale * delta_time
If tempScale < scale*0.7 Or tempScale > scale*1.3 Then dScale = -dScale
rot += 180 * delta_time
img.DrawRotated pos, rot, tempScale, tempScale
EndFunction
EndClass
# ladataan karttakuva ja asetetaan sille läpinäkyvyys
Var map As Image = New Image
map.Load "map.bmp"
map.SetOpacity mapOp
Var cow As Image = New Image
cow.AddMask 0,0,0 # asetaan ladattavalle lehmälle maskiväri : tämä tulee olla ennen latausta!
cow.Load "cow.png"
cow.SetOpacity cowOp # läpinäkyvyys
# luodaan tuhat lehmää
For i = 1 To 1000
Var pos, vel As Vector
pos.x = Random(0,screenw) : pos.y = Random(0,screenh) # : tarkoittaa moniriveä
vel.x = Random(-100,100) : vel.y = Random(-100,100)
Var rot As Float = Random(0,360)
Var scale As Float = Random(1,2)
Var c As Cow = New Cow # luoduille omille tyypeille luodaan automaattisesti linkitetty lista
c.Init( pos, vel, rot, scale ) # funktion voi ympäröidä suluilla, vaikkei se palauttaisikaan arvoa
Next
# fontti
Var font As Font = New Font
font.Load "porky.ttf"
Screen.SetFont font
Screen.SetColor 255,0,0,255*textOp
# kartan paikka ja nopeus
Var a,b,c,d,va,vb,vc,vd As Vector
a.x = 10 : a.y = 40
b.x = 400 : b.y = 100
c.x = 500 : c.y = 450
d.x = 100 : d.y = 200
va.x = 150 : va.y = -80
vb.x = 200 : vb.y = 200
vc.x = -350 : vc.y = -50
vd.x = -110 : vd.y = 60
Repeat
delta_time = GetFrameTime() # aika sekunteina ( tarkempi kuin yksi millisekunti )
# kartan liikutus
a += va*delta_time
b += vb*delta_time
c += vc*delta_time
d += vd*delta_time
# koordinaattien tarkistus
If a.x < 0 Or a.x > screenw Then a.x = -a.x
If a.y < 0 Or a.y > screenh Then a.y = -a.y
If b.x < 0 Or b.x > screenw Then b.x = -b.x
If b.y < 0 Or b.y > screenh Then b.y = -b.y
If c.x < 0 Or c.x > screenw Then c.x = -c.x
If c.y < 0 Or c.y > screenh Then c.y = -c.y
If d.x < 0 Or d.x > screenw Then d.x = -d.x
If d.y < 0 Or d.y > screenh Then d.y = -d.y
# päivitetään ja piirretään lehmät
For c As Cow = Each Cow
c.Update
Next
# piirretään kartta
map.Distort a,b,c,d
Screen.Text 10,10, "FPS: "+FPS()
Screen.Text 10,30, "Press Y/H to adjust cows' opacity.\nPress U/J to adjust text's opacity.\nPress I/K to adjust map's opacity."
# läpinäkyvyyden säätö
If Keyboard.Down( KEY_Y ) Then cowOp += delta_time
If Keyboard.Down( KEY_H ) Then cowOp -= delta_time
If Keyboard.Down( KEY_U ) Then textOp += delta_time
If Keyboard.Down( KEY_J ) Then textOp -= delta_time
If Keyboard.Down( KEY_I ) Then mapOp += delta_time
If Keyboard.Down( KEY_K ) Then mapOp -= delta_time
If cowOp < 0 Then cowOp = 0
If cowOp > 1 Then cowOp = 1
If textOp < 0 Then textOp = 0
If textOp > 1 Then textOp = 1
If mapOp < 0 Then mapOp = 0
If mapOp > 1 Then mapOp = 1
cow.SetOpacity cowOp
map.SetOpacity mapOp
Screen.SetColor 255,0,0,255*textOp
# piirretään näyttö
Screen.Draw
Forever
Koodissa saattaa olla typoja, mutta pääpiirteittäin asia tulee varmasti selväksi.
Mitä mieltä olette? Muutosehdotuksia? Ruusuja ja risuja?