Added tractor rotation
Before Width: | Height: | Size: 826 B After Width: | Height: | Size: 826 B |
Before Width: | Height: | Size: 792 B After Width: | Height: | Size: 792 B |
Before Width: | Height: | Size: 803 B After Width: | Height: | Size: 803 B |
Before Width: | Height: | Size: 818 B After Width: | Height: | Size: 818 B |
7
main.py
@ -13,8 +13,7 @@ myTractor = tractor.Tractor
|
||||
#screen background
|
||||
def set_screen():
|
||||
SCREEN.fill((0,100,0))
|
||||
pygame.display.update()
|
||||
TRACTOR = pygame.draw.rect(SCREEN, (255, 255, 255), (myTractor.x, myTractor.y, myTractor.width, myTractor.height))
|
||||
TRACTOR = SCREEN.blit(myTractor.ROTATION_IMG, (myTractor.x, myTractor.y))
|
||||
pygame.display.update()
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -26,12 +25,16 @@ if __name__ == "__main__":
|
||||
running = False
|
||||
keys = pygame.key.get_pressed()
|
||||
if keys[pygame.K_LEFT] and myTractor.x>0:
|
||||
myTractor.ROTATION_IMG = myTractor.LEFT
|
||||
myTractor.x -= myTractor.speed
|
||||
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()
|
||||
|
||||
|
10
tractor.py
@ -1,3 +1,5 @@
|
||||
import pygame
|
||||
|
||||
class Tractor:
|
||||
#this is where tractor spawns when program starts (center)
|
||||
x=500
|
||||
@ -7,3 +9,11 @@ class Tractor:
|
||||
#it's size
|
||||
width = 20
|
||||
height = 20
|
||||
|
||||
#tractor image rotation
|
||||
ROTATION_IMG = pygame.image.load('assets/tractor/tractor_UP.png')
|
||||
UP = pygame.image.load('assets/tractor/tractor_UP.png')
|
||||
DOWN = pygame.image.load('assets/tractor/tractor_DOWN.png')
|
||||
LEFT = pygame.image.load('assets/tractor/tractor_LEFT.png')
|
||||
RIGHT = pygame.image.load('assets/tractor/tractor_RIGHT.png')
|
||||
|
||||
|