From 1f98475dd35e3ec81143a3a6d1964046511c6a90 Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Fri, 27 Mar 2020 22:43:12 -0400 Subject: [PATCH] Basic background in one file --- main.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..a783c2f --- /dev/null +++ b/main.py @@ -0,0 +1,54 @@ +# -*- coding: UTF-8 -*- + +### Tangled Mind +### Author: Arthur 'Grizzly' Grisel-Davy + +import pygame +pygame.init() + + +screen_width = 800 +screen_height = 800 +screen = pygame.display.set_mode((screen_width, screen_height)) +done = False + + +BACKGROUND=(0,0,0) +WHITE=(255,255,255) +BLUE=(0,0,255) + +posx = 400 +posy = 400 +width=50 +height=50 + +pygame.draw.rect(screen,BLUE,(posx,posy,width,height)) + +speed = 1 + +while not done: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + done = True + + keystate = pygame.key.get_pressed() + if keystate[pygame.K_LEFT]: + posx -= speed + if posx <0: + posx=0 + if keystate[pygame.K_RIGHT]: + posx += speed + if posx+width > screen_width: + posx = screen_height-width + if keystate[pygame.K_UP]: + posy -= speed + if posy < 0: + posy = 0 + if keystate[pygame.K_DOWN]: + posy += speed + if posy+height > screen_height: + posy = screen_height-height + + screen.fill(BACKGROUND) + pygame.draw.rect(screen,BLUE,(posx,posy,width,height)) + pygame.display.flip() \ No newline at end of file