]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
fixed
authorSkullheadx <704277@pdsb.net>
Sun, 10 Jul 2022 02:05:56 +0000 (22:05 -0400)
committerSkullheadx <704277@pdsb.net>
Sun, 10 Jul 2022 02:05:56 +0000 (22:05 -0400)
Actors.py
Game.py
Levels/Level1.txt
Player.py
Setup.py

index 59e5e0b3ddbccf06c36d9fbe3735fef2080ecb39..87d3783588d3509074dc9fc93a209239feda924b 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -1,3 +1,6 @@
+from datetime import datetime, timedelta
+import threading
+
 from Setup import *
 from PhysicsBody import PhysicsBody
 from Block import Block
@@ -6,10 +9,14 @@ from Block import Block
 class Actor:
     width, height = 50, 100
     colour = (76, 82, 92)
-    speed = 0.5
+    speed = 0.6
     jump_strength = 1
-    gravity = 0.098
+    gravity = 0.2
     friction = 0.2
+    coyote_time_amount = timedelta(milliseconds=100)  # seconds after walking off ground that it still counts
+    jump_buffer = []
+    variable_jump_time = timedelta(milliseconds=125)  # how long to hold jump so we go higher
+    terminal_velocity = 15
 
     def __init__(self, pos, collision_layer, collision_mask):
         self.position = pg.Vector2(pos)
@@ -27,9 +34,17 @@ class Actor:
         self.areas = dict()
 
         self.movable = False
+
+        self.jumping = False
+        self.coyote_time = datetime.utcnow()
+        self.hold_jump = datetime.utcnow()
         self.stun_time = 0
 
     def update(self, delta):
+        if self.jumping:
+            if self.on_ground:
+                self.jumping = False
+
         self.stun_time -= delta
         self.stun_time = max(self.stun_time, 0)
 
@@ -44,7 +59,12 @@ class Actor:
             self.velocity.x *= self.friction
 
             # Apply gravity
-        self.velocity.y += self.gravity
+        if self.jumping and self.velocity.y > 0:
+            self.velocity.y += self.gravity * 2
+        else:
+            self.velocity.y += self.gravity
+        self.velocity.x = max(min(self.velocity.x, self.terminal_velocity), -self.terminal_velocity)
+        self.velocity.y = max(min(self.velocity.y, self.terminal_velocity), -self.terminal_velocity)
 
     def is_dead(self, reason=None):
         if self.health <= 0:
@@ -55,9 +75,11 @@ class Actor:
         if amount < 0:
             self.stun_time = -amount * 10
         self.is_dead(reason)
+
     def attack(self, enemy, weapon):
-        self.modify_health(weapon.damage,"enemy")
+        self.modify_health(weapon.damage, "enemy")
         self.push(enemy)
+
     def follow_target(self, node, follow_range=None, stop_dist=None):
         if stop_dist is None:
             stop_dist = max(self.height, self.width) * 1.5
@@ -78,14 +100,25 @@ class Actor:
 
     def jump(self):
         if self.stun_time == 0:
-            if self.on_ground:
-                self.velocity.y = -self.jump_strength
+            pass
+        if (self.on_ground and not self.jumping) or (datetime.utcnow() - self.hold_jump <= self.variable_jump_time):
+            self.velocity.y = -self.jump_strength
+            if not self.jumping:
+                self.hold_jump = datetime.utcnow()
+            self.jumping = True
+        # elif not (datetime.utcnow() - self.hold_jump <= self.variable_jump_time):
 
-    def move_left(self, customSpeed = speed):
+    def dash_left(self):
+        pass
+
+    def dash_right(self):
+        pass
+
+    def move_left(self, customSpeed=speed):
         if self.stun_time == 0:
             self.velocity.x = -customSpeed
 
-    def move_right(self, customSpeed = speed):
+    def move_right(self, customSpeed=speed):
         if self.stun_time == 0:
             self.velocity.x = customSpeed
 
@@ -99,7 +132,6 @@ class Actor:
     def push2(self, direction):
         self.velocity += pg.Vector2(direction, -1)
 
-
     def move_and_collide(self, pos, vel, delta):
         pos.x += vel.x * delta
         collision_rect = self.get_collision_rect(pos)
@@ -121,7 +153,8 @@ class Actor:
                         # vel.x = max(vel.x, 0)
                     collision_rect = self.get_collision_rect(pos)
 
-        self.on_ground = False
+        if datetime.utcnow() - self.coyote_time >= self.coyote_time_amount or self.jumping:
+            self.on_ground = False
         pos.y += vel.y * delta
         collision_rect = self.get_collision_rect(pos)
         for mask in self.collision_mask:
@@ -136,11 +169,11 @@ class Actor:
                         pos.y = thing.position.y - self.height
                         vel.y = min(vel.y, 0)
                         self.on_ground = True
+                        self.coyote_time = datetime.utcnow()
                     elif vel.y < 0:
                         pos.y = thing.position.y + thing.height
                         vel.y = max(vel.y, 0)
-                    collision_rect = self.get_collision_rect(pos)
-
+                    # collision_rect = self.get_collision_rect(pos)
         return pos, vel
 
     def get_collision_rect(self, pos=None):
diff --git a/Game.py b/Game.py
index a4eda61d94d2e440ea3f5796db49a38a16120e0a..fcc729b824be18d5c3253d63c54e2cf3cd626a30 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -56,6 +56,9 @@ class Game:
 
     def draw(self, surf):
         screen.fill((0, 191, 255))
+        # screen.fill((255,255,255))
+        # sky = pg.image.load("Assets/world/SKY.png")
+        # surf.blit(sky,(0,0))
         self.world.draw(surf)
         for enemy in self.enemies:
             enemy.draw(surf)
index a4ded547025c53cffe396251b52473c16dbb6889..ebd8233ed5cf62ebfdf8cb47f9c6d045a4fb6576 100644 (file)
@@ -1,15 +1,3 @@
 none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world
 1400.0,750.0|1300.0,800.0|1350.0,750.0|1300.0,750.0|1250.0,750.0|1250.0,800.0|1200.0,750.0|1050.0,750.0|1000.0,750.0|950.0,750.0|900.0,750.0|850.0,750.0|800.0,750.0|750.0,750.0|700.0,750.0|650.0,750.0|600.0,750.0|550.0,750.0|500.0,750.0|450.0,750.0|400.0,750.0|350.0,750.0|300.0,750.0|250.0,750.0|200.0,750.0|150.0,750.0|100.0,750.0|50.0,750.0|0.0,750.0|0.0,800.0|50.0,800.0|100.0,800.0|1100.0,750.0|1150.0,750.0|1200.0,800.0|1150.0,800.0|1100.0,800.0|1050.0,800.0|1000.0,800.0|800.0,800.0|750.0,800.0|700.0,800.0|650.0,800.0|600.0,800.0|250.0,800.0|200.0,800.0|150.0,800.0|1450.0,700.0|1500.0,700.0|1750.0,700.0|1800.0,700.0|1850.0,700.0|1900.0,700.0|1950.0,700.0|2000.0,700.0|2050.0,700.0|2050.0,750.0|2000.0,750.0|1950.0,750.0|1900.0,750.0|1850.0,750.0|1800.0,750.0|1700.0,700.0|1650.0,700.0|1600.0,700.0|1550.0,700.0|1750.0,750.0|1700.0,750.0|1650.0,750.0|1600.0,750.0|1550.0,750.0|1500.0,750.0|1450.0,750.0|2100.0,750.0|2450.0,700.0|2450.0,650.0|2450.0,750.0|2500.0,750.0|2500.0,700.0|2500.0,650.0|2500.0,600.0|2550.0,600.0|2550.0,650.0|2550.0,700.0|2550.0,750.0|2600.0,750.0|2600.0,700.0|2600.0,650.0|2600.0,600.0|2400.0,800.0|2450.0,800.0|2650.0,800.0|2600.0,800.0|2550.0,800.0|2500.0,800.0|2300.0,850.0|2350.0,850.0|2400.0,850.0|2450.0,850.0|2500.0,850.0|2550.0,850.0|2600.0,850.0|2650.0,850.0|2650.0,900.0|2600.0,900.0|2250.0,850.0|2250.0,900.0|2300.0,900.0|2350.0,900.0|2400.0,900.0|2450.0,900.0|2500.0,900.0|2550.0,900.0|2650.0,950.0|2600.0,950.0|2550.0,950.0|2500.0,950.0|2450.0,950.0|2400.0,950.0|2350.0,950.0|2300.0,950.0|2250.0,950.0|2200.0,950.0|2150.0,950.0|2100.0,950.0|2050.0,950.0|2000.0,950.0|1950.0,950.0|1900.0,950.0|1850.0,950.0|1800.0,950.0|1750.0,950.0|1700.0,950.0|1650.0,950.0|1600.0,950.0|1550.0,950.0|1500.0,950.0|1450.0,950.0|1400.0,950.0|1350.0,950.0|1300.0,950.0|1250.0,950.0|1200.0,950.0|1150.0,950.0|1100.0,950.0|1050.0,950.0|1000.0,950.0|950.0,950.0|900.0,950.0|850.0,950.0|800.0,950.0|750.0,950.0|700.0,950.0|650.0,950.0|600.0,950.0|550.0,950.0|450.0,900.0|400.0,900.0|350.0,900.0|300.0,900.0|250.0,900.0|200.0,900.0|150.0,900.0|100.0,900.0|50.0,900.0|0.0,900.0|0.0,950.0|50.0,950.0|100.0,950.0|150.0,950.0|200.0,950.0|250.0,950.0|300.0,950.0|350.0,950.0|400.0,950.0|450.0,950.0|500.0,950.0|500.0,900.0|550.0,900.0|600.0,900.0|650.0,900.0|700.0,900.0|750.0,900.0|800.0,900.0|850.0,900.0|900.0,900.0|1000.0,900.0|1050.0,900.0|1100.0,900.0|1150.0,900.0|1200.0,900.0|1250.0,900.0|1300.0,900.0|1350.0,900.0|1400.0,900.0|1450.0,900.0|1500.0,900.0|1400.0,850.0|1450.0,850.0|1500.0,850.0|1550.0,850.0|950.0,900.0|1600.0,850.0|1650.0,850.0|1700.0,850.0|1750.0,850.0|1800.0,850.0|1850.0,850.0|1900.0,850.0|1950.0,850.0|2000.0,850.0|2050.0,850.0|2100.0,850.0|2150.0,850.0|2200.0,850.0|2200.0,900.0|2150.0,900.0|2100.0,900.0|2050.0,900.0|2000.0,900.0|1950.0,900.0|1900.0,900.0|1850.0,900.0|1800.0,900.0|1750.0,900.0|1700.0,900.0|1650.0,900.0|1600.0,900.0|1550.0,900.0|1300.0,850.0|1250.0,850.0|1200.0,850.0|1150.0,850.0|1100.0,850.0|1050.0,850.0|1000.0,850.0|750.0,850.0|700.0,850.0|650.0,850.0|600.0,850.0|250.0,850.0|200.0,850.0|150.0,850.0|100.0,850.0|50.0,850.0|0.0,850.0|300.0,800.0|350.0,800.0|400.0,800.0|450.0,800.0|500.0,800.0|550.0,800.0|850.0,800.0|900.0,800.0|950.0,800.0|1350.0,800.0|1400.0,800.0|1450.0,800.0|1500.0,800.0|1550.0,800.0|1600.0,800.0|1650.0,800.0|1700.0,800.0|1750.0,800.0|1800.0,800.0|1850.0,800.0|1900.0,800.0|1950.0,800.0|2000.0,800.0|2050.0,800.0|2100.0,800.0|2150.0,800.0|1350.0,850.0|2100.0,700.0|950.0,850.0|900.0,850.0|850.0,850.0|800.0,850.0|550.0,850.0|500.0,850.0|450.0,850.0|400.0,850.0|350.0,850.0|300.0,850.0|800.0,550.0|800.0,600.0|750.0,600.0|750.0,650.0|800.0,650.0|850.0,650.0|0.0,700.0|50.0,700.0|100.0,700.0|150.0,700.0|200.0,700.0|250.0,700.0|300.0,700.0|350.0,700.0|400.0,700.0|450.0,700.0|500.0,700.0|550.0,700.0|600.0,700.0|650.0,700.0|700.0,700.0|750.0,700.0|800.0,700.0|850.0,700.0|900.0,700.0|950.0,700.0|1000.0,700.0|1050.0,700.0|1100.0,700.0|1150.0,700.0|1200.0,700.0|1250.0,700.0|1300.0,700.0|1350.0,700.0|1400.0,700.0|1450.0,650.0|1500.0,650.0|1550.0,650.0|1600.0,650.0|1650.0,650.0|1700.0,650.0|1750.0,650.0|1800.0,650.0|1850.0,650.0|1900.0,650.0|1950.0,650.0|2000.0,650.0|2050.0,650.0|2100.0,650.0|2150.0,700.0|2150.0,750.0|2200.0,800.0|2250.0,800.0|2300.0,800.0|2350.0,800.0|2500.0,550.0|2550.0,550.0|2600.0,550.0|2650.0,600.0|2450.0,600.0|2400.0,650.0|2400.0,700.0|2400.0,750.0|2650.0,650.0|2650.0,700.0|2650.0,750.0|700.0,650.0|2050.0,600.0|2650.0,1000.0|2600.0,1000.0|2550.0,1000.0|2500.0,1000.0|2450.0,1000.0|2400.0,1000.0|2350.0,1000.0|2300.0,1000.0|2250.0,1000.0|2200.0,1000.0|2150.0,1000.0|2100.0,1000.0|2050.0,1000.0|2350.0,1050.0|2700.0,1050.0|2650.0,1050.0|2600.0,1050.0|2550.0,1050.0|2500.0,1050.0|2450.0,1050.0|2400.0,1050.0|2000.0,1000.0|1950.0,1000.0|1900.0,1000.0|1850.0,1000.0|1850.0,1050.0|1900.0,1050.0|1950.0,1050.0|2000.0,1050.0|2050.0,1050.0|2100.0,1050.0|2150.0,1050.0|2200.0,1050.0|2250.0,1050.0|2300.0,1050.0|1800.0,1000.0|1800.0,1050.0|1750.0,1050.0|1700.0,1050.0|1600.0,1000.0|1650.0,1000.0|1700.0,1000.0|1750.0,1000.0|1650.0,1050.0|1600.0,1050.0
 DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|DIRT|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONE|DIRT|STONE|STONE|STONE|STONEDIRT|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|GRASS|DIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONEDIRT|STONE|STONE|STONE|STONE|STONE|STONE|STONE|PLAYER|ENEMY|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE|STONE
-
-
-
-
-
-
-
-
-
-
-
-
index 144867aa333fc2b15a96babddc1eb04cf3135f3d..611c387b9d426506fb73683354bcfb1dd12e698b 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -21,7 +21,6 @@ class Player(Actor):
     width, height = idle_frames[0].get_size()
 
     colour = (52, 94, 235)
-    jump_strength = 0.9
 
     def __init__(self, pos, collision_layer, collision_mask, can_hurt):
         super().__init__(pos, collision_layer, collision_mask)
@@ -86,6 +85,7 @@ class Player(Actor):
             elif self.direction == -1:
                 self.display = pg.transform.flip(self.idle_frames[math.floor(frame)], True, False)
             else:
+                self.direction = prev_direction
                 if prev_direction == 1:
                     self.display = self.idle_frames[math.floor(frame)]
                 elif prev_direction == -1:
index 4bb65fee4df7ba9c0f8547e72f121467b38adfbb..b36e7e7406a400409d78d1bd5024b08fbaf8f85f 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -25,16 +25,22 @@ def rotate(pos, img, angle, pivot):
     rot_rect = rot_img.get_rect(center=vec)
     return rot_img, rot_rect
 
-camera_offset = pg.Vector2(0,0)
+camera_offset = center.copy()
+
+MAP_WIDTH, MAP_HEIGHT = 10000,10000
 
 
 def get_display_rect(collision_rect):
+    camera_offset.x = max(0, min(camera_offset.x, MAP_WIDTH - SCREEN_WIDTH))
+    camera_offset.y = max(0, min(camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT))
+
     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))
 
 def get_display_point(vec):
+    camera_offset.x = max(0, min(camera_offset.x, MAP_WIDTH - SCREEN_WIDTH))
+    camera_offset.y = max(0, min(camera_offset.y, MAP_HEIGHT - SCREEN_HEIGHT))
     return vec - camera_offset
 
 from Area import Area