from Setup import *
from PhysicsBody import PhysicsBody
+from Block import Block
class Actor:
width, height = 50, 100
if thing == self:
continue
if collision_rect.colliderect(thing.get_collision_rect()):
+ print(self, vel, thing.velocity)
if thing.movable:
- thing.velocity.x = vel.x
- if vel.x > 0:
- pos.x = thing.position.x - self.width
- vel.x = min(vel.x, 0)
- elif vel.x < 0:
- pos.x = thing.position.x + thing.width
- vel.x = max(vel.x, 0)
+ if vel.x > 0:
+ thing.position.x = pos.x + self.width
+ elif vel.x < 0:
+ thing.position.x = pos.x - thing.width
+ else:
+ if vel.x > 0:
+ pos.x = thing.position.x - self.width
+ vel.x = min(vel.x, 0)
+ elif vel.x < 0:
+ pos.x = thing.position.x + thing.width
+ vel.x = max(vel.x, 0)
collision_rect = self.get_collision_rect(pos)
self.on_ground = False
if area.is_colliding(thing):
area.signal(thing)
if collision_rect.colliderect(thing.get_collision_rect()):
- if thing.movable:
- thing.velocity.y = vel.y
-
if vel.y > 0:
pos.y = thing.position.y - self.height
- vel.y = min(vel.y, 0)
+ vel.y = min(vel.y + thing.velocity.y, 0)
self.on_ground = True
elif vel.y < 0:
pos.y = thing.position.y + thing.height
- vel.y = max(vel.y, 0)
+ vel.y = max(vel.y + thing.velocity.y, 0)
collision_rect = self.get_collision_rect(pos)
return pos, vel
self.dizzy_time = max(0,self.dizzy_time)
# Deals with collision and applying velocity
- self.position, self.velocity = self.move_and_collide(self.position, self.velocity, delta)
+ self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x))
def update(self, delta):
+ Setup.camera_offset += self.player.update(delta)
for i,enemy in enumerate(self.enemies):
enemy.update(delta, self.player)
for block in self.blocks:
block.update(delta)
- Setup.camera_offset += self.player.update(delta)
# self.pet.update(delta, self.player, self.camera_pos)
thing.velocity.x = vel.x
if vel.x > 0:
pos.x = thing.position.x - self.width
- vel.x = min(vel.x, 0)
+ vel.x = min(vel.x+ thing.velocity.x, 0)
elif vel.x < 0:
pos.x = thing.position.x + thing.width
- vel.x = max(vel.x, 0)
+ vel.x = max(vel.x+ thing.velocity.x, 0)
collision_rect = self.get_collision_rect(pos)
self.on_ground = False
pos.y += vel.y * delta
if vel.y > 0:
pos.y = thing.position.y - self.height
- vel.y = min(vel.y, 0)
+ vel.y = min(vel.y+ thing.velocity.y, 0)
self.on_ground = True
elif vel.y < 0:
pos.y = thing.position.y + thing.height
- vel.y = max(vel.y, 0)
+ vel.y = max(vel.y+ thing.velocity.y, 0)
collision_rect = self.get_collision_rect(pos)
return pos, vel
import pygame.key
+import Setup
from Setup import *
from Actors import Actor
self.handle_input()
# Deals with collision and applying velocity
- self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity, delta)
+ self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
return self.velocity * delta
def handle_input(self):
def draw(self, surf):
super().draw(surf)
+ # print(self.position, self.velocity, get_display_rect(self.get_collision_rect()).topleft, Setup.camera_offset)
+ # pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
+
# pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8)
# Healthbar Stuff
pos = collision_rect.topleft
width, height = collision_rect.w, collision_rect.h
return pg.Rect(pos - camera_offset, (width, height))
+ # return pg.Rect(pos, (width, height))
old_level = 0
-level = 0
+level = 1
while is_running:
if pg.event.peek(pg.QUIT):