Code:
import pygame, sys
from pygame.locals import *
pygame.init()
playerPos = {"characterX":750, "characterY":325, "characterWidth":50, "characterHeight":70}
def playerMovement(pressed):
if (pressed[K_RIGHT]):
playerPos.characterX = playerPos.characterX + 3
if (pressed[K_LEFT]):
playerPos.characterX = playerPos.characterX - 3
if (pressed[K_DOWN]):
playerPos.characterY = playerPos.characterY + 3
if (pressed[K_UP]):
playerPos.characterY = playerPos.characterY - 3
#Colours
BACKGROUND = (255, 255, 255)
CHARACTER = (255, 30, 70)
# Game Setup
FPS = 60
fpsClock = pygame.time.Clock()
WINDOW_WIDTH = 1500
WINDOW_HEIGHT = 750
WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("My Game!")
# The Main function that controls the game\
def main():
looping = True
# The main game loop
while looping:
# Get inputs
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
playerMovement(pressed = pygame.key.get_pressed())
# Processing
# This section will be built out later
character = pygame.Rect(playerPos)
# Render elements of the game
WINDOW.fill(BACKGROUND)
pygame.draw.rect(WINDOW, CHARACTER, character)
pygame.display.update()
fpsClock.tick(FPS)
main()