tractor rotation
This commit is contained in:
parent
9eb5029b38
commit
5094ee732c
34
astar.py
34
astar.py
@ -99,21 +99,19 @@ def manhattan(pos0, pos1):
|
||||
|
||||
|
||||
def main():
|
||||
rotation = ["left", "up", "right", "down"]
|
||||
run = True
|
||||
clock = pygame.time.Clock()
|
||||
board = Board()
|
||||
board.load_images()
|
||||
|
||||
start_row, start_col = 1, 1
|
||||
end_row, end_col = 5, 0
|
||||
start_row, start_col = 0,0
|
||||
end_row, end_col = 9,9
|
||||
tractor = Tractor(start_row, start_col)
|
||||
board.set_grass(start_row, start_col)
|
||||
board.set_grass(end_row, end_col)
|
||||
|
||||
grid = [[Node(x, y) for y in range(rows)] for x in range(cols)]
|
||||
|
||||
|
||||
start = grid[start_row][start_col]
|
||||
end = grid[end_row][end_col]
|
||||
|
||||
@ -121,8 +119,6 @@ def main():
|
||||
|
||||
|
||||
while run:
|
||||
|
||||
|
||||
clock.tick(fps)
|
||||
|
||||
for event in pygame.event.get():
|
||||
@ -134,13 +130,29 @@ def main():
|
||||
continue
|
||||
|
||||
next_node = path.pop(0) if path else start_node
|
||||
dx = next_node.x - tractor.col
|
||||
dy = next_node.y - tractor.row
|
||||
tractor.row, tractor.col = next_node.y, next_node.x
|
||||
|
||||
|
||||
#rotation
|
||||
|
||||
|
||||
|
||||
|
||||
if dx > 0:
|
||||
tractor.direction = "right"
|
||||
elif dx < 0:
|
||||
tractor.direction = "left"
|
||||
elif dy > 0:
|
||||
tractor.direction = "down"
|
||||
elif dy < 0:
|
||||
tractor.direction = "up"
|
||||
|
||||
if board.is_weed(tractor.col, tractor.row ):
|
||||
board.set_grass(tractor.col, tractor.row )
|
||||
|
||||
elif board.is_dirt(tractor.col, tractor.row ):
|
||||
board.set_soil(tractor.col, tractor.row )
|
||||
|
||||
elif board.is_soil(tractor.col, tractor.row ):
|
||||
board.set_carrot(tractor.col, tractor.row )
|
||||
|
||||
|
||||
board.draw_cubes(WIN)
|
||||
tractor.draw(WIN)
|
||||
|
7
board.py
7
board.py
@ -1,7 +1,7 @@
|
||||
import pygame
|
||||
from constant import size, rows, cols
|
||||
import random
|
||||
|
||||
from tractor import Tractor
|
||||
|
||||
class Board:
|
||||
def __init__(self):
|
||||
@ -55,7 +55,7 @@ class Board:
|
||||
def load_costs(self):
|
||||
self.costs = {
|
||||
0: 100, #kamien
|
||||
1: 2, #chwasty
|
||||
1:2, #chwast
|
||||
2: 1, #po trawie
|
||||
3: 1, #po trawie
|
||||
4: 1, #po trawie
|
||||
@ -73,7 +73,8 @@ class Board:
|
||||
return self.costs.get(tile_type, 1)
|
||||
|
||||
def is_rock(self, row, col):
|
||||
return self.board[row][col] == 0
|
||||
tractor = Tractor(row, col)
|
||||
return self.board[row][col] == 0 and not (row == tractor.row and col == tractor.col)
|
||||
|
||||
def is_weed(self,row,col):
|
||||
return self.board[row][col] == 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pygame
|
||||
width, height = 640, 640
|
||||
rows, cols = 8, 8
|
||||
rows, cols = 10, 10
|
||||
size = width//cols
|
||||
yellow = (216,178,0)
|
||||
green= (103,178,0)
|
||||
|
Loading…
Reference in New Issue
Block a user