From b5e4710b029d9d0178eee336ef11423973549ce6 Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Thu, 7 Jul 2022 12:13:53 -0400 Subject: [PATCH] work from last night --- .idea/.gitignore | 3 +++ .idea/Pygame-Jam-main.iml | 8 ++++++++ Actors.py | 1 + Enemy.py | 6 +++--- SWORD.png | Bin 0 -> 848 bytes Setup.py | 9 ++++++--- Test.py | 24 ++++++++++++++++++++++++ Weapon.py | 27 +++++++++++++++++---------- main.py | 1 + 9 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Pygame-Jam-main.iml create mode 100644 SWORD.png create mode 100644 Test.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Pygame-Jam-main.iml b/.idea/Pygame-Jam-main.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Pygame-Jam-main.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Actors.py b/Actors.py index 091f72f..deda98e 100644 --- a/Actors.py +++ b/Actors.py @@ -130,6 +130,7 @@ class Actor: def draw(self, surf): pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=8) + # pg.draw.rect(surf, (0,0,0), self.get_collision_rect(), border_radius=8, width=2) # Uncomment for debugging area hitboxes # for area in self.areas.values(): diff --git a/Enemy.py b/Enemy.py index 3a26398..1290015 100644 --- a/Enemy.py +++ b/Enemy.py @@ -20,12 +20,12 @@ class Enemy(Actor): self.movable = True self.dizzy_time = 0 - self.weapon = Melee(self.position, (-35,self.height/2 - 20),self.width,-1) + self.weapon = Melee(self.position, (-Melee.width/2, Melee.height/2), (0, Melee.height), self.width,-1) def update(self, delta, target=None): super().update(delta) if target is not None and self.dizzy_time == 0: - self.follow_target(target,stop_dist=self.weapon.width + self.width + target.width) + self.follow_target(target,stop_dist=self.weapon.width * 0.8 + self.width + target.width) if self.weapon.get_collision_rect().colliderect(target.get_collision_rect()): self.weapon.swing() self.dizzy_time -= delta @@ -37,7 +37,7 @@ class Enemy(Actor): self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x)) def knockout(self, node): - self.dizzy_time = 5000 + self.dizzy_time = 2500 self.health -= 10 node.on_ground = True node.jump() diff --git a/SWORD.png b/SWORD.png new file mode 100644 index 0000000000000000000000000000000000000000..e1c410405a7b56f23e1472a7913705d5b8cf1540 GIT binary patch literal 848 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqrnmP}{o08eLUg@U5|w9K4T z1_q6ZwG(YU4m-#kjSt?cB-&mkPu1<$n;S?>ggHD;+TV5p;y%aae^azTPVZGke zEZ-f9dbuy#f#EQO`ZLWJ9Wo~aN zIrsZWV%Rj1N5zjgoAo^YoG88d)cl-kJL^12vrR869~o?nc$KuXJMv~gXL^Tn*Q&sM z6N)1r?l~H{_FClcd4F0DHf@{q(CTcU%7zw|AOXe2eO#+H2rLa%KI$^-+he(Zg2(48 zP4`*HC1EKR(9Cu6WAp!m@AJ++`Z8s!c{O#GN$={OK*l4i( z0|NtRfk$L91B0G22s2hJwJ&2}U|=ut^mS!_#?B_JC;RsCN__?f2FViFh!W@g+}zZ> z5(ej@)Wnk16ovB4k_-iRPv3y>Mm}){21X4}7sn8b(`&En_d4t#bKv89Sw#gF#}kUB zCl^c*pRlK8_u-w(vds%$C){6f_tF}-g7@A}c)9c9WN~YQ|FeQyIE)R z??p-RCVk1%POG{GYCKpgT;XxKd0$s;KqbeF=Rao}wrOI`eP zC)~?+`y9379|v3a#_yLLo-@CUzgu7H*M7;%y?}N94Xr(oAO8Gxc;&^_9Cg0N1ydA4wo;@o3I@e#}z~i;){rwNvrB?M_{=mss$H2hA;OXk;vd$@?2>?AD Bct!vK literal 0 HcmV?d00001 diff --git a/Setup.py b/Setup.py index 6c1d1dd..6292488 100644 --- a/Setup.py +++ b/Setup.py @@ -20,6 +20,9 @@ fps = 60 screen = pg.display.set_mode(dimensions, pg.SCALED) -def rotate(img ,angle, pivot): - center = img.get_rect().center - rot_image = pygame.transform.rotate(img, angle) + +def rotate(pos, img, angle, pivot): + vec = (pos - pivot).rotate(-angle) + pivot + rot_img = pg.transform.rotozoom(img, angle, 1) + rot_rect = rot_img.get_rect(center=vec) + return rot_img, rot_rect diff --git a/Test.py b/Test.py new file mode 100644 index 0000000..ba64cc4 --- /dev/null +++ b/Test.py @@ -0,0 +1,24 @@ +from Setup import * + + +class Test: + + def __init__(self): + self.position = center.copy() + + self.angle = 0 + self.pivot = pg.Vector2(SCREEN_WIDTH / 2 + 50, SCREEN_HEIGHT / 2 + 50) + self.img = pg.transform.scale(pygame.image.load("SWORD.png"), (100, 100)) + self.display = self.img.copy() + self.img_rect = self.display.get_rect() + + def update(self, delta): + self.display, self.img_rect = rotate(self.position, self.img, self.angle, self.pivot) + + self.angle += 1 + + def draw(self, surf): + surf.fill((0, 0, 0)) + surf.blit(self.display, self.img_rect.topleft) + + pg.draw.circle(surf, (255, 0, 0), self.pivot, 3) diff --git a/Weapon.py b/Weapon.py index c2179e4..f8793e0 100644 --- a/Weapon.py +++ b/Weapon.py @@ -4,43 +4,50 @@ from Setup import * class Melee: - img = pg.transform.smoothscale(pg.image.load("Assets/SWORD.png"), (40,40)) + img = pg.transform.scale(pg.image.load("SWORD.png"), (40,40)) flipped_img = pg.transform.flip(img,True,False) width,height = img.get_size() - def __init__(self, pos, offset, width,direction): + + def __init__(self, pos, offset, pivot, width,direction): self.position = pg.Vector2(pos) self.offset = pg.Vector2(offset) + self.pivot = self.position + pg.Vector2(pivot) self.holder_width = width self.direction = direction self.display = self.img + self.display_rect = self.display.get_rect() self.swing_timer = 0 + def update(self, delta, pos, direction): self.position = pg.Vector2(pos) + self.pivot = self.position + self.offset + pg.Vector2(self.width/2, self.height/2) self.direction = direction if self.direction == -1: - angle = 145 * (math.sin(math.radians((self.swing_timer)))) - print(self.swing_timer,angle) - self.display = pg.transform.rotate(self.img, angle) - elif self.direction == 0: - self.display = pg.transform.rotate(self.flipped_img, 360 * math.sin(math.radians(self.swing_timer/10))) + angle = 25 * (math.sin(math.radians(self.swing_timer))) + self.display, self.display_rect = rotate(self.position + self.offset, self.img, angle,self.pivot) + elif self.direction == 1: + angle = -25 * (math.sin(math.radians(self.swing_timer))) + self.display, self.display_rect = rotate(self.position+ pg.Vector2(self.holder_width,0) + pg.Vector2(-self.offset.x, self.offset.y), self.flipped_img, angle,self.pivot + pg.Vector2(self.holder_width,0)) self.swing_timer -= delta self.swing_timer = max(self.swing_timer, 0) def get_collision_rect(self): if self.direction == -1: - return pg.Rect(self.position - pg.Vector2(self.width,0),(self.width, self.height)) + return pg.Rect(self.display_rect.topleft,(self.width, self.height)) elif self.direction == 1: - return pg.Rect(self.position + pg.Vector2(self.holder_width,0),(self.width, self.height)) + return pg.Rect(self.display_rect.topleft,(self.width, self.height)) def swing(self): if True: if self.swing_timer == 0: - self.swing_timer = 180 + self.swing_timer = 360 def draw(self, surf): surf.blit(self.display, self.get_collision_rect().topleft) + # pygame.draw.circle(surf,(255,0,255),self.pivot,3) + # pygame.draw.circle(surf,(0,255,0),self.position,3) diff --git a/main.py b/main.py index 2d49c26..507912d 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from Setup import * from Game import Game +from Test import Test from MainMenu import Menu delta = 1000//fps -- 2.54.0