Speicherüberlauf

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

DrLove

Betreff: Speicherüberlauf

BeitragDi, Okt 18, 2005 13:16
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo zusammen, ich bin neu hier im Forum und auch sonst fang ich gerade erst an mit programmieren. Bisher klappte das auch alles super, nur bei meinem kleinem Spaceshooter hab ich arge Probleme. Und zwar läuft mein Speicher voll. Nu hab ich einzelne Codeabschnitte ausgeblockt, trotzdem klappt es net. Hier ist der geschriebene Code von mir (okay, ist sicher nix besonderes)
- vielleicht fällt euch was auf, ich verzweifel derweil mal weiter... Sad

BlitzBasic: [AUSKLAPPEN]
Graphics 640,480,16,1


.variablen
Global alien1 = LoadAnimImage(\"alienschiffe.bmp\",38,28,8,1)
Global alien2 = LoadAnimImage(\"alienschiffe.bmp\",38,28,4,1)
Global alien3 = LoadAnimImage(\"alienschiffe.bmp\",38,28,10,1)
Global held = LoadAnimImage(\"schiff1.bmp\",32,19,0,2)
Global back1 = LoadImage(\"stars.bmp\")
Global Lied
Global pos_x = 280
Global pos_y = 400
Global a1_x# = 50
Global a1_y# = 0
Global a2_x# = 100
Global a2_y# = 0
Global a3_x# = 150
Global a3_y# = 0
Global laser = LoadAnimImage(\"kugel.bmp\",15,17,0,1)
Global score = 0
Global ships = 5
Const rauf = 200, runter = 208, rechts = 205, links = 203, space = 57, a = 30

Type schuss
Field lx,ly
End Type


SetBuffer BackBuffer()
lied = PlayMusic(\"matrix.mid\")
While Not KeyHit(1)
Cls

.hintergrund
fontvariable1 = LoadFont (\"Impact\",25,0,0)

TileBlock back1,0-scrollx,0-scrolly

SetFont fontvariable1
Color 255,0,0
Text 50,0,\"SCORE:\"
Text 160,0,score
Text 500,0,\"SHIPS:\"
Text 580,0,ships

;Animation Hintergrund, wenn Held ist aktiv
If KeyDown (rauf) Then scrolly=scrolly - 5
If KeyDown (runter) Then scrolly=scrolly + 5
If KeyDown (rechts) Then scrollx=scrollx + 5
If KeyDown (links) Then scrollx=scrollx - 5

.HeldEngine
DrawImage held,pos_x,pos_y,I
MaskImage held,0,0,0
MaskImage laser,0,0,0
MaskImage alien1,0,0,0: MaskImage alien2,0,0,0: MaskImage alien3,0,0,0

;Animation Held
If MilliSecs() > frame + 100 Then
If KeyDown(rechts) Or KeyDown(links) Or KeyDown(rauf) Or KeyDown(runter) Then
I = I + 1
If I = 2 Then
I = 0
EndIf
EndIf
frame = MilliSecs()
EndIf

If Not KeyDown(rechts) Or KeyDown(links) Or KeyDown(rauf) Or KeyDown(runter) Then I = 0

;Bewegung Held
If KeyDown(rauf) Then pos_y = pos_y - 4
If KeyDown(runter) Then pos_y = pos_y + 4
If KeyDown(links) Then pos_x = pos_x - 4
If KeyDown(rechts) Then pos_x = pos_x + 4


;Bildschirmbegrenzung Held / Erstellung Laser
If pos_x < 0 Then pos_x = 0
If pos_x > 608 Then pos_x = 608
If pos_y < 30 Then pos_y = 30
If pos_y > 460 Then pos_y = 460

If KeyHit(a)
s.schuss = New schuss
s\lx = pos_x
s\ly = pos_y
EndIf

Color 255,255,0
For s.schuss = Each schuss
DrawImage laser,s\lx,s\ly
s\ly = s\ly-3
If s\ly < 0
Delete s.schuss
EndIf
Next

.feind1
Local c=50
DrawImage alien1,a1_x#,a1_y#
DrawImage alien1,a1_x#+c,a1_y#
DrawImage alien1,a1_x#+2*c,a1_y#
DrawImage alien1,a1_x#+3*c,a1_y#
DrawImage alien1,a1_x#+4*c,a1_y#

If pos_x >= a1_x# Then
a1_x# = a1_x# + 0.5
End If
If pos_x <= a1_x# Then
a1_x# = a1_x# - 0.5
End If
If pos_y >= a1_y# Then
a1_y# = a1_y# + 0.25
EndIf
If pos_y <= a1_y# Then
a1_y# = a1_y# - 0.25
End If

.feind2
If score > 400 Then DrawImage alien2,a2_x#,a2_y#

If pos_x >= a2_x# Then
a2_x# = a2_x# + 1
End If
If pos_x <= a2_x# Then
a2_x# = a2_x# - 1
End If
If pos_y >= a2_y# Then
a2_y# = a2_y# + 0.5
End If
If pos_y <= a2_y# Then
a2_y# = a2_y# - 0.5
End If

If ImagesCollide (alien1,a1_x#,a1_y#,0, alien2,a2_x#,a2_y#,0) Then
a1_x# = a1_x# + 2 Or a1_y# = a1_y# + 2
EndIf

.feind3
If score > 1400 Then DrawImage alien3,a3_x#,a3_y#

If pos_x >= a3_x# Then
a3_x# = a3_x# + 1.33
End If
If pos_x <= a3_x# Then
a3_x# = a3_x# - 1.33
End If
If pos_y >= a3_y# Then
a3_y# = a3_y# + 0.9
End If
If pos_y <= a3_y# Then
a3_y# = a3_y# - 0.9
End If

If ImagesCollide (alien2,a2_x#,a2_y#,0, alien3,a3_x#,a3_y#,0) Then
a2_x# = a2_x# + 2 Or a2_y# = a2_y# + 2
EndIf

.kollisionen
If ImagesOverlap (held,pos_x,pos_y, alien1,a1_x#,a1_y#) Then
ships = ships - 1
EndIf

If score > 400 Then
If ImagesOverlap (held,pos_x,pos_y, alien2,a2_x#,a2_y#) Then
ships = ships - 1
EndIf
EndIf

If score > 1400 Then
If ImagesOverlap (held,pos_x,pos_y, alien3,a3_x#,a3_y#) Then
ships = ships - 1
EndIf
EndIf

If KeyHit(28) Then score = score + 100

Flip
Wend
FreeImage alien1: FreeImage alien2: FreeImage alien3: FreeImage held
End

d-bug

BeitragDi, Okt 18, 2005 13:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Beim Überfliegen fällt mir nur auf, daß du bei jedem Durchlauf deiner Hauptschleife den Font neu lädst. Einmal laden reicht wohl.

falsch:
Code: [AUSKLAPPEN]
SetBuffer BackBuffer()
lied = PlayMusic("matrix.mid")
While Not KeyHit(1)
  Cls

.hintergrund
  fontvariable1 = LoadFont ("Impact",25,0,0)

...


besser (vielleicht):
Code: [AUSKLAPPEN]
Global fontvariable1 = LoadFont ("Impact",25,0,0)

SetBuffer BackBuffer()
lied = PlayMusic("matrix.mid")
While Not KeyHit(1)
  Cls

.hintergrund

...

DrLove

BeitragDi, Okt 18, 2005 13:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Ja richtig... dass ich das übersehen hab. Logisch das - und ich malte mir bereits ne mindestanforderung von 20GB RAM aus. Rolling Eyes

Vielen Dank - dann erarbeite ich mir nu die Kollision!

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group