push
This commit is contained in:
commit
569d790144
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (traktor)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal 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/traktor.iml" filepath="$PROJECT_DIR$/.idea/traktor.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
.idea/traktor.iml
Normal file
10
.idea/traktor.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
__pycache__/board.cpython-39.pyc
Normal file
BIN
__pycache__/board.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/constant.cpython-39.pyc
Normal file
BIN
__pycache__/constant.cpython-39.pyc
Normal file
Binary file not shown.
BIN
__pycache__/tractor.cpython-39.pyc
Normal file
BIN
__pycache__/tractor.cpython-39.pyc
Normal file
Binary file not shown.
25
board.py
Normal file
25
board.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pygame
|
||||
from constant import size, rows, cols
|
||||
|
||||
|
||||
|
||||
class Board:
|
||||
def __init__(self):
|
||||
self.board = []
|
||||
|
||||
|
||||
def load_images(self):
|
||||
self.grass = pygame.image.load("grass.png")
|
||||
self.dirt = pygame.image.load("dirt.png")
|
||||
|
||||
def draw_cubes(self, win):
|
||||
|
||||
for row in range(rows):
|
||||
for col in range(cols):
|
||||
cube_rect = pygame.Rect(row * size, col * size, size, size)
|
||||
|
||||
if (row + col) % 2 == 0:
|
||||
win.blit(self.grass, cube_rect)
|
||||
else:
|
||||
win.blit(self.dirt, cube_rect)
|
||||
|
7
constant.py
Normal file
7
constant.py
Normal file
@ -0,0 +1,7 @@
|
||||
import pygame
|
||||
width, height = 640, 640
|
||||
rows, cols = 8, 8
|
||||
size = width//cols
|
||||
yellow = (216,178,0)
|
||||
green= (103,178,0)
|
||||
red = (255,0,0)
|
46
main.py
Normal file
46
main.py
Normal file
@ -0,0 +1,46 @@
|
||||
import pygame
|
||||
from board import Board
|
||||
from constant import width, height, rows, cols
|
||||
from tractor import Tractor
|
||||
|
||||
|
||||
|
||||
|
||||
fps = 5
|
||||
WIN = pygame.display.set_mode((width, height))
|
||||
|
||||
pygame.display.set_caption('Inteligenty Traktor')
|
||||
|
||||
def main():
|
||||
run = True
|
||||
clock = pygame.time.Clock()
|
||||
board = Board()
|
||||
board.load_images()
|
||||
tractor = Tractor(4, 4)
|
||||
while run:
|
||||
clock.tick(fps)
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_UP] and tractor.row > 0:
|
||||
tractor.row -= 1
|
||||
tractor.direction = "up"
|
||||
if keys[pygame.K_DOWN] and tractor.row < rows-1:
|
||||
tractor.row += 1
|
||||
tractor.direction = "down"
|
||||
if keys[pygame.K_LEFT] and tractor.col > 0:
|
||||
tractor.col -= 1
|
||||
tractor.direction = "left"
|
||||
if keys[pygame.K_RIGHT] and tractor.col < cols -1:
|
||||
tractor.col += 1
|
||||
tractor.direction = "right"
|
||||
|
||||
board.draw_cubes(WIN)
|
||||
tractor.draw(WIN)
|
||||
pygame.display.update()
|
||||
pygame.quit()
|
||||
|
||||
main()
|
16
tractor.py
Normal file
16
tractor.py
Normal file
@ -0,0 +1,16 @@
|
||||
import pygame
|
||||
from constant import size
|
||||
class Tractor:
|
||||
def __init__(self, row, col):
|
||||
self.row = row
|
||||
self.col = col
|
||||
self.images = {
|
||||
"up": pygame.image.load("up.png"),
|
||||
"down": pygame.image.load("down.png"),
|
||||
"left":pygame.image.load("left.png"),
|
||||
"right":pygame.image.load("right.png")
|
||||
}
|
||||
self.direction = "down"
|
||||
def draw(self, win):
|
||||
tractor_image = self.images[self.direction]
|
||||
win.blit(tractor_image, (self.col*size, self.row*size))
|
Loading…
Reference in New Issue
Block a user