Add walls
This commit is contained in:
parent
5d2603b65e
commit
8632841061
BIN
images/wall.bmp
Normal file
BIN
images/wall.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
2
main.py
2
main.py
@ -39,6 +39,8 @@ class Game:
|
||||
Bomb(self, col, row)
|
||||
if tile == '4':
|
||||
Grenade(self, col, row)
|
||||
if tile == "#":
|
||||
Wall(self, col, row)
|
||||
if tile == 'A':
|
||||
self.player = Player(self, col, row)
|
||||
|
||||
|
6
map.txt
6
map.txt
@ -1,7 +1,7 @@
|
||||
.A.....
|
||||
###....
|
||||
.......
|
||||
.......
|
||||
.......
|
||||
.......
|
||||
....2..
|
||||
...###.
|
||||
...#2#.
|
||||
.......
|
||||
|
2
maze.py
2
maze.py
@ -69,6 +69,8 @@ class Maze:
|
||||
|
||||
if not(0 <= i < len(maze[0]) and 0 <= j < len(maze)):
|
||||
return False
|
||||
elif (maze[j][i] == "#"):
|
||||
return False
|
||||
|
||||
|
||||
return True
|
||||
|
170
sprites.py
170
sprites.py
@ -28,42 +28,46 @@ class Player(pg.sprite.Sprite):
|
||||
if self.direction == Direction.Right.name:
|
||||
if dx > 0:
|
||||
if self.check_border(dx):
|
||||
if self.collide_with_mines(dx):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.x += dx
|
||||
else:
|
||||
self.x += dx
|
||||
if not self.collide_with_walls(dx):
|
||||
if self.collide_with_mines(dx):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.x += dx
|
||||
else:
|
||||
self.x += dx
|
||||
|
||||
if self.direction == Direction.Up.name:
|
||||
if dy < 0:
|
||||
if self.check_border(0, dy):
|
||||
if self.collide_with_mines(0, dy):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.y += dy
|
||||
else:
|
||||
self.y += dy
|
||||
if not self.collide_with_walls(0, dy):
|
||||
if self.collide_with_mines(0, dy):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.y += dy
|
||||
else:
|
||||
self.y += dy
|
||||
|
||||
if self.direction == Direction.Down.name:
|
||||
if dy > 0:
|
||||
if self.check_border(0, dy):
|
||||
if self.collide_with_mines(0, dy):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.y += dy
|
||||
else:
|
||||
self.y += dy
|
||||
if not self.collide_with_walls(0, dy):
|
||||
if self.collide_with_mines(0, dy):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.y += dy
|
||||
else:
|
||||
self.y += dy
|
||||
|
||||
if self.direction == Direction.Left.name:
|
||||
if dx < 0:
|
||||
if self.check_border(dx):
|
||||
if self.collide_with_mines(dx):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.x += dx
|
||||
else:
|
||||
self.x += dx
|
||||
if not self.collide_with_walls(dx):
|
||||
if self.collide_with_mines(dx):
|
||||
#ctypes.windll.user32.MessageBoxW(0, "Mine Ahead!", "Warning", 1)
|
||||
print("Mine Ahead!")
|
||||
self.x += dx
|
||||
else:
|
||||
self.x += dx
|
||||
|
||||
elif direction != self.direction:
|
||||
self.direction = direction
|
||||
@ -90,6 +94,12 @@ class Player(pg.sprite.Sprite):
|
||||
return True
|
||||
return False
|
||||
|
||||
def collide_with_walls(self, dx=0, dy=0):
|
||||
for wall in self.game.walls:
|
||||
if wall.x == self.x + dx and wall.y == self.y + dy:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
right = 1
|
||||
@ -105,49 +115,60 @@ class Player(pg.sprite.Sprite):
|
||||
|
||||
def parse_maze_moves(self):
|
||||
self.moves = [char for char in self.maze.moves]
|
||||
|
||||
|
||||
if self.moves[0] != 'R':
|
||||
if self.moves[0] == 'D':
|
||||
self.moves.insert(0, 'Turn Down')
|
||||
if self.moves[0] == 'U':
|
||||
self.moves.insert(0, 'Turn Up')
|
||||
if self.moves[0] == 'L':
|
||||
self.moves.insert(0, 'Turn Left')
|
||||
|
||||
for n, i in enumerate(self.moves):
|
||||
if i == 'R':
|
||||
self.moves[n] = 'Right'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
else:
|
||||
self.move(dx=-1, direction='Right')
|
||||
if i == 'L':
|
||||
self.moves[n] = 'Left'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if i == 'D':
|
||||
self.moves[n] = 'Down'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
if i == 'U':
|
||||
self.moves[n] = 'Up'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
if i == 'R':
|
||||
self.moves[n] = 'Right'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
else:
|
||||
self.move(dx=-1, direction='Right')
|
||||
if i == 'L':
|
||||
self.moves[n] = 'Left'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if i == 'D':
|
||||
self.moves[n] = 'Down'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if self.moves[n+1] == 'U':
|
||||
self.moves.insert(n+1, 'Turn Up')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
if i == 'U':
|
||||
self.moves[n] = 'Up'
|
||||
if n != len(self.moves)-1:
|
||||
if i != self.moves[n+1]:
|
||||
if self.moves[n+1] == 'D':
|
||||
self.moves.insert(n+1, 'Turn Down')
|
||||
if self.moves[n+1] == 'R':
|
||||
self.moves.insert(n+1, 'Turn Right')
|
||||
if self.moves[n+1] == 'L':
|
||||
self.moves.insert(n+1, 'Turn Left')
|
||||
|
||||
print(self.moves)
|
||||
|
||||
|
||||
@ -220,4 +241,21 @@ class Grenade(pg.sprite.Sprite):
|
||||
self.rect.x = self.x * TILESIZE
|
||||
self.rect.y = self.y * TILESIZE
|
||||
|
||||
class Wall(pg.sprite.Sprite):
|
||||
def __init__(self, game, x, y):
|
||||
self.groups = game.all_sprites, game.walls
|
||||
pg.sprite.Sprite.__init__(self, self.groups)
|
||||
self.game = game
|
||||
#self.image = pg.Surface((TILESIZE, TILESIZE))
|
||||
self.image = pg.image.load('images/wall.bmp')
|
||||
#self.image.fill(YELLOW)
|
||||
self.image = pg.transform.scale(self.image, (TILESIZE, TILESIZE))
|
||||
self.rect = self.image.get_rect()
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def update(self):
|
||||
self.rect.x = self.x * TILESIZE
|
||||
self.rect.y = self.y * TILESIZE
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user