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
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()
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
--- /dev/null
+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)
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)