Prinzipieller Aufbau von Pong

Anfängerfragen zum Programmieren mit PureBasic.
Benutzeravatar
lassma-asma
Beiträge: 107
Registriert: 10.07.2007 09:14
Wohnort: Saarland

Beitrag von lassma-asma »

Zero_Cool hat geschrieben:@ lassma-asma
Vielen Dank für das Angebot. Werde gerne zu einem späteren Zeitpunkt darauf zurückkomen. Ich möchte das Spiel mehr oder weniger selber schreiben und nicht kopieren! Multi Pong ist sowas wie mein Ziel, tolles Programm.
war erst jetzt wieder on ... danke fürs Lob , hört man gerne ...
wenn deins fertig ist schreib mir doch ma per PN ...
Gruß lassma-asma

MultiPONG
HANGMAN


PB 3.94 und PureBasic 4.51 !!!
Zero_Cool
Beiträge: 84
Registriert: 04.12.2004 15:14

Beitrag von Zero_Cool »

Klar, danke. Mache ich gerne. Allerdings schlage ich mich immer noch mit Winkel und Ki herum :mrgreen: Nicht so einfach... vielen Dank für eure Hilfe.

Wir aber schon klappen! Werde gerne darauf zurück kommen!
Chance favors the prepared mind - Havrilla Design - My Gfx
Zero_Cool
Beiträge: 84
Registriert: 04.12.2004 15:14

Beitrag von Zero_Cool »

Abend Zusammen,

Habe eben eine erste komplett lauffähige Version erstellt. Leider bin ich vom Resultat nicht besonders überzeugt! Es läuft, aber irgendwie stimmt das mit dem Winkel und dem Computer-Gesteuerten Gegner nicht wirklich. Besser bringe ich es aber leider nicht hin. Hat irgendjemand Vorschläge zur Verbesserung?

Code: Alles auswählen

;- Konstante 

width = 810 
height = 610 

cr.d = 0
cl.d = 0
cr$ = StrD(cr,0)
cl$ = StrD(cl,0)

bx = 200 ; x-Achse
mx = 3

by = 305 ; y-Achse
my = 3

cy = 305

;- Initialisation 

If Not OpenWindow(0, 0, 0, width, height, "Pong", #PB_Window_ScreenCentered) 
End 
EndIf 

If Not (InitKeyboard() And InitSprite()) 
End 
EndIf 

If Not OpenWindowedScreen(WindowID(0), 0, 0, width, height, 0, 0, 0) 
End 
EndIf 

;- Schriftart

If Not LoadFont(0, "OCR A Std", 80) 
End 
EndIf 

;-Sprites

If Not CreateSprite(0, 20, 100) 
End 
EndIf 

If StartDrawing(SpriteOutput(0)) 
Box(0, 0, 20, 100, $FFFFFF) 
StopDrawing() 
EndIf 

; Sprite Rechts

If Not CreateSprite(1, 20, 100) 
End 
EndIf 

If StartDrawing(SpriteOutput(1)) 
Box(0, 0, 20, 100, $FFFFFF) 
StopDrawing() 
EndIf 

; Sprite Oben

If Not CreateSprite(2, 800, 10) 
End 
EndIf 

If StartDrawing(SpriteOutput(2)) 
For n=0 To 800 Step 20 
Box(n-10, 0, 10, 10, $FFFFFF) 
Next 
StopDrawing() 
EndIf 

; Sprite Unten

If Not CreateSprite(3, 800, 10) 
End 
EndIf 

If StartDrawing(SpriteOutput(3)) 
For n=0 To 800 Step 20 
Box(n-10, 0, 10, 10, $FFFFFF) 
Next 
StopDrawing() 
EndIf 

; Sprite Mitte

If Not CreateSprite(4, 10, 560) 
End 
EndIf 

If StartDrawing(SpriteOutput(4)) 
For n=0 To 600 Step 20 
Box(0, n-10, 10, 10, $FFFFFF) 
Next 
StopDrawing() 
EndIf 

; Sprite Ball

If Not CreateSprite(5, 20, 20) 
End 
EndIf 

If StartDrawing(SpriteOutput(5)) 
Box(0, 0, 20, 20, $FFFFFF) 
StopDrawing() 
EndIf 

; Sprite Links (Goal)

If Not CreateSprite(6, 10, 560) 
End 
EndIf 

If StartDrawing(SpriteOutput(6)) 
Box(0, 0, 10, 560, $000000) 
StopDrawing() 
EndIf 

; Sprite Rechts (Goal)

If Not CreateSprite(7, 10, 560) 
End 
EndIf 

If StartDrawing(SpriteOutput(7)) 
Box(0, 0, 10, 560, $000000) 
StopDrawing() 
EndIf 

;- Endlose Schleife 

Define y = (height - 100) / 2
Repeat    
  
ExamineKeyboard() ; Aktualisiert den Tastatur-Status 
ClearScreen(RGB(0, 0, 0)) 
  
; Inhalt 
If KeyboardPushed(#PB_Key_Up)
If y <= 20
y = 20 
Else 
y - 3 
EndIf 
EndIf 
  
If KeyboardPushed(#PB_Key_Down) 
If y => height - 120
y = height - 120 
Else 
y + 3 
EndIf
EndIf 

If bx = 200 ; Startet Zähler für y-Achse des Balles
county = y
EndIf

If bx = 560 ; Startet Zähler für y-Achse des Balles
county = cy
EndIf

; Collision Rechts
If SpriteCollision(1, 780, cy, 5, bx, by)
mx=-3
my = -(county - y)/30
EndIf

; Collision Links
If SpriteCollision(0, 10, y, 5, bx, by)
mx=3
my = -(county - y)/30
EndIf

; Collision Rechts (Goal)
If SpriteCollision(6, 800, 20, 5, bx, by)
cl.d + 1
cl$ = StrD(cl,0)
bx = 200
mx = 3 

by = 305
my = 3
EndIf

; Collision Links (Goal)
If SpriteCollision(7, 0, 20, 5, bx, by)
cr.d + 1
cr$ = StrD(cr,0)
bx = 200
mx = 3 

by = 305
my = 3
EndIf

; Collision Oben
If SpriteCollision(2, 0, 10, 5, bx, by)
my=my*-1
EndIf

; Collision Unten
If SpriteCollision(3, 0, 590, 5, bx, by)
my=my*-1
EndIf


bx+mx ; Bewegung x-Achse
by+my ; Bewegung y-Achse

 ;-Ki-Spieler

If bx > 500

If (by - cy) > 10
cy = cy + 3
EndIf
If (by - cy) < -10
cy = cy - 3
EndIf

EndIf

DisplaySprite(0, 10, y) ; Spieler Links
DisplaySprite(1, 780, cy) ; Spieler Rechts
DisplaySprite(2, 0, 10)  ; Sprite Oben
DisplaySprite(3, 0, 590) ; Sprite Unten
DisplaySprite(4, 400, 20) ; Sprite Mitte
DisplaySprite(5, bx, by) ; Sprite Ball
DisplaySprite(6, 0, 20) ; Goal Links
DisplaySprite(7, 800, 20) ; Goal Rechts

;-Counter
StartDrawing(ScreenOutput()) 
DrawingFont(FontID(0)) 
DrawingMode(#PB_2DDrawing_Transparent) 
DrawText(310, 35, cl$, $FFFFFF) 
StopDrawing() 

StartDrawing(ScreenOutput()) 
DrawingFont(FontID(0)) 
DrawingMode(#PB_2DDrawing_Transparent) 
DrawText(423, 35, cr$, $FFFFFF) 
StopDrawing()
  
FlipBuffers() 
  
; Window-Events abarbeiten 

While WindowEvent()
Wend 

Until KeyboardReleased(#PB_Key_Escape) 
Chance favors the prepared mind - Havrilla Design - My Gfx
Antworten