Shooter Weltall problem
Übersicht

![]() |
Mathias-KwiatkowskiBetreff: Shooter Weltall problem |
![]() Antworten mit Zitat ![]() |
---|---|---|
so schnell das 2. problem, testet den code mal hier, der laser strahl soll natürlich in fahrtrichtung gesendet werden, aber irgendwie will der nicht , was amch ich falsch?
Code: [AUSKLAPPEN] Framework brl.glmax2d
Import brl.bmploader Import brl.httpstream Import brl.bankstream Graphics 1024, 768 Global char000:TImage = LoadImage(CreateBankStream(LoadBank("http::www.purechannel.ath.cx/000.bmp"))) Global Stars:TImage = LoadImage(CreateBankStream(LoadBank("http::www.purechannel.ath.cx/001.bmp"))) MidHandleImage(Char000) Global x:Float = 150, y:Float = 150 Global geschwindigkeit:Float = 0 Global winkel:Int Global CamX:Int, CamY:Int While Not KeyHit(KEY_ESCAPE) Cls For xs = 0 To 5000 Step 256 For ys = 0 To 5000 Step 256 DrawImage Stars, xs - CamX, ys - CamY Next Next If KeyDown(KEY_LEFT) Then winkel = winkel + 2 If KeyDown(KEY_RIGHT) Then winkel = winkel - 2 If KeyDown(KEY_UP) Then geschwindigkeit = geschwindigkeit + 0.01 If geschwindigkeit > 5 Then geschwindigkeit = 5 EndIf If Not KeyDown(KEY_UP) Then geschwindigkeit = geschwindigkeit - 0.01 If geschwindigkeit <= 0 Then geschwindigkeit = 0 EndIf If KeyDown(KEY_DOWN) Then geschwindigkeit = geschwindigkeit - 0.05 EndIf If KeyDown(KEY_SPACE) Then SetColor 255, 255, 0 DrawLine 1024 / 2, 768 / 2, 1024 - x, 768 - y SetColor 255, 255, 255 End If x = x + Cos(winkel) * geschwindigkeit y = y - Sin(winkel) * geschwindigkeit CamX = x CamY = y SetRotation (- winkel) DrawImage char000, 1024 / 2 - ImageWidth(char000) / 2, 768 / 2 - ImageHeight(char000) / 2 SetRotation (0) DrawText "Geschwindigkeit:" + geschwindigkeit + " Winkel:" + winkel + " Cam X:" + CamX + " Cam Y:" + CamY, 10, 10 Flip Wend End |
||
battlegorge |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Du musst die Linie auch mit sin/cos berechen, so wie dus bei x und y gemacht hast!
Code: [AUSKLAPPEN] Strict Graphics 640,480,0 Global x#=320,y#=240,dir#=0,speed#=2,size#=40,target#=4*size Repeat Cls If KeyDown(key_left) dir:-2 If KeyDown(key_right) dir:+2 If dir>360 dir:-360 If dir<0 dir:+360 If KeyDown(key_up) x:+ speed*Cos(dir) y:+ speed*Sin(dir) EndIf DrawOval x-size/2,y-size/2,size,size DrawLine x+(size/2)*Cos(dir),y+(size/2)*Sin(dir),x+target*Cos(dir),y+target*Sin(dir) DrawText dir,10,10 Flip 1 Until KeyHit(key_escape) Or AppTerminate() |
||
Matthias |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hay. Da ich mich auch schon einmal mit diesem Genre befasst habe, weis ich wie schwer es dann später wird, wenn mann mehr wie ein Laser haben will.
Deshalb habe ich dir mal ein Beispiel gemacht. Vieleicht kannst du damit was anfangen. Code: [AUSKLAPPEN] Framework brl.glmax2d Import brl.bmploader Import brl.httpstream Import brl.bankstream Graphics 1024, 768 Global char000:TImage = LoadImage(CreateBankStream(LoadBank("http::www.purechannel.ath.cx/000.bmp"))) Global Stars:TImage = LoadImage(CreateBankStream(LoadBank("http::www.purechannel.ath.cx/001.bmp"))) MidHandleImage(Char000) Global Schiff:TSchiff[10] Global CamPosX#,CamPosY# Type TSchiff Field PosX#,PosY# Field LPortX[10],LPortY[10] Field Winkel#,Gesch# Field Feuer,MaxLaser,LLange End Type CreateSchiff(500,500) CreateSchiff(700,700) Function CreateSchiff(X,Y) While Schiff[SID]<>null SID:+1 Wend Schiff[SID]=New TSchiff Schiff[SID].PosX=X Schiff[SID].PosY=Y Schiff[SID].LPortX[0]=13 Schiff[SID].LPortY[0]=-23 Schiff[SID].LPortX[1]=13 Schiff[SID].LPortY[1]=23 Schiff[SID].LLange=150 Schiff[SID].MaxLaser=1 End Function While Not KeyHit(KEY_ESCAPE) Cls For xs = 0 To 5000 Step 256 For ys = 0 To 5000 Step 256 DrawImage Stars, xs - CamPosX, ys - CamPosY Next Next UpdateSchiffe() Flip Wend End Function UpdateSchiffe() SchiffStrg() While Schiff[SID]<>null S:TSchiff=Schiff:TSchiff[SID] Sn#=sin(S.Winkel*-1) Co#=cos(S.Winkel*-1) S.PosX:+Co*S.Gesch S.PosY:-Sn*S.Gesch X#=S.PosX-CamPosX Y#=S.PosY-CamPosY SetRotation S.Winkel DrawImage char000,X,Y SetRotation 0 SetColor 255,255,0 If S.Feuer Then For P=0 To S.MaxLaser FX=X+S.LPortX[P]*Co+S.LPortY[P]*Sn FY=Y+S.LPortY[P]*Co-S.LPortX[P]*Sn TX=FX+Co*S.LLange TY=FY-Sn*S.LLange DrawLine FX,FY,TX,TY S.Feuer=0 Next End If SetColor 255,255,255 SID:+1 Wend SetRotation 0 End Function Function SchiffStrg() S:TSchiff=Schiff:TSchiff[CamSID] If KeyDown(KEY_LEFT) S.Winkel:-2 If KeyDown(KEY_RIGHT) S.Winkel:+2 If KeyDown(KEY_UP) Then S.Gesch:+.01 If S.Gesch>5 S.Gesch=5 If Not KeyDown(KEY_UP) Then S.Gesch:-.01 If S.Gesch<0 Then S.Gesch=0 If KeyDown(KEY_DOWN) Then S.Gesch:-.05 If KeyDown(KEY_SPACE) Then S.Feuer=1 CamPosX=S.PosX-GraphicsWidth()*.5 CamPosY=S.PosY-GraphicsHeight()*.5 End Function Gruß Matthias |
||
![]() |
Firstdeathmaker |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hmm, schonmal was von OOP gehört?
Beispiel für Spaceshooter Basics. Idee: Basictype TGameObject, davon werden alle auf dem Spielfeld vorkommenden Objekte abgeleitet. Logik und Grafik werden strikt getrennt. Code: [AUSKLAPPEN] Graphics 800,600,0
New TShip Repeat Logic() Cls Render() Flip Until KeyHit(KEY_ESCAPE) End Function Logic() TGameObject.Update() End Function Function Render() TGameObject.Render() End Function Type TGameObject Global list:TList = New TList Function Update() For Local o:TGameObject = EachIn TGameObject.list o.Logic() Next End Function Function Render() For Local o:TGameObject = EachIn TGameObject.list o.Draw() Next End Function Field pos:Float[2] Field direction:Float'For movement. Field rotation:Float'For drawing Field speed:Float'current speed Field link:TLink Method New() link = TGameObject.List.AddLast(Self) End Method Method Logic() Self.Move() End Method Method Move() pos[0]:+Sin(direction)*speed pos[1]:-Cos(direction)*speed End Method Method Draw() SetRotation Self.rotation DrawRect Self.pos[0],Self.pos[1],10,10 End Method Method Remove() RemoveLink(Self.Link) End Method End Type Type TShip Extends TGameObject Field engine_acc:Float = .3'acceleration Field engine_speed:Float = 3.0 'maximum speed Field img_ship:TImage Method New() 'img_ship = LoadImage(CreateBankStream(LoadBank("http::www.purechannel.ath.cx/000.bmp"))) If img_ship MidHandleImage(img_ship) pos[0] = 400 pos[1] = 300 End Method Method Logic() If KeyDown(KEY_UP) Accelerate(1) If KeyDown(KEY_DOWN) Accelerate(-1) If KeyDown(KEY_LEFT) Turn(-1) If KeyDown(KEY_RIGHT) Turn(1) If KeyHit(KEY_SPACE) Local s:TShot = New TShot s.pos[0] = Self.pos[0] s.pos[1] = Self.pos[1] s.direction = Self.direction s.rotation = Self.rotation EndIf Super.move() End Method Method Accelerate(strength:Float)'-1 maximum backwards, 1 = maximum forwards speed:+engine_acc*strength If speed>engine_speed speed = engine_speed If speed<-engine_speed speed = -engine_speed End Method Method Turn(strength:Float)'-1 maximum to the left, +1 maximum to the right Self.direction:+strength Self.rotation:+strength End Method Method Draw() SetRotation Self.rotation If img_ship DrawImage Self.img_ship,pos[0],pos[1] Else DrawRect pos[0],pos[1],20,30 EndIf End Method End Type Type TShot Extends TGameObject Field lifetime:Int Method New() lifetime = MilliSecs() + 2000 speed = 5 End Method Method Logic() If lifetime<MilliSecs() Remove() Super.move() End Method Method Draw() SetRotation 0 DrawLine pos[0],pos[1],pos[0]+Sin(rotation)*10,pos[1]-Cos(rotation)*10 End Method End Type |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
![]() |
Mathias-Kwiatkowski |
![]() Antworten mit Zitat ![]() |
---|---|---|
danke für eure vielen antworten, werde mich nun ran setzen. | ||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group