BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Graphics3D 800,600,16,0 SetBuffer BackBuffer()
Global mfont=LoadFont("Tahoma",15,1) SetFont mfont
Global camp=CreatePivot() Global cam=CreateCamera(camp) CameraRange cam,1,10000 MoveEntity cam,0,0,-10
Global licht=CreateLight(2) LightRange licht,50
Global tex=CreateTexture(128,128) SetBuffer TextureBuffer(tex) Color 0,255,0 Rect 0,0,128,128 Color 0,128,0 Rect 0,0,64,64 Rect 64,64,64,64 SetBuffer BackBuffer() ScaleTexture tex,0.25,0.25 Global bru =CreateBrush(255,255,255) BrushTexture bru,tex
Global Welt=CreateCube() ScaleMesh Welt,0.5,0.5,0.5 ScaleMesh Welt,100,100,100
EntityPickMode Welt,2 FlipMesh Welt PaintMesh Welt,bru NameEntity Welt,"Welt"
Global lpiv=CreatePivot()
Global LaserGun=CreateCylinder(8,True,cam) ScaleMesh LaserGun,0.5,5,0.5 RotateMesh LaserGun,90,0,0 PositionMesh LaserGun,0,0,MeshDepth(LaserGun)/2 EntityColor LaserGun,128,128,128 PositionEntity LaserGun,0,-9,1,True
Type bumType Field bum Field bume Field timeout End Type Global bum.bumType
Type bulletType Field bullet Field strecke End Type Global b.bulletType
Type zielType Field ziel End Type Global ziel.zielType
HidePointer
Const cWelt=1 Const cBullet=2 Const cZiel=3
EntityType Welt,cWelt
Collisions cBullet,cWelt,2,1 Collisions cBullet,cZiel,2,1
Global Punkte Global Ziele Global SpielZeit Global StartZeit
MakeZiele
Local tx,ty
Local ti
While Not KeyHit(1)
ti=MilliSecs()
mx=MouseX() my=MouseY()
If Abs(GraphicsWidth() /2-mx)>80 Then TurnEntity camp,0,Sgn(GraphicsWidth()/2-mx)/2.0,0 If Abs(GraphicsHeight()/2-my)>80 Then TurnEntity cam,-Sgn(GraphicsHeight()/2-my)/2.0,0,0 If EntityPitch(cam)> 80 Then RotateEntity cam, 80,EntityYaw(cam),0 If EntityPitch(cam)<-80 Then RotateEntity cam,-80,EntityYaw(cam),0 EndIf
If CameraPick(cam,mx,my) Then PositionEntity lpiv,PickedX(),PickedY(),PickedZ() PointEntity LaserGun,lpiv CameraProject cam,PickedX(),PickedY(),PickedZ() tx=ProjectedX() ty=ProjectedY() EndIf
MoveBullet
If MouseHit(1) Then NewBullet End If
UpdateWorld TestBullet:UpdateBum RenderWorld
Color 255,255,255 Plot mx,my Color 255,0,0 Rect tx-10,ty-10,20,20,False Texto 15,15*1,"Punkte "+Punkte,0,0,255,255,255 Texto 15,15*2,"Ziele "+Ziele,0,0,255,255,255
If Ziele=0 Then Texto 15,15*4,"Deine Zeit "+SpielZeit+" sec.",0,0,200,255,200 Texto 15,15*5,"N für neues Spiel drücken",0,0,200,255,200 If KeyHit(49) Then MakeZiele EndIf
Flip Wend End
Function NewBullet() b.bulletType=New bulletType b\bullet=CreateSphere() ScaleMesh b\bullet,1,1,1 EntityType b\bullet,cBullet EntityRadius b\bullet,2 EntityColor b\bullet,255,0,0
PositionEntity b\bullet,EntityX(LaserGun,True),EntityY(LaserGun,True),EntityZ(LaserGun,True) RotateEntity b\bullet,EntityPitch(LaserGun,True),EntityYaw(LaserGun,True),EntityRoll(LaserGun,True) MoveEntity b\bullet,0,0,MeshDepth(LaserGun)+MeshDepth(b\bullet)/2.0 End Function
Function MoveBullet()
For b.bulletType=Each bulletType MoveEntity b\bullet,0,0,2 b\strecke=b\strecke+2 If b\strecke>250 Then DeleteBullet b Next
End Function
Function TestBullet()
For b.bulletType=Each bulletType If CountCollisions(b\bullet)>0 Then bum.bumType=New bumType bum\bum=CreateSphere(8) EntityColor bum\bum,255,255,0 EntityAlpha bum\bum,0.5 bum\timeout=100 PositionEntity bum\bum,EntityX(b\bullet),EntityY(b\bullet,1),EntityZ(b\bullet) bum\bume=EntityCollided(b\bullet,cZiel) DeleteBullet b EndIf Next
End Function
Function DeleteBullet(b.BulletType) FreeEntity b\bullet Delete b End Function
Function UpdateBum() For bum.bumType=Each bumType If bum\timeout>50 Then ScaleMesh bum\bum,1.02,1.02,1.02 Else ScaleMesh bum\bum,0.98,0.98,0.98 bum\timeout=bum\timeout-1 If bum\timeout=0 Then DeleteZiel bum\bume FreeEntity bum\bum:Delete bum Else UpdateZiel bum\bume EndIf Next
End Function
Function MakeZiele()
Ziele=0 Punkte=0
Local i
For i=1 To 20
ziel.zielType=New ZielType ziel\ziel=CreateCube() ScaleMesh ziel\ziel,2,2,2 EntityColor ziel\ziel,Rnd(0,255),Rnd(0,255),Rnd(0,255) EntityType ziel\ziel,cZiel PositionEntity ziel\ziel,Rnd(-45,45),Rnd(-45,45),Rnd(-45,45) EntityPickMode ziel\ziel,2 NameEntity ziel\ziel,"Ziel "+i
Ziele=Ziele+1
Next
SpielZeit=0 StartZeit=MilliSecs()
End Function
Function DeleteZiel(e)
For ziel.zielType=Each ZielType
If ziel\ziel=e Then FreeEntity ziel\ziel Delete ziel Ziele=Ziele-1 If Ziele=0 Then SpielZeit=Int(MilliSecs()-StartZeit)/1000 Exit EndIf
Next
End Function
Function UpdateZiel(e)
For ziel.zielType=Each ZielType
If ziel\ziel=e Then TurnEntity ziel\ziel,0,1,0 Punkte=Punkte+1 Exit EndIf
Next
End Function
Function TextO(x,y,t$,cx,cy,r,g,b)
Color 0,0,0
For a=-1 To 1 For b=-1 To 1 If a<>0 Or b<>0 Then Text x+a,y+b,t$,cx,cy EndIf Next Next
Color r,g,b Text x,y,t$,cx,cy
End Function
|