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