Added working movement
This commit is contained in:
commit
958c7ec271
6
.gitignore
vendored
6
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
VENV
|
VENV
|
||||||
|
env
|
||||||
|
**/__pycache__
|
||||||
|
.vscode
|
||||||
|
*.swp
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from DataModels.Cell import Cell
|
from DataModels.Cell import Cell
|
||||||
from DataModels.Road import Road
|
from DataModels.Road import Road
|
||||||
|
from config import GRID_WIDTH, GRID_HEIGHT
|
||||||
|
|
||||||
|
|
||||||
class GC(Cell):
|
class GC(Cell):
|
||||||
@ -9,10 +10,11 @@ class GC(Cell):
|
|||||||
def move(self, direction, environment):
|
def move(self, direction, environment):
|
||||||
x, y = [self.x, self.y]
|
x, y = [self.x, self.y]
|
||||||
movement = {
|
movement = {
|
||||||
"right": (x + 1, y) if environment[x + 1][y] == 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 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),
|
||||||
"up": (x, y + 1) if environment[x][y + 1] == Road else (x, y),
|
"down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y),
|
||||||
"down": (x, y - 1) if 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]
|
self.x, self.y = movement[direction]
|
||||||
print(self.x, self.y)
|
print(self.x, self.y)
|
||||||
|
self.update_rect(self.x, self.y)
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,5 @@
|
|||||||
9 9
|
9 9
|
||||||
|
2 1
|
||||||
E E E H E E E E E
|
E E E H E E E E E
|
||||||
E Y R R E H E E E
|
E Y R R E H E E E
|
||||||
E R E R E R E G 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 B R H E R R H E
|
||||||
E E R R R R E E E
|
E E R R R R E E E
|
||||||
E E E E H R R R H
|
E E E E H R R R H
|
||||||
3 1
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
6 5
|
6 5
|
||||||
|
1 0
|
||||||
Y R R R E H
|
Y R R R E H
|
||||||
E R E R R R
|
E R E R R R
|
||||||
H R B R H R
|
H R B R H R
|
||||||
E R R R R G
|
E R R R R G
|
||||||
E H E E R H
|
E H E E R H
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
13 4
|
13 4
|
||||||
|
3 0
|
||||||
E Y R R R H H R R R E E E
|
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
|
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
|
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
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
12 10
|
12 10
|
||||||
|
1 0
|
||||||
Y R R R E H R R R R R E
|
Y R R R E H R R R R R E
|
||||||
E R E R R E R E H E R H
|
E R E R R E R E H E R H
|
||||||
H R R H R R R R R R R E
|
H R R H R R R R R R R E
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -4,7 +4,9 @@ CELL_SIZE = 64
|
|||||||
FPS = 60
|
FPS = 60
|
||||||
|
|
||||||
map = open( sys.argv[1], 'r' )
|
map = open( sys.argv[1], 'r' )
|
||||||
|
|
||||||
GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()]
|
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_HEIGHT = GRID_HEIGHT * CELL_SIZE
|
||||||
WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE
|
WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE
|
||||||
|
13
main.py
13
main.py
@ -2,7 +2,7 @@ import pygame
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from random import randint
|
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.Grass import Grass
|
||||||
from DataModels.House import House
|
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 = open(sys.argv[1], 'r')
|
||||||
map.readline()
|
map.readline()
|
||||||
|
map.readline()
|
||||||
|
|
||||||
map_objects = [[None for y in range(0, GRID_WIDTH)]
|
map_objects = [[None for y in range(0, GRID_WIDTH)]
|
||||||
for x in range(0, GRID_HEIGHT)]
|
for x in range(0, GRID_HEIGHT)]
|
||||||
@ -37,8 +38,9 @@ def generate(letter):
|
|||||||
i = 0
|
i = 0
|
||||||
for y in map.readlines():
|
for y in map.readlines():
|
||||||
for x in y.split():
|
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(
|
yellow, green, blue = [randint(0, HOUSE_CAPACITY // 2), randint(
|
||||||
0, HOUSE_CAPACITY // 2), randint(0, HOUSE_CAPACITY // 2)]
|
0, HOUSE_CAPACITY // 2), randint(0, HOUSE_CAPACITY // 2)]
|
||||||
@ -69,8 +71,9 @@ for line in map_objects:
|
|||||||
for item in line:
|
for item in line:
|
||||||
pygame_sprites.add(item)
|
pygame_sprites.add(item)
|
||||||
|
|
||||||
gc = GC(0, 0, 10)
|
gc = GC(GC_X, GC_Y, 2)
|
||||||
pygame_sprites.add()
|
print("GC: " + str(GC_X) + str(GC_Y))
|
||||||
|
pygame_sprites.add(gc)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user