grid added
This commit is contained in:
parent
98784d7e4f
commit
50c7d8766f
41
field.py
41
field.py
@ -1,38 +1,51 @@
|
|||||||
import pygame
|
import pygame
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
WHITE = (200, 200, 200)
|
||||||
BLUE = (46, 34, 240)
|
BLUE = (46, 34, 240)
|
||||||
WHITE = (255, 255, 255)
|
WINDOW_HEIGHT = 600
|
||||||
W = 600
|
WINDOW_WIDTH = 600
|
||||||
H = 400
|
BLOCK_SIZE = 40
|
||||||
sc = pygame.display.set_mode((W, H))
|
|
||||||
|
|
||||||
|
|
||||||
|
def drawGrid():
|
||||||
|
#Set the size of the grid block
|
||||||
|
for x in range(0, WINDOW_WIDTH, BLOCK_SIZE):
|
||||||
|
for y in range(0, WINDOW_HEIGHT, BLOCK_SIZE):
|
||||||
|
rect = pygame.Rect(x, y, BLOCK_SIZE, BLOCK_SIZE)
|
||||||
|
pygame.draw.rect(sc, WHITE, rect, 1)
|
||||||
|
def draw_interface():
|
||||||
|
global sc
|
||||||
|
sc = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
|
||||||
pygame.display.set_caption("Pole i ciągnik")
|
pygame.display.set_caption("Pole i ciągnik")
|
||||||
pygame.display.set_icon(pygame.image.load("icon.png"))
|
pygame.display.set_icon(pygame.image.load("icon.png"))
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
sc.fill(BLACK)
|
||||||
FPS = 60
|
FPS = 60
|
||||||
|
|
||||||
x = W // 2
|
x = BLOCK_SIZE / 4
|
||||||
y = H // 2
|
y = BLOCK_SIZE / 4
|
||||||
speed = 20
|
|
||||||
|
|
||||||
flRunning = True
|
flRunning = True
|
||||||
while flRunning:
|
while flRunning:
|
||||||
|
sc.fill(BLACK)
|
||||||
|
drawGrid()
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
flRunning = False
|
flRunning = False
|
||||||
elif event.type == pygame.KEYDOWN:
|
elif event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
x -= speed
|
x -= BLOCK_SIZE
|
||||||
elif event.key == pygame.K_RIGHT:
|
elif event.key == pygame.K_RIGHT:
|
||||||
x += speed
|
x += BLOCK_SIZE
|
||||||
elif event.key == pygame.K_DOWN:
|
elif event.key == pygame.K_DOWN:
|
||||||
y += speed
|
y += BLOCK_SIZE
|
||||||
elif event.key == pygame.K_UP:
|
elif event.key == pygame.K_UP:
|
||||||
y -= speed
|
y -= BLOCK_SIZE
|
||||||
sc.fill(WHITE)
|
pygame.draw.rect(sc, BLUE, (x, y, BLOCK_SIZE / 2, BLOCK_SIZE / 2))
|
||||||
pygame.draw.rect(sc, BLUE, (x, y, 20, 20))
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
Loading…
Reference in New Issue
Block a user