Added working movement

This commit is contained in:
Michal Starski 2019-04-01 14:36:27 +02:00
commit 958c7ec271
24 changed files with 27 additions and 13 deletions

6
.gitignore vendored
View File

@ -1 +1,5 @@
VENV
VENV
env
**/__pycache__
.vscode
*.swp

View File

@ -1,5 +1,6 @@
from DataModels.Cell import Cell
from DataModels.Road import Road
from config import GRID_WIDTH, GRID_HEIGHT
class GC(Cell):
@ -9,10 +10,11 @@ class GC(Cell):
def move(self, direction, environment):
x, y = [self.x, self.y]
movement = {
"right": (x + 1, y) if environment[x + 1][y] == Road else (x, y),
"left": (x - 1, y) if environment[x - 1][y] == Road else (x, y),
"up": (x, y + 1) if environment[x][y + 1] == Road else (x, y),
"down": (x, y - 1) if environment[x][y - 1] == Road else (x, y)
"right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y),
"left": (x - 1, y) if x - 1 >= 0 and type(environment[x - 1][y]) == Road else (x, y),
"down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y),
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
}
self.x, self.y = movement[direction]
print(self.x, self.y)
self.update_rect(self.x, self.y)

View File

@ -1,4 +1,5 @@
9 9
2 1
E E E H E E E E E
E Y R R E H E E E
E R E R E R E G E
@ -8,4 +9,3 @@ R R R R R E R R E
E B R H E R R H E
E E R R R R E E E
E E E E H R R R H
3 1

View File

@ -1,6 +1,7 @@
6 5
1 0
Y R R R E H
E R E R R R
H R B R H R
E R R R R G
E H E E R H
E H E E R H

View File

@ -1,5 +1,6 @@
13 4
3 0
E Y R R R H H R R R E E E
H R R H R R R R H R R H E
E E R E H E R H R E R R G
H R R E E B R R R H E R H
H R R E E B R R R H E R H

View File

@ -1,4 +1,5 @@
12 10
1 0
Y R R R E H R R R R R E
E R E R R E R E H E R H
H R R H R R R R R R R E

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,9 @@ CELL_SIZE = 64
FPS = 60
map = open( sys.argv[1], 'r' )
GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()]
GC_X, GC_Y = [int(x) for x in map.readline().split()]
WINDOW_HEIGHT = GRID_HEIGHT * CELL_SIZE
WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE

13
main.py
View File

@ -2,7 +2,7 @@ import pygame
import sys
from random import randint
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS
from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y
from DataModels.Grass import Grass
from DataModels.House import House
@ -17,6 +17,7 @@ GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
map = open(sys.argv[1], 'r')
map.readline()
map.readline()
map_objects = [[None for y in range(0, GRID_WIDTH)]
for x in range(0, GRID_HEIGHT)]
@ -37,8 +38,9 @@ def generate(letter):
i = 0
for y in map.readlines():
for x in y.split():
x_coord = i % GRID_WIDTH
y_coord = i // GRID_WIDTH
y_coord = i % GRID_WIDTH
x_coord = (i - y_coord)//GRID_WIDTH
yellow, green, blue = [randint(0, HOUSE_CAPACITY // 2), randint(
0, HOUSE_CAPACITY // 2), randint(0, HOUSE_CAPACITY // 2)]
@ -69,8 +71,9 @@ for line in map_objects:
for item in line:
pygame_sprites.add(item)
gc = GC(0, 0, 10)
pygame_sprites.add()
gc = GC(GC_X, GC_Y, 2)
print("GC: " + str(GC_X) + str(GC_Y))
pygame_sprites.add(gc)
while True: