utworzenie kraty i dodanie podstawowych grafik

This commit is contained in:
LuminoX 2024-03-05 14:36:03 +01:00
commit 8f20ef1d7b
8 changed files with 92 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sztuczna.iml" filepath="$PROJECT_DIR$/.idea/sztuczna.iml" />
</modules>
</component>
</project>

8
.idea/sztuczna.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
avatar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

60
main.py Normal file
View File

@ -0,0 +1,60 @@
import pygame
import sys
BLACK = (0, 0, 0)
GRID_SIZE = 100
GRID_WIDTH = 20
GRID_HEIGHT = 10
pygame.init()
WINDOW_SIZE = (GRID_WIDTH * GRID_SIZE, GRID_HEIGHT * GRID_SIZE)
screen = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("Mini Zoo")
agent_pos = [0,0]
agent_image = pygame.image.load('avatar.png')
agent_image = pygame.transform.scale(agent_image, (GRID_SIZE,GRID_SIZE))
background_image = pygame.image.load('tło.jpg')
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
def draw_grid():
for y in range(0, GRID_HEIGHT * GRID_SIZE, GRID_SIZE):
for x in range(0, GRID_WIDTH * GRID_SIZE, GRID_SIZE):
rect = pygame.Rect(x, y, GRID_SIZE, GRID_SIZE)
pygame.draw.rect(screen, BLACK, rect, 1)
def draw_agent(agent_pos):
x, y = agent_pos
screen.blit(agent_image, (x*GRID_SIZE,y*GRID_SIZE))
def main():
global agent_pos
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type ==pygame.KEYDOWN:
if event.key == pygame.K_UP and agent_pos[1] > 0:
agent_pos[1] -= 1
elif event.key == pygame.K_DOWN and agent_pos[1] < GRID_HEIGHT - 1:
agent_pos[1] += 1
elif event.key == pygame.K_LEFT and agent_pos[0] > 0:
agent_pos[0] -= 1
elif event.key == pygame.K_RIGHT and agent_pos[0] < GRID_WIDTH - 1:
agent_pos[0] += 1
screen.blit(background_image,(0,0))
draw_grid()
draw_agent(agent_pos)
pygame.display.flip()
clock.tick(10)
if __name__ == "__main__":
main()

BIN
tło.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB