def changePositionBy(self, action, x, y): pass_x = pass_y = False # Check if any movement is blocked if self.blockMovement["right"] and x > 0: pass_x = True if self.blockMovement["left"] and x < 0: pass_x = True if self.blockMovement["up"] and y < 0: pass_y = True if self.blockMovement['down'] and y > 0: pass_y = True previous = Vector2(x, y) # Perform Movement if action == TRANSFORM2D_MV_POS: if not pass_x: self.x += x for child in self.parent.children: child.getComponentByType("transform2d").changePositionBy(TRANSFORM2D_MV_POS, x, 0) if not pass_y: self.y += y for child in self.parent.children: child.getComponentByType("transform2d").changePositionBy(TRANSFORM2D_MV_POS, 0, y) self.offsetLastFrame = Vector2(Vector2(self.x, self.y) - previous) self.blockMovement["up"] = False self.blockMovement["down"] = False self.blockMovement["right"] = False self.blockMovement["left"] = False
def __init__(self): self.gravity = 2.0 self.mass = 1.0 self.gravityFrame = 1 self.gravityForce = Vector2(0, self.GetGravityForce()) self.forces = [] self.forceDecreasing = [] self.frame = Vector2(0, 0) self.my_type = "physiqs"
def getFullInformation(self): return { "x": self.x, "y": self.y, "width": self.width, "height": self.height, "end_x": self.x + self.width, "end_y": self.y + self.height, "vector2": { "start": Vector2(self.x, self.y), "end": Vector2(self.x + self.width, self.y + self.height,) } }
def __init__(self): self.x: int self.y: int self.width: int self.height: int self.offsetLastFrame = Vector2(0, 0) self.blockMovement = { "up": False, "right": False, "down": False, "left": False } self.my_type = "transform2d"
def appendForces(self): del_indexes = [] self.frame = Vector2(0, self.GetGravityForce() * self.screen.fixedUpdateTimout) for i in range(len(self.forces)): self.frame += Vector2(self.forces[i].x * self.screen.fixedUpdateTimout, self.forces[i].y * self.screen.fixedUpdateTimout) self.forces[i] -= Vector2(self.forceDecreasing[i], self.forceDecreasing[i]) self.forceDecreasing[i] += self.forceDecreasing[i] * .2 - self.mass * .2 if self.forces[i].x < 0: self.forces[i].x = 0 if self.forces[i].y < 0: self.forces[i].y = 0 if self.forces[i].x <= 0 and self.forces[i].y <= 0: del_indexes.append(i) for i in del_indexes: self.forceDecreasing.pop(i) self.forces.pop(i) for j in range(len(del_indexes)): if del_indexes[j] > i: del_indexes[j] -= 1
def getPosition(self): return Vector2(self.x, self.y)
def checkReset(self): if self.transform2d.blockMovement["down"]: self.addForce(Vector2(0, -1), 5 / self.mass) self.gravityFrame = 1