From 3a100d925bfc0225507fa3c8049f0f04cca11a3e Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Tue, 21 Apr 2020 00:51:51 -0400 Subject: [PATCH] perfect collisions perso/map and solve #5 with collisions bullet/map --- asset/asset.svg | 73 ++++++++++++++++++++++++++++------------- asset/perso.png | Bin 0 -> 819 bytes asset/perso1_right.png | Bin 236 -> 938 bytes main.py | 2 +- models.py | 37 ++++++++++++--------- 5 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 asset/perso.png diff --git a/asset/asset.svg b/asset/asset.svg index d3b414f..6b764c7 100644 --- a/asset/asset.svg +++ b/asset/asset.svg @@ -14,7 +14,7 @@ viewBox="0 0 210 297" version="1.1" id="svg8" - inkscape:version="0.92.4 5da689c313, 2019-01-14" + inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)" sodipodi:docname="asset.svg"> @@ -25,9 +25,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="0.24748737" - inkscape:cx="-3244.5066" - inkscape:cy="371.0213" + inkscape:zoom="20.055905" + inkscape:cx="-1045.8998" + inkscape:cy="197.95561" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -73,24 +73,6 @@ y="238.79167" inkscape:export-xdpi="96" inkscape:export-ydpi="96" /> - - + + + + + + + + + diff --git a/asset/perso.png b/asset/perso.png new file mode 100644 index 0000000000000000000000000000000000000000..19c8aec1f630d618f1b43d5c5a6c6aa978e4f8a1 GIT binary patch literal 819 zcmV-31I+x1P)U?})bze~AdFq612j+mT24UP5gIbL4 zMj7vmo|#;mT?))L0Rzxgl;DfOr^&;A1RdJk8f)NXs#NdBk=BRaft^csemXM*B$|lv zAoOY`7M_LjH#C?`wgBUPU;q?(5VNen4rt>`>vih?pQ)$Nvb4u`Ksb!}h}llL4Ip7F z-RX$=hc?RAktd+Tp@YhXTqf(WN@8aiQgJ+SS zjrY9*CYz2CnQ$?`fdGs;qd=~So^0FK@Atd|dp3$uYwmbag7Y+fZ?;g{YKeZh*}LW) z+;elCj}NQ{wHOuE_YK5kgIXNejj0H7QG#9op8RWxicGYA+Ze30uZJog$MijWdr2L6 z1cd6e?U;Ysi;4gM002ovPDHLkV1m1DZ~p)Q literal 0 HcmV?d00001 diff --git a/asset/perso1_right.png b/asset/perso1_right.png index cca4d3004022641fc0d30fcfde86ea126c36d30e..ea122db7981ecfdb64c855742a79138b99dda5d7 100644 GIT binary patch delta 877 zcmV-z1Cspg0jdWfiBL{Q4GJ0x0000DNk~Le0000U0000U2nGNE06Q?QqLCp?e*-5; zL_t(YiM^LiYZE~j$Df&<>1H=}n>K0*k!1y zWHLF*80*jFay_PLl4|vY5Yypse4~`kyWQ>wV`F2vLxTf>z%XO%o?#fhoby^QP&p|= z;B-2d9S+CiSS&VkP%sJxgHJX$H-{Kw#|}l@B|=D6QIuJq&o`)PnpHj~f0PHBrs1xx zu325z1Ey&@>VX0PSeDgNC=}cP0Diy!^Wx&-&eGxX!nL)vr@F3Rw=7H8JxLvKlMphq zv9U2wp5Fn7LZL`Do4s?CP+Q~U<4Ml>mvA_IwE`TCMx|UXH&XAOR@3zK^b$g-D-wyw zJK$6*HEI|}Z=;~L2qCWke?SEQz^bYWg+ihKut(;9G%+!eMF}eFN zQ!ogRz#lv2d=h`^I46^0v3RpqN2*77t5dYwF#--JxqbzgN~P0{g6^kIo<55?=f|53 zmY~><0YGjxSj47+YnL6pINv(Qf13?1f}mrB(C=o0bG#*uDW$8;e+K^m*9xYTzNM71 zMnSBthM2M+3sB}4S3ZzTCbJ-l;&;Z_`9^?$n$8lMgbq6%9*zupPI+QDkw}=LD89$I z@gI076lw*4f~IMfP19sqUTQR$QhHmKVJ9m#*5~s@T`t!-EOV z^VRI_AY-hx9w;Fs-PYFjy1To3WVgMoX6T0)V z^$IgEFyOE(>po-5pU>xeN~IF5R!;~qB}rPQl+Gc99>(MGL;QZVRl&AYRTW$=*X4XZ zf6Fw@)131YoO34tl(sKzDN5<8D2j7luXkbhvhJmSQ0_?^U-|`A00000NkvXXu0mjf D*mR6m delta 169 zcmZ3*{)SPpGr-TCmrII^fq{Y7)59eQNNa#F2OE&=`L`o?qM}bdL#C&TV@O2n+v^*7 z8w_|{E*d8tU2`B{%>+f??v$1mKSj-d+Of4eH|j7}i25JCX7rzL;*xudzvLJ@?Nhkm zx}e)Zym4J^*@0L&E%BV6yh1OOz=GF0)*2-1)*-90 - self.perso = pygame.transform.rotate(self.img_perso,self.degres_perso) + # if self.speed != [0,0]: + # if self.speed[0]!=0: + # self.degres_perso = -1*degrees(atan(self.speed[1]/self.speed[0])) + # if self.speed[0] < 0: + # self.degres_perso = 180+self.degres_perso + # else: + # self.degres_perso = ((self.speed[1]>0)*2-1)*-90 + # self.perso = pygame.transform.rotate(self.img_perso,self.degres_perso) #Calculate canon rotation: x_mouse, y_mouse = pygame.mouse.get_pos() @@ -172,17 +175,21 @@ class Projectile(pygame.sprite.Sprite): self.direction = direction = [cos(radians(angle)),-sin(radians(angle))] self.img = pygame.transform.rotate(pygame.image.load(img_path+texture).convert_alpha(),angle) self.rect = self.img.get_rect() + self.mask = pygame.mask.from_surface(self.img) def move(self): self.deplacement = (round(self.deplacement[0]+self.speed*self.direction[0]),round(self.deplacement[1]+self.speed*self.direction[1])) + def draw(self,surface,offset): surface.blit(self.img,(offset[0]+self.pos_init[0]+self.deplacement[0]-self.rect[0],offset[1]+self.pos_init[1]+self.deplacement[1]-self.rect[1])) - def is_out(self,surface): - if (self.deplacement[0]+surface.get_width()/2<0-self.img.get_width() or - self.deplacement[1]+surface.get_height()/2<0-self.img.get_height() or - self.deplacement[0]+surface.get_width()/2>surface.get_width()+self.img.get_width() or - self.deplacement[1]+surface.get_height()/2>surface.get_height()+self.img.get_height()): + def is_out(self,carte): + abs_pos = (self.pos_init[0]+self.deplacement[0],self.pos_init[1]+self.deplacement[1]) + if carte.mask.overlap(self.mask, (abs_pos[0]-self.rect.center[0],abs_pos[1]-self.rect.center[1])): + # if (self.deplacement[0]+surface.get_width()/2<0-self.img.get_width() or + # self.deplacement[1]+surface.get_height()/2<0-self.img.get_height() or + # self.deplacement[0]+surface.get_width()/2>surface.get_width()+self.img.get_width() or + # self.deplacement[1]+surface.get_height()/2>surface.get_height()+self.img.get_height()): return True else: return False \ No newline at end of file