ignore_*
/ignore
-*/__pycache__
\ No newline at end of file
+*/__pycache__
+.idea/Pygame-Jam-main.iml
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
- <orderEntry type="inheritedJdk" />
+ <orderEntry type="jdk" jdkName="Python 3.10 (Pygame-Jam)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
thing.velocity.x = vel.x
if vel.x > 0:
pos.x = thing.position.x - self.width
- vel.x = min(vel.x + thing.velocity.x, 0)
+ vel.x = min(vel.x, 0)
elif vel.x < 0:
pos.x = thing.position.x + thing.width
- vel.x = max(vel.x + thing.velocity.x, 0)
+ vel.x = max(vel.x, 0)
collision_rect = self.get_collision_rect(pos)
self.on_ground = False
area.signal(thing)
if collision_rect.colliderect(thing.get_collision_rect()):
if thing.movable:
- thing.velocity.y += vel.y
+ thing.velocity.y = vel.y
if vel.y > 0:
pos.y = thing.position.y - self.height
- vel.y = min(vel.y + thing.velocity.y, 0)
+ vel.y = min(vel.y, 0)
self.on_ground = True
elif vel.y < 0:
pos.y = thing.position.y + thing.height
- vel.y = max(vel.y + thing.velocity.y, 0)
+ vel.y = max(vel.y, 0)
collision_rect = self.get_collision_rect(pos)
return pos, vel
return pg.Rect(pos, (self.width, self.height))
def draw(self, surf):
- pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=8)
+ pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
# pg.draw.rect(surf, (0,0,0), self.get_collision_rect(), border_radius=8, width=2)
# Uncomment for debugging area hitboxes
return pg.Rect(self.position + self.offset, (self.width, self.height))
def draw(self, surf):
- pg.draw.rect(surf, (255,0,0),self.get_collision_rect())
+ pg.draw.rect(surf, (255,0,0),get_display_rect(self.get_collision_rect()))
def get_collision_rect(self):
return pg.Rect(self.position, (self.width, self.height))
-
def draw(self, surf):
- pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=5)
+ pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=5)
def knockout(self, node):
self.dizzy_time = 2500
- self.health -= 10
+ self.modify_health(-50, None)
node.on_ground = True
node.jump()
# self.crouch(1000)
+import Setup
from Setup import *
+from Setup import camera_offset
from Player import Player
from Pet import Pet
from Enemy import Enemy
self.collision_layer = {"world":set(),"player": set(), "enemy":set(), "pet":set()}
self.player = Player(center, self.collision_layer["player"], [self.collision_layer["enemy"], self.collision_layer["world"]])
- self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
+ # self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
self.enemies = [Enemy((SCREEN_WIDTH * 3 /4, 0),self.collision_layer["enemy"], [self.collision_layer["player"], self.collision_layer["world"]])]
- self.blocks = [Block((0, SCREEN_HEIGHT * 3 / 4),self.collision_layer["world"])]
- # Block((SCREEN_WIDTH/2 - 50, SCREEN_HEIGHT * 3 / 4),self.collision_layer[0]),
- # Block((SCREEN_WIDTH/2 + 50, SCREEN_HEIGHT * 3 / 4),self.collision_layer[0]),
+ self.blocks = [Block((0, SCREEN_HEIGHT * 3 / 4),self.collision_layer["world"]),
+ Block((SCREEN_WIDTH, SCREEN_HEIGHT * 3 / 4 - 25),self.collision_layer["world"])]
def update(self, delta):
-
for i,enemy in enumerate(self.enemies):
enemy.update(delta, self.player)
if enemy.dead:
for block in self.blocks:
block.update(delta)
- self.player.update(delta)
- self.pet.update(delta, self.player)
+ Setup.camera_offset += self.player.update(delta)
+
+ # self.pet.update(delta, self.player, self.camera_pos)
def draw(self, surf):
screen.fill((255, 255, 255))
thing.velocity.x = vel.x
if vel.x > 0:
pos.x = thing.position.x - self.width
- vel.x = min(vel.x + thing.velocity.x, 0)
+ vel.x = min(vel.x, 0)
elif vel.x < 0:
pos.x = thing.position.x + thing.width
- vel.x = max(vel.x + thing.velocity.x, 0)
+ vel.x = max(vel.x, 0)
collision_rect = self.get_collision_rect(pos)
self.on_ground = False
pos.y += vel.y * delta
continue
if collision_rect.colliderect(thing.get_collision_rect()):
if thing.movable:
- thing.velocity.y += vel.y
+ thing.velocity.y = vel.y
if vel.y > 0:
pos.y = thing.position.y - self.height
- vel.y = min(vel.y + thing.velocity.y, 0)
+ vel.y = min(vel.y, 0)
self.on_ground = True
elif vel.y < 0:
pos.y = thing.position.y + thing.height
- vel.y = max(vel.y + thing.velocity.y, 0)
+ vel.y = max(vel.y, 0)
collision_rect = self.get_collision_rect(pos)
return pos, vel
def draw(self, surf):
# print(self.position, self.velocity)
- pg.draw.rect(surf, self.colour, self.get_collision_rect(), border_radius=8)
+ pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
from Setup import *
from Actors import Actor
+
class Player(Actor):
width, height = 25, 50
colour = (52, 94, 235)
jump_strength = 0.9
gravity = 0.098
friction = 0.7
-
def __init__(self, pos, collision_layer, collision_mask):
super().__init__(pos, collision_layer, collision_mask)
# self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)}
-
def update(self, delta):
super().update(delta)
self.handle_input()
# 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, delta)
+ return self.velocity * delta
def handle_input(self):
pressed = pygame.key.get_pressed()
def draw(self, surf):
super().draw(surf)
-
-
- #Healthbar Stuff
- #bar is made of 2 rectanges, background which is just a simple rectange and foreground which goes on top and has a bit of math involved
- background_rect = pg.Rect(20, 20, 1080*0.2, 640*0.08)
-
- #idea is that 1080*0.185 = size of bar at 100% hp, at lower hp you want to get a fraction of that which is why we multiply by (health*0.01) example: 70 hp * 0.01 = 0.7
- foreground_rect = pg.Rect(0, 0, 1080*0.185*(self.health*0.01), 640*0.06)
- #make sure the red part health bar always sits on the left
- #sets bar to center of background bar, then subtracts 1/2 of blank space to put it on the left
- foreground_rect.center = (background_rect.centerx - 1080*0.185*((1 - self.health*0.01)/2), background_rect.centery)
+ # pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8)
+
+ # Healthbar Stuff
+ # bar is made of 2 rectanges, background which is just a simple rectange and foreground which goes on top and has a bit of math involved
+ background_rect = pg.Rect(20, 20, 1080 * 0.2, 640 * 0.08)
+
+ # idea is that 1080*0.185 = size of bar at 100% hp, at lower hp you want to get a fraction of that which is why we multiply by (health*0.01) example: 70 hp * 0.01 = 0.7
+ foreground_rect = pg.Rect(0, 0, 1080 * 0.185 * (self.health * 0.01), 640 * 0.06)
+ # make sure the red part health bar always sits on the left
+ # sets bar to center of background bar, then subtracts 1/2 of blank space to put it on the left
+ foreground_rect.center = (
+ background_rect.centerx - 1080 * 0.185 * ((1 - self.health * 0.01) / 2), background_rect.centery)
pg.draw.rect(surf, (54, 54, 54), background_rect)
pg.draw.rect(surf, (255, 0, 0), foreground_rect)
-
- #text
- font = pg.font.Font("Font/Exo2-Regular.ttf" , 30)
+
+ # text
+ font = pg.font.Font("Font/Exo2-Regular.ttf", 30)
current_health = str(self.health) + "/100"
current_health_display = font.render(current_health, True, (255, 255, 255))
- text_rect = current_health_display.get_rect(center = background_rect.center)
+ text_rect = current_health_display.get_rect(center=background_rect.center)
surf.blit(current_health_display, text_rect)
rot_img = pg.transform.rotozoom(img, angle, 1)
rot_rect = rot_img.get_rect(center=vec)
return rot_img, rot_rect
+
+camera_offset = pg.Vector2(0,0)
+
+def get_display_rect(collision_rect):
+ pos = collision_rect.topleft
+ width, height = collision_rect.w, collision_rect.h
+ return pg.Rect(pos - camera_offset, (width, height))
self.swing_timer = 360
def draw(self, surf):
- surf.blit(self.display, self.get_collision_rect().topleft)
+ surf.blit(self.display, get_display_rect(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)