Spaces:
Sleeping
Sleeping
import random | |
from classes.Collider import Collider | |
class LeftRightWalkTrait: | |
def __init__(self, entity, level): | |
self.direction = random.choice([-1, 1]) | |
self.entity = entity | |
self.collDetection = Collider(self.entity, level) | |
self.speed = 1 | |
self.entity.vel.x = self.speed * self.direction | |
def update(self): | |
if self.entity.vel.x == 0: | |
self.direction *= -1 | |
self.entity.vel.x = self.speed * self.direction | |
self.moveEntity() | |
def moveEntity(self): | |
self.entity.rect.y += self.entity.vel.y | |
self.collDetection.checkY() | |
self.entity.rect.x += self.entity.vel.x | |
self.collDetection.checkX() | |