Basic background in one file
This commit is contained in:
parent
1f066cb930
commit
1f98475dd3
1 changed files with 54 additions and 0 deletions
54
main.py
Normal file
54
main.py
Normal file
|
@ -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()
|
Loading…
Reference in a new issue