Added tractor rotation #4
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
|
#screen background
|
||||||
def set_screen():
|
def set_screen():
|
||||||
SCREEN.fill((0,100,0))
|
SCREEN.fill((0,100,0))
|
||||||
pygame.display.update()
|
TRACTOR = SCREEN.blit(myTractor.ROTATION_IMG, (myTractor.x, myTractor.y))
|
||||||
TRACTOR = pygame.draw.rect(SCREEN, (255, 255, 255), (myTractor.x, myTractor.y, myTractor.width, myTractor.height))
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -26,12 +25,16 @@ if __name__ == "__main__":
|
|||||||
running = False
|
running = False
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_LEFT] and myTractor.x>0:
|
if keys[pygame.K_LEFT] and myTractor.x>0:
|
||||||
|
myTractor.ROTATION_IMG = myTractor.LEFT
|
||||||
myTractor.x -= myTractor.speed
|
myTractor.x -= myTractor.speed
|
||||||
if keys[pygame.K_RIGHT] and myTractor.x<1000-myTractor.width:
|
if keys[pygame.K_RIGHT] and myTractor.x<1000-myTractor.width:
|
||||||
|
myTractor.ROTATION_IMG = myTractor.RIGHT
|
||||||
myTractor.x += myTractor.speed
|
myTractor.x += myTractor.speed
|
||||||
if keys[pygame.K_UP] and myTractor.y>0:
|
if keys[pygame.K_UP] and myTractor.y>0:
|
||||||
|
myTractor.ROTATION_IMG = myTractor.UP
|
||||||
myTractor.y -= myTractor.speed
|
myTractor.y -= myTractor.speed
|
||||||
if keys[pygame.K_DOWN] and myTractor.y<1000-myTractor.height:
|
if keys[pygame.K_DOWN] and myTractor.y<1000-myTractor.height:
|
||||||
|
myTractor.ROTATION_IMG = myTractor.DOWN
|
||||||
myTractor.y += myTractor.speed
|
myTractor.y += myTractor.speed
|
||||||
set_screen()
|
set_screen()
|
||||||
|
|
||||||
|
10
tractor.py
@ -1,3 +1,5 @@
|
|||||||
|
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=500
|
||||||
@ -7,3 +9,11 @@ class Tractor:
|
|||||||
#it's size
|
#it's size
|
||||||
width = 20
|
width = 20
|
||||||
height = 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')
|
||||||
|
|
||||||
|