added bckg lines and moved screen func to another file
This commit is contained in:
parent
b61c1ddb6e
commit
78a85cec87
BIN
__pycache__/screen.cpython-310.pyc
Normal file
BIN
__pycache__/screen.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
assets/barn.png
Normal file
BIN
assets/barn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 818 B After Width: | Height: | Size: 818 B |
Binary file not shown.
Before Width: | Height: | Size: 826 B |
Binary file not shown.
Before Width: | Height: | Size: 792 B |
Binary file not shown.
Before Width: | Height: | Size: 803 B |
34
main.py
34
main.py
@ -1,21 +1,13 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import tractor
|
import tractor
|
||||||
|
import screen
|
||||||
|
|
||||||
#pygame initialization
|
# pygame initialization
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
#set screen
|
# creating agent
|
||||||
SCREEN = pygame.display.set_mode((1000, 1000))
|
|
||||||
pygame.display.set_caption("Traktor_interaktor")
|
|
||||||
|
|
||||||
myTractor = tractor.Tractor
|
myTractor = tractor.Tractor
|
||||||
|
|
||||||
#screen background
|
|
||||||
def set_screen():
|
|
||||||
SCREEN.fill((0,100,0))
|
|
||||||
TRACTOR = SCREEN.blit(myTractor.ROTATION_IMG, (myTractor.x, myTractor.y))
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
@ -23,19 +15,9 @@ if __name__ == "__main__":
|
|||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
keys = pygame.key.get_pressed()
|
# defines agent movement
|
||||||
if keys[pygame.K_LEFT] and myTractor.x>0:
|
tractor.movement(myTractor)
|
||||||
myTractor.ROTATION_IMG = myTractor.LEFT
|
# screen visualisation
|
||||||
myTractor.x -= myTractor.speed
|
screen.set_screen(myTractor)
|
||||||
if keys[pygame.K_RIGHT] and myTractor.x<1000-myTractor.width:
|
|
||||||
myTractor.ROTATION_IMG = myTractor.RIGHT
|
|
||||||
myTractor.x += myTractor.speed
|
|
||||||
if keys[pygame.K_UP] and myTractor.y>0:
|
|
||||||
myTractor.ROTATION_IMG = myTractor.UP
|
|
||||||
myTractor.y -= myTractor.speed
|
|
||||||
if keys[pygame.K_DOWN] and myTractor.y<1000-myTractor.height:
|
|
||||||
myTractor.ROTATION_IMG = myTractor.DOWN
|
|
||||||
myTractor.y += myTractor.speed
|
|
||||||
set_screen()
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
29
screen.py
Normal file
29
screen.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
# size in pixels of one tile = 36px/36px
|
||||||
|
tile = (36, 36)
|
||||||
|
|
||||||
|
# later move it to another class "barn"?
|
||||||
|
barn_img = pygame.image.load('assets/barn.png')
|
||||||
|
barn = pygame.transform.scale(barn_img, tile)
|
||||||
|
|
||||||
|
# screen settings
|
||||||
|
SIZE = (900, 900)
|
||||||
|
SCREEN = pygame.display.set_mode(SIZE)
|
||||||
|
pygame.display.set_caption("Traktor_interaktor")
|
||||||
|
|
||||||
|
# screen dispaly
|
||||||
|
def set_screen(myTractor):
|
||||||
|
# setting background color
|
||||||
|
SCREEN.fill((90,50,20))
|
||||||
|
|
||||||
|
# dispaly agent icon
|
||||||
|
TRACTOR = SCREEN.blit(myTractor.IMG, (myTractor.x, myTractor.y))
|
||||||
|
# display barn
|
||||||
|
SCREEN.blit(barn, (0, 863))
|
||||||
|
# draw lines(horizontal, vertical) on the screen
|
||||||
|
for line in range(25):
|
||||||
|
pygame.draw.line(SCREEN, (0, 0, 0), (0, line * 36), (SIZE[0], line * 36))
|
||||||
|
pygame.draw.line(SCREEN, (0, 0, 0), (line * 36, 0), (line * 36, SIZE[1]))
|
||||||
|
|
||||||
|
pygame.display.update()
|
44
tractor.py
44
tractor.py
@ -1,19 +1,33 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
#this is where tractor spawns when program starts (center)
|
# this is where tractor spawns when program starts (center)
|
||||||
x=500
|
x=432
|
||||||
y=500
|
y=432
|
||||||
#it's speed -> pixels it moves after pressing arrow
|
# it's speed -> pixels it moves after pressing arrow
|
||||||
speed = 10
|
speed = 36
|
||||||
#it's size
|
# tractor image
|
||||||
width = 20
|
tractor_img = pygame.image.load('assets/tractor/tractor.png')
|
||||||
height = 20
|
IMG = pygame.transform.scale(tractor_img, (36, 36))
|
||||||
|
# tractor image rotation
|
||||||
#tractor image rotation
|
UP = pygame.transform.rotate(IMG, 0)
|
||||||
ROTATION_IMG = pygame.image.load('assets/tractor/tractor_UP.png')
|
DOWN = pygame.transform.rotate(IMG, 180)
|
||||||
UP = pygame.image.load('assets/tractor/tractor_UP.png')
|
LEFT = pygame.transform.rotate(IMG, 90)
|
||||||
DOWN = pygame.image.load('assets/tractor/tractor_DOWN.png')
|
RIGHT = pygame.transform.rotate(IMG, -90)
|
||||||
LEFT = pygame.image.load('assets/tractor/tractor_LEFT.png')
|
|
||||||
RIGHT = pygame.image.load('assets/tractor/tractor_RIGHT.png')
|
|
||||||
|
def movement(myTractor):
|
||||||
|
keys = pygame.key.get_pressed()
|
||||||
|
|
||||||
|
if keys[pygame.K_LEFT] and myTractor.x>0:
|
||||||
|
myTractor.IMG = myTractor.LEFT
|
||||||
|
myTractor.x -= myTractor.speed
|
||||||
|
if keys[pygame.K_RIGHT] and myTractor.x<900-myTractor.speed:
|
||||||
|
myTractor.IMG = myTractor.RIGHT
|
||||||
|
myTractor.x += myTractor.speed
|
||||||
|
if keys[pygame.K_UP] and myTractor.y>0:
|
||||||
|
myTractor.IMG = myTractor.UP
|
||||||
|
myTractor.y -= myTractor.speed
|
||||||
|
if keys[pygame.K_DOWN] and myTractor.y<900-myTractor.speed:
|
||||||
|
myTractor.IMG = myTractor.DOWN
|
||||||
|
myTractor.y += myTractor.speed
|
||||||
|
Loading…
Reference in New Issue
Block a user