Rumballern auf Würfel von Markus |
Ohne Worte :wink: [code:1:8dffe867a1] ;Blitz Basic 3D Example , Rumballern auf Würfel ;MR 08.04.2003 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 ;Ziele sollten auch Pickable sein ! FlipMesh Welt PaintMesh Welt,bru NameEntity Welt,"Welt" ;----------------------------------------- Global lpiv=CreatePivot() ;Zum anvisieren und ausrichten der Gun ein Pivot Global LaserGun=CreateCylinder(8,True,cam) ScaleMesh LaserGun,0.5,5,0.5 ;lang ziehen RotateMesh LaserGun,90,0,0 ;Rohr nach vorne PositionMesh LaserGun,0,0,MeshDepth(LaserGun)/2 ;Vorne anfassen EntityColor LaserGun,128,128,128 PositionEntity LaserGun,0,-9,1,True ;nach unten im Screen ;----------------------------------------- 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 ;Zielpos. in 2D ;----------------------------------------- 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 ;Links Rechts If Abs(GraphicsHeight()/2-my)>80 Then TurnEntity cam,-Sgn(GraphicsHeight()/2-my)/2.0,0,0 ;Hoch runter If EntityPitch(cam)> 80 Then RotateEntity cam, 80,EntityYaw(cam),0 ;damit man nicht auf den Kopf steht den Winkel begrenzen :-) 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 ;Scheiß NVidia Detonator Treiber schneckt ;While Abs(MilliSecs()-ti)<20 ;50 FPS ;Wend Flip Wend End ;---------------------------------------------------------------------------------------- Function NewBullet() b.bulletType=New bulletType bullet=CreateSphere() ScaleMesh bullet,1,1,1 EntityType bullet,cBullet EntityRadius bullet,2 EntityColor bullet,255,0,0 PositionEntity bullet,EntityX(LaserGun,True),EntityY(LaserGun,True),EntityZ(LaserGun,True) RotateEntity bullet,EntityPitch(LaserGun,True),EntityYaw(LaserGun,True),EntityRoll(LaserGun,True) MoveEntity bullet,0,0,MeshDepth(LaserGun)+MeshDepth(bullet)/2.0 End Function ;---------------------------------------------------------------------------------------- Function MoveBullet() For b.bulletType=Each bulletType MoveEntity bullet,0,0,2 bstrecke=bstrecke+2 If bstrecke>250 Then DeleteBullet b Next End Function ;---------------------------------------------------------------------------------------- Function TestBullet() For b.bulletType=Each bulletType If CountCollisions(bullet)>0 Then bum.bumType=New bumType bumum=CreateSphere(8) EntityColor bumum,255,255,0 EntityAlpha bumum,0.5 bum imeout=100 PositionEntity bumum,EntityX(bullet),EntityY(bullet,1),EntityZ(bullet) bumume=EntityCollided(bullet,cZiel) DeleteBullet b EndIf Next End Function ;---------------------------------------------------------------------------------------- Function DeleteBullet(b.BulletType) FreeEntity bullet Delete b End Function ;---------------------------------------------------------------------------------------- Function UpdateBum() For bum.bumType=Each bumType If bum imeout>50 Then ScaleMesh bumum,1.02,1.02,1.02 Else ScaleMesh bumum,0.98,0.98,0.98 bum imeout=bum imeout-1 If bum imeout=0 Then DeleteZiel bumume FreeEntity bumum:Delete bum Else UpdateZiel bumume EndIf Next End Function ;---------------------------------------------------------------------------------------- Function MakeZiele() Ziele=0 Punkte=0 Local i For i=1 To 20 ziel.zielType=New ZielType zielziel=CreateCube() ScaleMesh zielziel,2,2,2 EntityColor zielziel,Rnd(0,255),Rnd(0,255),Rnd(0,255) EntityType zielziel,cZiel PositionEntity zielziel,Rnd(-45,45),Rnd(-45,45),Rnd(-45,45) EntityPickMode zielziel,2 NameEntity zielziel,"Ziel "+i Ziele=Ziele+1 Next SpielZeit=0 StartZeit=MilliSecs() End Function ;---------------------------------------------------------------------------------------- Function DeleteZiel(e) For ziel.zielType=Each ZielType If zielziel=e Then FreeEntity zielziel 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 zielziel=e Then TurnEntity zielziel,0,1,0 Punkte=Punkte+1 Exit EndIf Next End Function ;---------------------------------------------------------------------------------------- Function TextO(x,y,t$,cx,cy,r,g,b) ;Outline Text :-) 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 ;---------------------------------------------------------------------------------------- [/code:1:8dffe867a1] |
von ??? |
Ganz nett. Nur wenn man erst auf die wand zeigt und dann auf nen würfel oder anders herum, sieht das etwas komisch aus wenn der lauf der waffe sich so ruckartig auf den würfel / die wand ausrichtet |
von ??? |
[quote:9fcc13e107="DC"]Ganz nett. Nur wenn man erst auf die wand zeigt und dann auf nen würfel oder anders herum, sieht das etwas komisch aus wenn der lauf der waffe sich so ruckartig auf den würfel / die wand ausrichtet[/quote:9fcc13e107] Hi, weiß ich ,aber so trifft man auch :wink: |
von ??? |
hehe, gefällt mir!! wirklich gut idee! :) |