Appearance
Lösungen
Aufgabe 2
python
import pgtrun
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.left = 0
links.y = HEIGHT / 2
rechts = Actor("schlaeger_rot.png")
rechts.right = WIDTH
rechts.y = HEIGHT / 2
pgtrun.go()Aufgabe 3
python
import pgtrun
def update():
bewege_schläger()
def bewege_schläger():
if keyboard[keys.Q]:
links.y = links.y - 5
if keyboard[keys.A]:
links.y = links.y + 5
if keyboard[keys.O]:
rechts.y = rechts.y - 5
if keyboard[keys.L]:
rechts.y = rechts.y + 5
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.left = 0
links.y = HEIGHT / 2
rechts = Actor("schlaeger_rot.png")
rechts.right = WIDTH
rechts.y = HEIGHT / 2
pgtrun.go()Aufgabe 4
python
import pgtrun
import random
def anspiel(richtung):
ball.x = WIDTH / 2
ball.y = HEIGHT / 2
ball.vx = 4 * richtung
ball.vy = random.randrange(-2, 2)
def update():
bewege_schläger()
bewege_ball()
def bewege_schläger():
if keyboard[keys.Q] and links.top > 0:
links.y = links.y - 5
if keyboard[keys.A] and links.bottom < HEIGHT:
links.y = links.y + 5
if keyboard[keys.O] and rechts.top > 0:
rechts.y = rechts.y - 5
if keyboard[keys.L] and rechts.bottom < HEIGHT:
rechts.y = rechts.y + 5
def bewege_ball():
ball.x = ball.x + ball.vx
ball.y = ball.y + ball.vy
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
ball.draw()
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.left = 0
links.y = HEIGHT / 2
rechts = Actor("schlaeger_rot.png")
rechts.right = WIDTH
rechts.y = HEIGHT / 2
ball = Actor("ball.png")
anspiel(1)
pgtrun.go()Aufgabe 5
python
import pgtrun
import random
def anspiel(richtung):
ball.x = WIDTH / 2
ball.y = HEIGHT / 2
ball.vx = 4 * richtung
ball.vy = random.randrange(-2, 2)
def update():
bewege_schläger()
bewege_ball()
def bewege_schläger():
if keyboard[keys.Q] and links.top > 0:
links.y = links.y - 5
if keyboard[keys.A] and links.bottom < HEIGHT:
links.y = links.y + 5
if keyboard[keys.O] and rechts.top > 0:
rechts.y = rechts.y - 5
if keyboard[keys.L] and rechts.bottom < HEIGHT:
rechts.y = rechts.y + 5
def bewege_ball():
ball.x = ball.x + ball.vx
ball.y = ball.y + ball.vy
if ball.bottom > HEIGHT:
ball.vy = -ball.vy
if ball.top < 0:
ball.vy = -ball.vy
if ball.colliderect(links):
ball.vx = -ball.vx
if ball.colliderect(rechts):
ball.vx = -ball.vx
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
ball.draw()
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.left = 0
links.y = HEIGHT / 2
rechts = Actor("schlaeger_rot.png")
rechts.right = WIDTH
rechts.y = HEIGHT / 2
ball = Actor("ball.png")
anspiel(1)
pgtrun.go()Aufgabe 6
python
import pgtrun
import random
import anzeige
def anspiel(richtung):
ball.x = WIDTH / 2
ball.y = HEIGHT / 2
ball.vx = 4 * richtung
ball.vy = random.randrange(-2, 2)
def update():
bewege_schläger()
bewege_ball()
def bewege_schläger():
if keyboard[keys.Q] and links.top > 0:
links.y = links.y - 5
if keyboard[keys.A] and links.bottom < HEIGHT:
links.y = links.y + 5
if keyboard[keys.O] and rechts.top > 0:
rechts.y = rechts.y - 5
if keyboard[keys.L] and rechts.bottom < HEIGHT:
rechts.y = rechts.y + 5
def bewege_ball():
ball.x = ball.x + ball.vx
ball.y = ball.y + ball.vy
if ball.bottom > HEIGHT:
ball.vy = -ball.vy
if ball.top < 0:
ball.vy = -ball.vy
if ball.colliderect(links):
ball.vx = -ball.vx
if ball.colliderect(rechts):
ball.vx = -ball.vx
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
ball.draw()
anzeige.zeige_zahl(100, 50, links.punkte)
anzeige.zeige_zahl(800, 50, rechts.punkte)
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.punkte = 0
links.left = 0
links.y = HEIGHT / 2
rechts = Actor("schlaeger_rot.png")
rechts.punkte = 0
rechts.right = WIDTH
rechts.y = HEIGHT / 2
ball = Actor("ball.png")
anspiel(1)
pgtrun.go()Aufgabe 7
python
import pgtrun
import random
import anzeige
def anspiel(richtung):
ball.x = WIDTH / 2
ball.y = HEIGHT / 2
ball.vx = 4 * richtung
ball.vy = random.randrange(-2, 2)
def update():
bewege_schlaeger()
bewege_ball()
def bewege_schläger():
if keyboard[keys.Q] and links.top > 0:
links.y = links.y - 5
if keyboard[keys.A] and links.bottom < HEIGHT:
links.y = links.y + 5
if keyboard[keys.O] and rechts.top > 0:
rechts.y = rechts.y - 5
if keyboard[keys.L] and rechts.bottom < HEIGHT:
rechts.y = rechts.y + 5
def bewege_ball():
ball.x = ball.x + ball.vx
ball.y = ball.y + ball.vy
if ball.bottom > HEIGHT or ball.top < 0:
ball.vy = -ball.vy
if ball.colliderect(links):
ball.vx = -ball.vx
if ball.colliderect(rechts):
ball.vx = -ball.vx
if ball.left < 0:
rechts.punkte = rechts.punkte + 1
anspiel(-1)
if ball.right > WIDTH:
links.punkte = links.punkte + 1
anspiel(1)
def draw():
screen.fill(hintergrundfarbe)
links.draw()
rechts.draw()
ball.draw()
anzeige.zeige_zahl(100, 50, links.punkte)
anzeige.zeige_zahl(800, 50, rechts.punkte)
WIDTH = 900
HEIGHT = 500
TITLE = "Pong"
hintergrundfarbe = 100, 50, 0
links = Actor("schlaeger_blau.png")
links.left = 0
links.y = HEIGHT / 2
links.punkte = 0
rechts = Actor("schlaeger_rot.png")
rechts.right = WIDTH
rechts.y = HEIGHT / 2
rechts.punkte = 0
ball = Actor("ball.png")
anspiel(1)
pgtrun.go()