Code: Select all
Include "ide\cbJanelas.cb"
'Pääohjelma
SCREEN 400,300,0,0
FrameLimit 40
Type RAKETIT
Field obj
EndType
Type ASTEROIDIT
Field obj
Field hp
EndType
Type VIHUT
Field obj
Field hp#
Field id
EndType
Const TUTKA_X=225
Const TUTKA_Y=100
Const TUTKA_KOKO=50
maksimi=2
Global hp
hp#=100.0
kamera=MakeImage(200,150)
space=MakeImage(400,300)
DrawToImage space
For i=1 To 100
Dot Rand(0,399),Rand(0,299)
Next i
DrawToScreen
world=MakeObjectFloor()
PositionObject world,0,0,-500
PaintObject world,space
sina=LoadObject("media\sinä.bmp",72)
energia=LoadObject("media\energia.bmp")
hiiri=LoadImage("media\hiiri.bmp")
meteori=LoadObject("media\meteori.bmp")
ShowObject meteori,OFF
pu=LoadObject("media\power-up.bmp")
ma=LoadObject("media\musta-aukko.bmp",72)
raketti=LoadObject("media\Kranaatti.jpg")
ShowObject raketti,OFF
vihu=LoadObject("media\vihu.bmp",72)
ShowObject vihu,OFF
pää=LoadObject("media\päävihu.bmp")
h=MakeObject()
n=2
Repeat
ClsColor 56,62,184
ShowMouse hiiri
If pause Then
Else
PositionObject h,MouseWX(),MouseWY()
Gosub tarkista
Color 255,255,255
Text 251,9,"hp: "+hp
PositionObject pää,Int(750.1994),Int(-17.1)
If LeftKey() Then TurnObject sina,5
If RightKey() Then TurnObject sina, -5
If UpKey() Then MoveObject sina,n
If DownKey() Then MoveObject sina,-n
If KeyDown(42) Or KeyDown(54) Then n=8 Else n=2
If KeyHit(cbkeyspace) And reload=0 Then
newRaketti.RAKETIT= New(RAKETIT)
newRaketti\obj=CloneObject(raketti)
CloneObjectPosition newRaketti\obj,sina
CloneObjectOrientation newRaketti\obj,sina
MoveObject newRaketti\obj,40
reload=4
EndIf
i=0
For lVihu.VIHUT= Each VIHUT
For iRaketti.RAKETIT= Each RAKETIT
MoveObject iRaketti\obj,6
If After(lVihu)<>NULL Then
If ObjectsOverlap(lVihu\obj,iRaketti\obj,3) Then
id.VIHUT=lVihu
EndIf
If id=lVihu Then
PositionObject lVihu\obj,ObjectX(h),ObjectY(h)
EndIf
EndIf
i=i+1
Next iRaketti
Next lVihu
If reload>0 Then reload=reload-1
Text 248,60,"Ladatut ammukset: "+i
EndIf
If KeyHit(cbkeyP) Then pause=Not pause
camera(kamera,ObjectX(sina),ObjectY(sina))
DrawImage kamera,0,0
DrawScreen
Forever
Function nappi(Teksti$,x,y,leveys=0,korkeus=0)
leveys1=leveys
korkeus1=korkeus
If leveys1=0 Then leveys2=TextWidth(Teksti)
If korkeus1=0 Then korkeus2=TextHeight(Teksti)
'Napin pohjaväri. EI TEKSTIN VÄRI!
r=getRGB(RED)
g=getRGB(GREEN)
b=getRGB(BLUE)
Color r,g,b
If r=0 And g=0 And b=0 Then
r1=255
g1=255
b1=255
Else
r1=0
g1=0
b1=0
EndIf
Box x,y,leveys2,korkeus2
Color r1,r1,r1
Text x,y,Teksti
If MouseX() >=x And MouseX()<= x+leveys2 And MouseY() >= y And MouseY() <= y+korkeus2 Then
in=True
Else
in=False
EndIf
If in=True And MouseHit(1) Then
painettu=True
Else
painettu=False
EndIf
Return painettu
EndFunction
Function VähennäHp(maara#)
hp=hp-maara
Return hp#
EndFunction
Function camera(img,x,y)
l=ImageWidth(img)
k=ImageHeight(img)
UpdateGame
DrawToImage img
ClsColor cbblack
Cls
PositionCamera x,y
PositionCamera CameraX()+((ScreenWidth()-l)/2),CameraY()-((ScreenHeight()-k)/2)
DrawGame
DrawToScreen
EndFunction
Luo:
newVihu.VIHUT= New(VIHUT)
newVihu\obj=CloneObject(vihu)
newVihu\hp=4.0
Return
Return
tarkista:
Nykyinen_maara = 0
For vihumää.VIHUT = Each VIHUT
Nykyinen_maara + 1
Next vihumää
If Nykyinen_maara < Maksimi Then Gosub luo
Return