Plattform Pacman - Päckchenproblem
Übersicht

CoralBetreff: Plattform Pacman - Päckchenproblem |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo Leute,
ich bin dabei ein "Platform Pacman" zu machen und stoße mal wieder auf einen Fehler. Ich weiß nicht, wie ich die Päckchen so zeichnen soll, dass man alle einzeln einsammeln -> verschwinden lassen kann. Außerdem bin ich noch nicht ganz zufrieden mit meiner Sprungfunktion aber seht selbst^^ Code: [AUSKLAPPEN] Graphics 800,600,32,2
SeedRnd(MilliSecs()) SetBuffer BackBuffer() Const Player_Speed = 3.5 Const Ghost_Speed = 2.5 Type TGhost Field x Field y Field Image End Type Type TPlayer Field x Field y Field score# Field Image End Type Type Tcoin Field x Field y Field Image End Type Global layout = LoadImage("level.bmp") Global player.Tplayer = New Tplayer player\Image = LoadImage("pacman_klein.bmp") Global Ghost1.TGhost = New TGhost Ghost1\Image = LoadImage("monster.bmp") Global Ghost2.TGhost = New TGhost Ghost2\Image = LoadImage("monster.bmp") Global Ghost3.TGhost = New TGhost Ghost3\Image = LoadImage("monster.bmp") Global Ghost4.TGhost = New TGhost Ghost4\Image = LoadImage("monster.bmp") Global coin.Tcoin = New Tcoin coin\Image = LoadImage("coin.bmp") Global Game_Over = LoadImage("Game Over.bmp") Global GoModus1 = 0 Global GoModus2 = 0 Global GoModus3 = 0 Global GoModus4 = 0 Global Lives = 3 Global Power = 15 Global MappositionX = 0, MappositionY = 0 Delay(200) InitializeLevel() timer = CreateTimer(60) ;----------------------------------------------------------------------------------------------- While Not KeyHit(1) Cls Physics() TestKeyboard() Coins() DrawImage (layout,MappositionX,MappositionY) DrawImage (player\Image,player\x,player\y) DrawImage (Ghost1\Image,Ghost1\x,Ghost1\y) DrawImage (Ghost2\Image,Ghost2\x,Ghost2\y) DrawImage (Ghost3\Image,Ghost3\x,Ghost3\y) DrawImage (Ghost4\Image,Ghost4\x,Ghost4\y) DrawScore() Ghosts() If Lives = 0 Then Restart() Flip 0 WaitTimer(timer ) Wend ;----------------------------------------------------------------------------------------------- Function InitializeLevel() Delay 2000 player\x = 400 player\y = 395 Ghost1\x = 200 Ghost1\y = 400 Ghost2\x = 200 Ghost2\y = 486 Ghost3\x = 437 Ghost3\y = 100 Ghost4\x = 580 Ghost4\y = 100 player\score = 0 Lives = 3 coin\y = 410 End Function Function Restart() Cls Locate 350,280 Print "GAME OVER" Delay 3000 Lives = 3 player\score = 0 player\x = 400 player\y = 395 End Function ;----------------------------------------------------------------------------------------------- Function DrawScore() Text 300,10,"Score: " + player\score Text 450,10,"Lives: " + Lives End Function ;----------------------------------------------------------------------------------------------- Function TestKeyboard() If KeyDown(200) And col_DetecteCollision(player,layout,MappositionX,MappositionY) <> 1 And Power > 0 ; Pfeiltaste hoch player\y = player\y - 20 Power = Power - 1 If col_DetecteCollision(player,layout,MappositionX,MappositionY) = 1 Then player\y = player\y + 11 If Power = 0 Then player\y = player\y + 11 EndIf EndIf If KeyDown(208) And col_DetecteCollision(player,layout,MappositionX,MappositionY) <> 1 ; Pfeiltaste runter player\y = player\y + player_Speed If col_DetecteCollision(player,layout,MappositionX,MappositionY) = 1 Then player\y = player\y - player_Speed EndIf End If If KeyDown(203) And col_DetecteCollision(player,layout,MappositionX,MappositionY) <> 1 ; Pfeiltaste links player\x = player\x - player_Speed If col_DetecteCollision(player,layout,MappositionX,MappositionY) = 1 Then player\x = player\x + player_Speed EndIf EndIf If KeyDown(205) And col_DetecteCollision(player,layout,MappositionX,MappositionY) <> 1 ; Pfeiltaste rechts player\x = player\x + player_Speed If col_DetecteCollision(player,layout,MappositionX,MappositionY) = 1 Then player\x = player\x - player_Speed EndIf End If If KeyHit(25) ; P Cls Text 400,300,"Press 'P' to Unpause Game" While Not KeyHit(25) ; P Wend EndIf End Function ;------------------------------------------------------------------------------------------------- ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; col_DetecteCollision() ; Ist für Alle kollisionen zuständig Function col_DetecteCollision(player.Tplayer,MapImage,MapX,MapY) Return ImagesCollide (player\Image, player\x, player\y, 0, MapImage, MapX, MapY, 0) End Function Function Ghosts() If ImagesCollide(Ghost1\Image, Ghost1\x, Ghost1\y, 0, player\Image, player\x, player\y, 0) Then Lives = Lives - 1 player\x = 400 player\y = 395 If Ghost1\x > 200 Then GoModus1 = 1 If Ghost1\x < 90 Then GoModus1 = 0 If GoModus1 = 0 Then Ghost1\x = Ghost1\x + 1 Else Ghost1\x = Ghost1\x - 1 If ImagesCollide(Ghost2\Image, Ghost2\x, Ghost2\y, 0, player\Image, player\x, player\y, 0) Then Lives = Lives - 1 player\x = 400 player\y = 395 If Ghost2\x > 550 Then GoModus2 = 1 If Ghost2\x < 0 Then GoModus2 = 0 If GoModus2 = 0 Then Ghost2\x = Ghost2\x + 1 Else Ghost2\x = Ghost2\x - 1 If ImagesCollide(Ghost3\Image, Ghost3\x, Ghost3\y, 0, player\Image, player\x, player\y, 0) Then Lives = Lives - 1 player\x = 400 player\y = 395 If Ghost3\x > 437 Then GoModus3 = 1 If Ghost3\x < 275 Then GoModus3 = 0 If GoModus3 = 0 Then Ghost3\x = Ghost3\x + 1 Else Ghost3\x = Ghost3\x - 1 If ImagesCollide(Ghost4\Image, Ghost4\x, Ghost4\y, 0, player\Image, player\x, player\y, 0) Then Lives = Lives - 1 player\x = 400 player\y = 395 If Ghost4\x > 660 Then GoModus4 = 1 If Ghost4\x < 505 Then GoModus4 = 0 If GoModus4 = 0 Then Ghost4\x = Ghost4\x + 1 Else Ghost4\x = Ghost4\x - 1 End Function Function Physics() player\y = player\y + 10 If ImagesCollide(player\Image, player\x, player\y, 0, layout, 0, 0, 0) Then player\y = player\y - 10 Power = 15 If player\y > 700 Then Lives = Lives - 1 player\x = 400 player\y = 395 If player\x => 784 Then player\x = player\x - 784 If player\x =< 0 Then player\x = player\x + 784 End Function Function Coins() For coin\x = 90 To 210 Step 20 DrawImage(coin\Image, coin\x, coin\y) Next End Function Hier sind die Bilder http://rapidshare.com/files/290446725/Bilder.zip Sorry der Code ist ein kleines bischen unordentlich ![]() |
||
![]() |
TimBo |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi,
du hast schonmal für die Coins eine Klasse erstellt. Fürge ihr noch eine Variable "status" zu. Wenn du einen Coin berührt hast wird er zu 0. Wenn er 0 ist, wird er nicht gemalt (auf collision geschaut etc). Oder du löschst einfach den Coin, wenn der Gegner drauf stößt. Grüße TimBo |
||
mfg Tim Borowski // CPU: Ryzen 2700x GPU: Nvidia RTX 2070 OC (Gigabyte) Ram: 16GB DDR4 @ 3000MHz OS: Windows 10
Stolzer Gewinner des BCC 25 & BCC 31 hat einen ersten Preis in der 1. Runde beim BWInf 2010/2011 & 2011/12 mit BlitzBasic erreicht. |
![]() |
gameworx |
![]() Antworten mit Zitat ![]() |
---|---|---|
Du hast zwar die Klasse "tcoin" angelegt, aber nur ein einziges Objekt coin erstellt. Du zeichnest in der Funktion "coins" zwar mehrere Münzen auf den Bildschirm, es handelt sich aber technisch nur um eine einzige Münze.
Eine Variable für "status" würde ich nicht benutzen. Ansonsten aber genau so wie TimBo sagt. Einfach für jede Münze ein Objekt anlegen und bei Kollission mit "delete coin" löschen. Dann sollte es eigentlich funktionieren. ![]() |
||
Coral |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Danke für die schnelle Antwort... Ich hatte mir schon fast gedacht, dass ich jeden coin einzeln zeichnen muss, aber ich war mir nicht sicher^^ | ||
![]() |
TimBo |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi,
das ist nicht schwer jeden Coin zu zeichnen. Einen Type erstellst du so c.coin= new coin das weißt du sicher. Dann machst du einfach BlitzBasic: [AUSKLAPPEN]
Grüße TimBo |
||
![]() |
orpheus_2003 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Und denk vielleicht auch da dran:
https://www.blitzforum.de/foru...gescollide Imagescollide ist gleich böse wie Goto..... ![]() |
||
GazerStar - the beginning
http://gazerstar.lexigame.de/ Wizard (Worktitel) http://wizard.lexigame.de |
Coral |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
@TimBo
...und dann kann ich auch für jeden coin eine Statusvariable machen? Oder hab ich dann wieder das Problem wie vorher, dass dann der Status von allen auf einmal auf 0 gesetzt wird? Ich hab schon angefangen jeden coin einzeln zu machen, aber wie funktioniert das bei deiner Methode? Im Moment habe ich zum Zeichnen: Code: [AUSKLAPPEN] If coin1\Status = 1 Then
DrawImage(coin1\Image, 50, 500) coin1\Status = 0 EndIf Das kann ich aber bei deiner Methode nicht so abfragen oder? |
||
![]() |
SpionAtom |
![]() Antworten mit Zitat ![]() |
---|---|---|
Types sind genau das richtige für die Coins. Man benötigt auch kein weiteres Attribut wie status.
Types sind ja nichts weiteres Listen, und jeder Listeneintrag entspräche dann einem Coin. Bei Kollision mit einem Coin, kann man mit Delete einen Listeneintrag (Coin) einfach Löschen. Es wäre glaub ich schlauer, wenn du dich nochmal grundlegend mit Types beschäftigst, sie würden bei richtigem Einsatz deinen Quellcode einfacher und flexibler machen. |
||
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080 |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group