Merge pull request 'Added tractor rotation' (#4) from tractor_icon_rotation into main

Reviewed-on: s473634/TurboTraktor#4
Reviewed-by: s473634
This commit is contained in:
Miłosz Rolewski 2023-03-11 19:47:49 +01:00
commit b61c1ddb6e
8 changed files with 15 additions and 2 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 826 B

After

Width:  |  Height:  |  Size: 826 B

View File

Before

Width:  |  Height:  |  Size: 792 B

After

Width:  |  Height:  |  Size: 792 B

View File

Before

Width:  |  Height:  |  Size: 803 B

After

Width:  |  Height:  |  Size: 803 B

View File

Before

Width:  |  Height:  |  Size: 818 B

After

Width:  |  Height:  |  Size: 818 B

View File

@ -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()

View File

@ -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')