Merge pull request 'Scal SuperSaperTestowy' (#1) from SuperSaperTestowy into master

Reviewed-on: #1
This commit is contained in:
Mateusz Romański 2021-04-09 21:24:02 +02:00
commit 5f1780bc2f
8 changed files with 45 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,9 +1,11 @@
from const import SAPPER_IDLE from const import SAPPER_IDLE
import pygame as pg
class Agent: class Agent:
def __init__(self, x: int = 0, y: int = 0): def __init__(self, x: int = 0, y: int = 0):
self.name = "Kapitan Bomba" self.name = "Kapitan Bomba"
self.img = SAPPER_IDLE self.img = pg.image.load(SAPPER_IDLE[1])
self.dir = 1
self.x = x self.x = x
self.y = y self.y = y

View File

@ -37,7 +37,13 @@ for name, val in {
) )
ICON = main_path + '/images/mine_icon.png' ICON = main_path + '/images/mine_icon.png'
SAPPER_IDLE = pg.image.load(main_path + '/images/sapper_idle/agent.png') SAPPER_IDLE = [main_path + '/images/sapper_idle/agent0.png',
main_path + '/images/sapper_idle/agent1.png',
main_path + '/images/sapper_idle/agent2.png',
main_path + '/images/sapper_idle/agent3.png']
#pg.image.load(main_path + '/images/sapper_idle/agent1.png')
#empty space #empty space

View File

@ -1,4 +1,6 @@
import pygame as pg import pygame as pg
import os
main_path = os.path.dirname(os.getcwd())
from agent import Agent from agent import Agent
from environment import Environment from environment import Environment
@ -12,7 +14,17 @@ class GameUi:
self.clock = pg.time.Clock() self.clock = pg.time.Clock()
self.screen = pg.display.set_mode((WIDTH, HEIGHT)) self.screen = pg.display.set_mode((WIDTH, HEIGHT))
def move(self, coord: str, shift: int): def move(self):
coord = 'x' if self.agent.dir in (1, 3) else 'y'
shift = -1 if self.agent.dir in (2, 3) else 1
# print(coord, shift)
test = int(getattr(self.agent, coord) + shift)
if coord == 'x':
if self.env.field[self.agent.y][test].number in (2, 3):
return
elif coord == 'y':
if self.env.field[test][self.agent.x].number in (2, 3):
return
for x in range(8): for x in range(8):
setattr( setattr(
self.agent, self.agent,
@ -22,7 +34,6 @@ class GameUi:
) )
self.update() self.update()
self.clock.tick(15) self.clock.tick(15)
self.agent.img = SAPPER_IDLE
self.update() self.update()
def update(self): def update(self):
@ -31,3 +42,11 @@ class GameUi:
self.screen.blit(IMAGES[self.env.field[y][x].number].img, (x * 80, y * 80)) self.screen.blit(IMAGES[self.env.field[y][x].number].img, (x * 80, y * 80))
self.screen.blit(self.agent.img, (self.agent.x * 80, self.agent.y * 80)) self.screen.blit(self.agent.img, (self.agent.x * 80, self.agent.y * 80))
pg.display.update() pg.display.update()
def rotate(self, dir):
self.agent.dir = (self.agent.dir + dir) % 4
#print(self.agent.dir)
self.agent.img = pg.image.load(SAPPER_IDLE[self.agent.dir])
self.update()

View File

@ -21,19 +21,25 @@ def main():
running = True running = True
#ruchy agenta:
#1 - right
#2 - up
#3 - left
#0 - down
while running: while running:
for event in pg.event.get(): for event in pg.event.get():
# print(agent.x*80)
if event.type == pg.QUIT: if event.type == pg.QUIT:
running = False running = False
elif event.type == pg.KEYDOWN: elif event.type == pg.KEYDOWN:
if (event.key == pg.K_d or event.key == pg.K_RIGHT) and agent.x*80 < 700: if (event.key == pg.K_d or event.key == pg.K_RIGHT):
game_ui.move('x', 1) game_ui.rotate(-1)
elif (event.key == pg.K_a or event.key == pg.K_LEFT) and agent.x*80 > 5: elif (event.key == pg.K_a or event.key == pg.K_LEFT):
game_ui.move('x', -1) game_ui.rotate(1)
elif (event.key == pg.K_s or event.key == pg.K_DOWN) and agent.y*80 < 700: elif (event.key == pg.K_w or event.key == pg.K_UP and ((agent.dir == 1 and agent.x*80 < 700) or (agent.dir == 3 and agent.x*80 > 5) or
game_ui.move('y', 1) (agent.dir == 2 and agent.y*80 > 0) or (agent.dir == 0 and agent.y*80 < 700))):
elif (event.key == pg.K_w or event.key == pg.K_UP) and agent.y*80 > 0: game_ui.move()
game_ui.move('y', -1)
elif event.key == pg.K_SPACE: elif event.key == pg.K_SPACE:
if env.field[agent.y][agent.x].mine: if env.field[agent.y][agent.x].mine:
env.field[agent.y][agent.x] = factory.create_tile( env.field[agent.y][agent.x] = factory.create_tile(