pscreenTest_Movement.py
pscreenTest_Movement.py
—
Python Source,
1Kb
File contents
#Small example demonstrating movement
import pscreen
screenWidth = 400
screenHeight = 400
#Load our screen
pscreen.LoadScreen((screenWidth, screenHeight), False, "pygame")
#Set the initial position in the middle of the screen
positionX = screenWidth / 2
positionY = screenHeight / 2
#Initialize a font
pscreen.FontSelect()
#Game loop
while True:
#Exit out of this loop if escape is pressed
if pscreen.KeyIsPressed("escape"):
break
#Clear the screen to black
pscreen.ClearScreen((0, 0, 0))
#Directional keys allow movement
#Clip the movement at the borders of the window
if pscreen.KeyIsPressed("right"):
if positionX < screenWidth - 10:
positionX += 1
if pscreen.KeyIsPressed("left"):
if positionX > 10:
positionX -= 1
if pscreen.KeyIsPressed("down"):
if positionY < screenHeight - 10:
positionY += 1
if pscreen.KeyIsPressed("up"):
if positionY > 10:
positionY -= 1
pscreen.FontWrite(10, 375, "Press the directional keys to move.")
#Draw a circle
pscreen.Circle(positionX, positionY, 10, (255, 200, 125, 255), 5)
pscreen.UpdateScreen()
pscreen.UnloadScreen()


