Merge pull request 'Refactor' (#4) from Refactor into main
Reviewed-on: s473601/Machine_learning_2023#4
This commit is contained in:
commit
9ac833550c
17
Interface/movement.py
Normal file
17
Interface/movement.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import pygame
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def moving_cleaner(grid_width, grid_height,tile_width,tile_height, x, y):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_LEFT and x>(tile_width / 2):
|
||||||
|
x -= tile_width
|
||||||
|
if event.key == pygame.K_RIGHT and x<(grid_width-(tile_width / 2)):
|
||||||
|
x += tile_width
|
||||||
|
if event.key == pygame.K_UP and y>(tile_height / 2):
|
||||||
|
y -= tile_height
|
||||||
|
if event.key == pygame.K_DOWN and y<(grid_height-(tile_height / 2)):
|
||||||
|
y += tile_height
|
||||||
|
return(x,y)
|
@ -1,30 +1,20 @@
|
|||||||
from Interface.grid_draw import GridDraw, Colors
|
from Interface.grid_draw import GridDraw, Colors
|
||||||
import sys
|
import sys
|
||||||
import pygame
|
import pygame
|
||||||
|
from Interface.movement import moving_cleaner
|
||||||
|
|
||||||
# dummy function
|
# dummy function
|
||||||
def initial_draw():
|
def initial_draw(grid_width, grid_height):
|
||||||
grid = GridDraw(500, 500)
|
grid = GridDraw(grid_width, grid_height)
|
||||||
tile_width = 500 / 10
|
tile_width = grid_width / 10
|
||||||
tile_height = 500 / 10
|
tile_height = grid_height / 10
|
||||||
x = tile_width / 2
|
x = tile_width / 2
|
||||||
y = tile_height / 2
|
y = tile_height / 2
|
||||||
radius = 15
|
radius = 15
|
||||||
while True:
|
while True:
|
||||||
grid.start_draw()
|
grid.start_draw()
|
||||||
grid.board(10, 10)
|
grid.board(10, 10)
|
||||||
for event in pygame.event.get():
|
(x,y) = moving_cleaner(grid_width,grid_height,tile_width,tile_height, x, y)
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
sys.exit()
|
|
||||||
if event.type == pygame.KEYDOWN:
|
|
||||||
if event.key == pygame.K_LEFT:
|
|
||||||
x -= tile_width
|
|
||||||
if event.key == pygame.K_RIGHT:
|
|
||||||
x += tile_width
|
|
||||||
if event.key == pygame.K_UP:
|
|
||||||
y -= tile_height
|
|
||||||
if event.key == pygame.K_DOWN:
|
|
||||||
y += tile_height
|
|
||||||
grid.circle(x, y, 20, color=Colors.RED)
|
grid.circle(x, y, 20, color=Colors.RED)
|
||||||
grid.end_draw()
|
grid.end_draw()
|
||||||
pygame.time.delay(10)
|
pygame.time.delay(10)
|
||||||
|
Loading…
Reference in New Issue
Block a user