-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSword.py
More file actions
38 lines (30 loc) · 1.26 KB
/
Sword.py
File metadata and controls
38 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
"""Sword module: melee weapon entity."""
import pygame
from Constants import SWORD_WID, SWORD_HT, STAB_OFFSET
__author__ = "Joshua Sonnenberg and Ethan Richardson"
class Sword(pygame.Rect):
"""Represents a sword weapon attached to an entity."""
def __init__(self, entity) -> None:
"""Initialize the sword.
Args:
entity: The entity (player or enemy) that owns this sword.
"""
super(Sword, self).__init__(entity.x+10, entity.y+10, SWORD_WID, SWORD_HT)
self.entity = entity
self.stab = False
self.sword_position = 'UP'
def update(self) -> None:
"""Update sword position based on entity position and facing direction."""
if self.entity.facing == 'RIGHT' or self.entity.facing == 'RSTOP':
self.x = self.entity.x+10
if self.stab:
self.x += STAB_OFFSET
elif self.entity.facing == 'LEFT' or self.entity.facing == 'LSTOP':
self.x = self.entity.x-30
if self.stab:
self.x -= STAB_OFFSET
if self.sword_position == 'UP':
self.y = self.entity.y+10
elif self.sword_position == 'DOWN':
self.y = self.entity.y+20