2023-03-07 12:28:13 +01:00
|
|
|
import pygame
|
2023-03-07 13:00:35 +01:00
|
|
|
import tractor
|
2023-03-07 12:28:13 +01:00
|
|
|
|
|
|
|
#pygame initialization
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
#set screen
|
|
|
|
SCREEN = pygame.display.set_mode((1000, 1000))
|
|
|
|
pygame.display.set_caption("Traktor_interaktor")
|
|
|
|
|
2023-03-07 13:00:35 +01:00
|
|
|
myTractor = tractor.Tractor
|
|
|
|
|
2023-03-07 12:28:13 +01:00
|
|
|
#screen background
|
|
|
|
def set_screen():
|
|
|
|
SCREEN.fill((0,100,0))
|
2023-03-11 12:14:30 +01:00
|
|
|
TRACTOR = SCREEN.blit(myTractor.ROTATION_IMG, (myTractor.x, myTractor.y))
|
2023-03-07 13:00:35 +01:00
|
|
|
pygame.display.update()
|
2023-03-07 12:28:13 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
running = True
|
|
|
|
|
|
|
|
while running:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
running = False
|
2023-03-07 13:00:35 +01:00
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
if keys[pygame.K_LEFT] and myTractor.x>0:
|
2023-03-11 12:14:30 +01:00
|
|
|
myTractor.ROTATION_IMG = myTractor.LEFT
|
2023-03-07 13:00:35 +01:00
|
|
|
myTractor.x -= myTractor.speed
|
|
|
|
if keys[pygame.K_RIGHT] and myTractor.x<1000-myTractor.width:
|
2023-03-11 12:14:30 +01:00
|
|
|
myTractor.ROTATION_IMG = myTractor.RIGHT
|
2023-03-07 13:00:35 +01:00
|
|
|
myTractor.x += myTractor.speed
|
|
|
|
if keys[pygame.K_UP] and myTractor.y>0:
|
2023-03-11 12:14:30 +01:00
|
|
|
myTractor.ROTATION_IMG = myTractor.UP
|
2023-03-07 13:00:35 +01:00
|
|
|
myTractor.y -= myTractor.speed
|
|
|
|
if keys[pygame.K_DOWN] and myTractor.y<1000-myTractor.height:
|
2023-03-11 12:14:30 +01:00
|
|
|
myTractor.ROTATION_IMG = myTractor.DOWN
|
2023-03-07 13:00:35 +01:00
|
|
|
myTractor.y += myTractor.speed
|
2023-03-07 12:28:13 +01:00
|
|
|
set_screen()
|
|
|
|
|
|
|
|
pygame.quit()
|