From 93888c2addeeb24ae05cd0430f372282184c5e3e Mon Sep 17 00:00:00 2001 From: dardwo Date: Sat, 11 Mar 2023 12:14:30 +0100 Subject: [PATCH] Added tractor rotation --- .DS_Store | Bin 0 -> 6148 bytes __pycache__/tractor.cpython-310.pyc | Bin 357 -> 648 bytes .../tracktor_S.png => tractor/tractor_DOWN.png} | Bin .../tracktor_W.png => tractor/tractor_LEFT.png} | Bin .../tractor_RIGHT.png} | Bin .../tracktor_N.png => tractor/tractor_UP.png} | Bin main.py | 7 +++++-- tractor.py | 10 ++++++++++ 8 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .DS_Store rename assets/{tracktor/tracktor_S.png => tractor/tractor_DOWN.png} (100%) rename assets/{tracktor/tracktor_W.png => tractor/tractor_LEFT.png} (100%) rename assets/{tracktor/tracktor_E.png => tractor/tractor_RIGHT.png} (100%) rename assets/{tracktor/tracktor_N.png => tractor/tractor_UP.png} (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T00x4)$C#HR`k~O#X`jto^yx_Xt*xl(o9DNwrDeyya+kRL;k% z$G4=92Os+X6})}*I;{myZu!DVuluG}^g9PGl5(zQT1wZFa#rAC>Uk{X`9e*%8FuN| z(uKCv8eMpiV>NM&iO$E9$~DU6nCe}a&(v5uF)b9j_+*g2OnZaA?7izcJ{mgV+jheD z=EAyx?_loJ7;576S6z8B!Qh7+Zk2nJJ1Pg(;XplQ|ir3>h#2 zISxQvtS~WKo-Kt1sEBpq83|@TO^(S~j1CGb8H#v-(qQ73mVQQlZmND(Vs>egesM`@ zN@n6@0VYX*kRc#k3{uL$z{14B2*gYrj71<(KTQaYFbKlp11M6o3 I3JEa)03;tGx&QzG diff --git a/assets/tracktor/tracktor_S.png b/assets/tractor/tractor_DOWN.png similarity index 100% rename from assets/tracktor/tracktor_S.png rename to assets/tractor/tractor_DOWN.png diff --git a/assets/tracktor/tracktor_W.png b/assets/tractor/tractor_LEFT.png similarity index 100% rename from assets/tracktor/tracktor_W.png rename to assets/tractor/tractor_LEFT.png diff --git a/assets/tracktor/tracktor_E.png b/assets/tractor/tractor_RIGHT.png similarity index 100% rename from assets/tracktor/tracktor_E.png rename to assets/tractor/tractor_RIGHT.png diff --git a/assets/tracktor/tracktor_N.png b/assets/tractor/tractor_UP.png similarity index 100% rename from assets/tracktor/tracktor_N.png rename to assets/tractor/tractor_UP.png diff --git a/main.py b/main.py index 92a9e04..ea57a68 100644 --- a/main.py +++ b/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() diff --git a/tractor.py b/tractor.py index 306c088..6601852 100644 --- a/tractor.py +++ b/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') +