Problem bei Pacman

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

 

xXThunderXx

Betreff: Problem bei Pacman

BeitragSo, Jun 28, 2009 12:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo zusammen,

ich hab ein kleines Problem ich weis nicht mehr weiter. Ich will ein Pac-man programmieren jedoch scheitere ich an eine kleinichkeit. Ich will die gelbe punkte zeichnen was auch glabt, jedoch wenn ich eine kollision machen will mit den Punkt glabt sie nicht richtig. Ich wollte ein range einbauen usw. damit, wenn der Pac-Man dort rein kommt der Punkt aktiv = 0 gesetzt wird und genau da happerts.
Ich hoffe ihr könnt mir helfen.
Hir ist der code der Spiel Funktion
Code: [AUSKLAPPEN]

Function game()
Repeat



;Mapmalen
;Map und Coins malen
For y = 0 To 37
   For x = 0 To 49
      DrawImage map_bild,x*16,y*16,map(x,y)

   Next
Next

   standpunkt_x = pac(0)\x /16
   standpunkt_y = pac(0)\y /16   
   
   ;Coinmalen/Kollision 
   For i = 0 To 274
      If coin(i)\aktiv = 1 Then
         DrawImage coin_bild,(coin(i)\x),(coin(i)\y)
      EndIf
      If (pac(0)\x = coin(i)\x +5  Or pac(0)\x = coin(i)\x - 5 )   And   (pac(0)\y = coin(i)\y +5 Or  pac(0)\y = coin(i)\y -5 )  Then
         coin(i)\aktiv = 0
      EndIf
   Next
   .Bewegung
   ;Spieler Bewegung
      



   ;Rechts
   If KeyDown(205) And map(standpunkt_x + nachstes_frame ,standpunkt_y) = 9 Then
      pac(0)\frame = 0
      pac(0)\x = pac(0)\x + speed 
   EndIf
   ;Links
   If KeyDown(203) And map(standpunkt_x,standpunkt_y) = 9 Then
      pac(0)\frame = 2
      pac(0)\x = pac(0)\x - speed
   EndIf
   ;Hoch
   If KeyDown(200) And map(standpunkt_x ,standpunkt_y) = 9 Then
      pac(0)\frame = 3
      pac(0)\y = pac(0)\y - speed
   EndIf
   ;Runter
   If KeyDown(208) And map(standpunkt_x,standpunkt_y + nachstes_frame ) = 9 Then
      pac(0)\frame = 1
      pac(0)\y = pac(0)\y + speed
   EndIf

   DrawImage pac_man,pac(0)\x,pac(0)\y,pac(0)\frame
   
   If map(standpunkt_x + nachstes_frame,standpunkt_y) = 7 Then pac(0)\x = pac(0)\x - speed
   If map(standpunkt_x,standpunkt_y) = 7 Then pac(0)\y = pac(0)\y + speed
   If map(standpunkt_x,standpunkt_y + nachstes_frame) = 7 Then pac(0)\y = pac(0)\y - speed
   If map(standpunkt_x,standpunkt_y) = 7 Then pac(0)\x = pac(0)\x + speed
   

   
   
    Flip(1)
   Cls
   WaitTimer(timer)
Until KeyHit(1)
End
End Function


Hir der vom Menü
Code: [AUSKLAPPEN]

AppTitle "Pac-Man"

;Dateien Einlesen
Include "Map.bb"
Include "Function.bb"


Graphics 800,600,32,2
SeedRnd MilliSecs()
SetBuffer BackBuffer()
Global timer = CreateTimer(38)


;Menü bilder lade

Global background = LoadImage(".\gfx\hintergrund.png")
Global ki_leicht  = LoadImage(".\gfx\l_ki.png")
Global ki_mittel  = LoadImage(".\gfx\n_ki.png")
Global ki_schwer  = LoadImage(".\gfx\s_ki.png")
Global exit_bild  = LoadImage(".\gfx\exit.png")
Global maus       = LoadImage(".\gfx\maus.bmp")
;Bilder Laden
   Global map_bild = LoadAnimImage(".\gfx\innen.png",16,16,0,480)
   Global pac_man = LoadAnimImage(".\gfx\pac.png",20,20,0,4)
   MaskImage pac_man,255,0,255
   Global coin_bild = LoadImage(".\gfx\coin.png")

;Daten setzen
Global nachstes_frame = 1
Const speed = 8

i = 0
For y = 0 To 37
   For x = 0 To 49
      If map(x,y) = 9 And map(x+1,y+1) = 9 And map(x+1,y) = 9 And map(x,y+1) = 9  Then 
         coin(i)\aktiv = 1
         coin(i)\y = (y * 16) + 8
         coin(i)\x = (x * 16) + 8
         i = i + 1
      EndIf 
   Next
Next


Repeat

 

;Menü zeichen
DrawImage background,0,0
DrawImage ki_leicht,300,100
DrawImage ki_mittel,300,200
DrawImage ki_schwer,300,300
DrawImage exit_bild,300,400
 
;maus daten setzen
mx = MouseX()
my = MouseY()

;Killiseionen mit Buttons
 If ImagesOverlap(maus,mx,my,ki_leicht,300,100) And MouseDown(1) Then modus = 1
 If ImagesOverlap(maus,mx,my,ki_mittel,300,200) And MouseDown(1) Then modus = 2
 If ImagesOverlap(maus,mx,my,ki_schwer,300,300) And MouseDown(1) Then modus = 3
 If ImagesOverlap(maus,mx,my,exit_bild,300,400) And MouseDown(1) Then modus = 4   

;1. Sepielschleife

   Select modus
      
      Case 1
         game()

      Case 2
         game()
         
      Case 3
         game()
      
      Case 4
         End 
   End Select




WaitTimer(timer)
Flip
Cls
Forever


Ich weis nicht wo der fehler liegt

Nicdel

BeitragSo, Jun 28, 2009 13:02
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich habs mir noch nicht ganz durchgelesen, aber der Timer bringt nur mit Flip(0) was.
Desktop: Intel Pentium 4 2650 Mhz, 2 GB RAM, ATI Radeon HD 3850 512 MB, Windows XP
Notebook: Intel Core i7 720 QM 1.6 Ghz, 4 GB DDR3 RAM, nVidia 230M GT, Windows 7

mpmxyz

BeitragSo, Jun 28, 2009 13:41
Antworten mit Zitat
Benutzer-Profile anzeigen
Code: [AUSKLAPPEN]
      If (pac(0)\x = coin(i)\x +5  Or pac(0)\x = coin(i)\x - 5 )   And   (pac(0)\y = coin(i)\y +5 Or  pac(0)\y = coin(i)\y -5 )  Then
         coin(i)\aktiv = 0
      EndIf

Ich habe deinen Code mal überflogen, aber da muss sich der Pacman immer in je genau 5 Längeneinheiten X- und Y-Entfernung zu den Münzen befinden.
Das sollte bei Pacman unmöglich sein.
Besser ist das hier:
Code: [AUSKLAPPEN]
      If (Abs(pac(0)\x-coin(i)\x) <= 5)   And   (Abs(pac(0)\y-coin(i)\y) <= 5)  Then
         coin(i)\aktiv = 0
      EndIf

Das sollte der Grund sein.

Wenn du eine Kreisförmige Kollision haben möchtest, dann nehme stattdessen das hier:
Code: [AUSKLAPPEN]
If (pac(0)\x-coin(i)\x)^2+(pac(0)\y-coin(i)\y)^2<=5^2 then ...

Pythagoras lässt grüßen. Wink

mfG
mpmxyz
Moin Moin!
Projekte: DBPC CodeCruncher Mandelbrot-Renderer

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group