]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
halfway
authorSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 17:34:06 +0000 (13:34 -0400)
committerSkullheadx <704277@pdsb.net>
Thu, 7 Jul 2022 17:34:06 +0000 (13:34 -0400)
.gitignore
.idea/Pygame-Jam-main.iml
Actors.py
Area.py
Block.py
Enemy.py
Game.py
PhysicsBody.py
Player.py
Setup.py
Weapon.py

index 0e40883413626464dcf6e72ffbd225e744b02564..3f26c87d0b43879eb24a9c27d5977b2c87e5fea8 100644 (file)
@@ -10,4 +10,5 @@
 
 ignore_*
 /ignore
-*/__pycache__
\ No newline at end of file
+*/__pycache__
+.idea/Pygame-Jam-main.iml
index d0876a78d06ac03b5d78c8dcdb95570281c6f1d6..1739b24714f62a82c768fa04a5310d2aedbb99e4 100644 (file)
@@ -2,7 +2,7 @@
 <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
index deda98e2190df2fe382ea415581f33592bdb51c9..bf4edb77b21046bb73882eec57dc2f1a7fb7c58d 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -92,10 +92,10 @@ class Actor:
                         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
@@ -110,15 +110,15 @@ class Actor:
                         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
@@ -129,7 +129,7 @@ class Actor:
         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
diff --git a/Area.py b/Area.py
index 8babd5b9770cea2dc8f04a7e8d35c700ddbb5c6b..9a83242511c03d6be0eb5109b667102fabb1ac0e 100644 (file)
--- a/Area.py
+++ b/Area.py
@@ -37,4 +37,4 @@ class Area:
         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()))
index a5dd3a2ca2775bd29063a91d2ccc948f6f11d93e..6e77b193da44001cc1dec20c6227a9f82a43f593 100644 (file)
--- a/Block.py
+++ b/Block.py
@@ -17,6 +17,5 @@ class Block:
 
     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)
index 129001517354fe841eda66905a37ab58aa2822a4..1b253da311b5079e97c55fb058b76113064062b6 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -38,7 +38,7 @@ class Enemy(Actor):
 
     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)
diff --git a/Game.py b/Game.py
index 343be76ff7fb6150ba201e51c0b2d26613b261aa..6c80399596016a07df8c90250d1de3622d2ce9d1 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -1,4 +1,6 @@
+import Setup
 from Setup import *
+from Setup import camera_offset
 from Player import Player
 from Pet import Pet
 from Enemy import Enemy
@@ -11,17 +13,15 @@ class Game:
         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:
@@ -32,8 +32,9 @@ class Game:
         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))
index 2a73e137e68ededf10f2997d2355e79c61181d4d..6dbb26933a44fecf8dc24cfa28579dcbbc38929b 100644 (file)
@@ -45,10 +45,10 @@ class PhysicsBody:
                         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
@@ -59,15 +59,15 @@ class PhysicsBody:
                     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
 
@@ -78,4 +78,4 @@ class PhysicsBody:
 
     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)
index c90ea968e6fabcccc5aa8f580d3fb8a4f5389349..77785009415db2f4811c8e9ee418b3caba728c0b 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -3,6 +3,7 @@ import pygame.key
 from Setup import *
 from Actors import Actor
 
+
 class Player(Actor):
     width, height = 25, 50
     colour = (52, 94, 235)
@@ -10,13 +11,11 @@ class Player(Actor):
     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)
 
@@ -24,7 +23,8 @@ class Player(Actor):
         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()
@@ -37,23 +37,24 @@ class Player(Actor):
 
     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)
index 62924886536e752071582cb25ffc8b555c5ecf16..c3dfdcff53973ddcf2ed0682f2bb85d91af5f5b4 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -26,3 +26,10 @@ def rotate(pos, img, angle, pivot):
     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))
index f8793e068f3637978eee110daa98b5c3c43dd094..3d424e30a261815403da4515bcd8cb792340a5af 100644 (file)
--- a/Weapon.py
+++ b/Weapon.py
@@ -48,6 +48,6 @@ class Melee:
                 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)