]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
Fixed Textures + combat
authorSkullheadx <704277@pdsb.net>
Mon, 11 Jul 2022 02:34:41 +0000 (22:34 -0400)
committerSkullheadx <704277@pdsb.net>
Mon, 11 Jul 2022 02:34:41 +0000 (22:34 -0400)
22 files changed:
Actors.py
Assets/player/DUSTCLOUD.gif [new file with mode: 0644]
Assets/unused/LEAF.png [moved from Assets/world/blocks/LEAF.png with 100% similarity]
Assets/unused/LEAFS.png [moved from Assets/world/blocks/LEAFS.png with 100% similarity]
Assets/unused/TREEBARK.png [moved from Assets/world/blocks/TREEBARK.png with 100% similarity]
Assets/world/CLOUD.png [new file with mode: 0644]
Assets/world/SKY.png [new file with mode: 0644]
Assets/world/blocks/CORNERDIRT.png [new file with mode: 0644]
Assets/world/blocks/CORNERGRASS.png [new file with mode: 0644]
Assets/world/blocks/DIRT.png
Assets/world/blocks/GRASS.png
Assets/world/blocks/SIDEDIRT.png [new file with mode: 0644]
Assets/world/blocks/STONE.png
Assets/world/blocks/STONEDIRT.png
Assets/world/decor/PORTAL.gif [new file with mode: 0644]
Enemy.py
Game.py
Levels/Level3.txt [new file with mode: 0644]
PhysicsBody.py
Player.py
Setup.py
main.py

index ddc158e70766db49cf5b2ff988b9c97c870dffdf..52ea841bfe10c8c3b9437bf38ecac81844c7161f 100644 (file)
--- a/Actors.py
+++ b/Actors.py
@@ -2,7 +2,7 @@ from datetime import datetime, timedelta
 import threading
 
 from Setup import *
-from PhysicsBody import PhysicsBody
+from PhysicsBody import PhysicsBody
 from Block import Block
 
 
@@ -52,7 +52,7 @@ class Actor:
         self.stun_time = max(self.stun_time, 0)
         self.invincibility_frames -= delta
         self.invincibility_frames = max(self.invincibility_frames, 0)
-        if self.invincibility_frames == 0:
+        if self.invincibility_frames == 0 and self.on_ground:
             self.attacked = False
 
         for area in self.areas.values():
@@ -83,28 +83,34 @@ class Actor:
             self.stun_time = -amount * 10
         self.is_dead(reason)
 
-    def attack(self, enemy, weapon):
-        self.modify_health(weapon.damage, "enemy")
-        self.push(enemy)
-        self.attacked = True
-        self.invincibility_frames = self.invincibility_time
+    def attack(self, enemy, weapon, direction):
+        if not self.attacked:
+            self.push(direction, 2, -1)
+            self.modify_health(weapon.damage, "enemy")
+            self.attacked = True
+            self.invincibility_frames = self.invincibility_time
 
-    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
+    def follow_target(self, node, follow_range=100000, stop_dist=115):
+        if stop_dist is None:
+            stop_dist = max(self.height, self.width) * 1.5
 
         target = node.position
 
         # So that actor doesn't come up and hug u lol
-        if (self.position - target).length_squared() < pow(stop_dist, 2):
+        distance_between = ((self.position+pg.Vector2(self.width,self.height)/2) - (target+pg.Vector2(node.width,node.height)/2)).length_squared()
+
+        if abs(self.position.x - target.x) < stop_dist:
+            self.velocity.x = 0
+            return
+        if distance_between > follow_range ** 2:
             return
 
-        if target.x < self.position.x:
+        if target.x + node.width < self.position.x:
             self.move_left()
         elif target.x > self.position.x:
             self.move_right()
 
-        if target.y < self.position.y:
+        if not (target.y - node.height/2< self.position.y < target.y + node.height/2):
             self.jump()
 
     def jump(self):
@@ -123,23 +129,20 @@ class Actor:
     def dash_right(self):
         pass
 
-    def move_left(self, customSpeed=speed):
+    def move_left(self, customSpeed=None):
+        if customSpeed is None:
+            customSpeed = self.speed
         if self.stun_time == 0:
             self.velocity.x = -customSpeed
 
-    def move_right(self, customSpeed=speed):
+    def move_right(self, customSpeed=None):
+        if customSpeed is None:
+            customSpeed = self.speed
         if self.stun_time == 0:
             self.velocity.x = customSpeed
 
-    def push(self, enemy):
-        v = enemy.weapon.direction
-        # if enemy.velocity.x != pg.Vector2(0,0):
-        #     v = enemy.velocity.normalize().x
-
-        self.velocity += pg.Vector2(v, -1)
-
-    def push2(self, direction):
-        self.velocity += pg.Vector2(direction, -1)
+    def push(self, direction, strength=1, y=-1):
+        self.velocity += pg.Vector2(direction * strength, y)
 
     def move_and_collide(self, pos, vel, delta):
         pos.x += vel.x * delta
@@ -149,11 +152,11 @@ class Actor:
                 if thing == self:
                     continue
                 if collision_rect.colliderect(thing.get_collision_rect()):
-                    if thing.movable:
-                        if vel.x > 0:
-                            thing.position.x = pos.x + self.width
-                        elif vel.x < 0:
-                            thing.position.x = pos.x - thing.width
+                    if thing.movable:
+                        if vel.x > 0:
+                            thing.position.x = pos.x + self.width
+                        elif vel.x < 0:
+                            thing.position.x = pos.x - thing.width
                     if vel.x > 0:
                         pos.x = thing.position.x - self.width
                         # vel.x = min(vel.x, 0)
@@ -181,7 +184,7 @@ class Actor:
                         self.coyote_time = datetime.utcnow()
                     elif vel.y < 0:
                         pos.y = thing.position.y + thing.height
-                        vel.y = max(vel.y, 0)
+                        vel.y = max(vel.y, 0)
                     # collision_rect = self.get_collision_rect(pos)
         return pos, vel
 
diff --git a/Assets/player/DUSTCLOUD.gif b/Assets/player/DUSTCLOUD.gif
new file mode 100644 (file)
index 0000000..b936052
Binary files /dev/null and b/Assets/player/DUSTCLOUD.gif differ
diff --git a/Assets/world/CLOUD.png b/Assets/world/CLOUD.png
new file mode 100644 (file)
index 0000000..ad92278
Binary files /dev/null and b/Assets/world/CLOUD.png differ
diff --git a/Assets/world/SKY.png b/Assets/world/SKY.png
new file mode 100644 (file)
index 0000000..17aa286
Binary files /dev/null and b/Assets/world/SKY.png differ
diff --git a/Assets/world/blocks/CORNERDIRT.png b/Assets/world/blocks/CORNERDIRT.png
new file mode 100644 (file)
index 0000000..2343ebd
Binary files /dev/null and b/Assets/world/blocks/CORNERDIRT.png differ
diff --git a/Assets/world/blocks/CORNERGRASS.png b/Assets/world/blocks/CORNERGRASS.png
new file mode 100644 (file)
index 0000000..feb8ed3
Binary files /dev/null and b/Assets/world/blocks/CORNERGRASS.png differ
index 49987920899f86e2a3f37908471db392ab82834a..ec7ccf42c2d9172228a838b1dbde9f61de766686 100644 (file)
Binary files a/Assets/world/blocks/DIRT.png and b/Assets/world/blocks/DIRT.png differ
index 4ec4647251a5babfac81e7a54ca5d4fbc48b7672..b25260de47db285ff190a1e8c3d76c50db6c045f 100644 (file)
Binary files a/Assets/world/blocks/GRASS.png and b/Assets/world/blocks/GRASS.png differ
diff --git a/Assets/world/blocks/SIDEDIRT.png b/Assets/world/blocks/SIDEDIRT.png
new file mode 100644 (file)
index 0000000..163e8f8
Binary files /dev/null and b/Assets/world/blocks/SIDEDIRT.png differ
index 7cf51fc0b4d14d68d9e1c64e62a6219a32af101a..aef6c760ecdf69efcdfd99bfbbe518cd5f4b927d 100644 (file)
Binary files a/Assets/world/blocks/STONE.png and b/Assets/world/blocks/STONE.png differ
index 8d253bde2c97f3fa47d48867eb5956794727ea18..4ac1e4bab68a4ddb324065c4a1accfc057cad4ac 100644 (file)
Binary files a/Assets/world/blocks/STONEDIRT.png and b/Assets/world/blocks/STONEDIRT.png differ
diff --git a/Assets/world/decor/PORTAL.gif b/Assets/world/decor/PORTAL.gif
new file mode 100644 (file)
index 0000000..19a8e60
Binary files /dev/null and b/Assets/world/decor/PORTAL.gif differ
index 6dc3c9863d2b74472fd6071fdd04484212977889..157ebed276297fc4f80c11fa8e88f3910757e353 100644 (file)
--- a/Enemy.py
+++ b/Enemy.py
@@ -4,51 +4,59 @@ from Player import Player
 from Actors import Actor
 from Weapon import Melee
 
+
 class Enemy(Actor):
     width, height = 50, 100
     speed = Actor.speed * 0.5
-    jump_strength = Actor.jump_strength * 0.5
+    jump_strength = Actor.jump_strength * 0.5
     colour = (235, 64, 52)
-    
+    friction = 0.9
 
     def __init__(self, pos, collision_layer, collision_mask):
         super().__init__(pos, collision_layer, collision_mask)
 
-        self.areas = {"head":Area(self.position,pg.Vector2(self.width * 1/3 * 1/2,-2), self.width * 2/3, 25, Player, self.knockout)}
-        self.movable = True
+        self.areas = {
+            "head": Area(self.position, pg.Vector2(self.width * 1 / 3 * 1 / 2, -2), self.width * 2 / 3, 25, Player,
+                         self.knockout)}
+        self.movable = False
         self.dizzy_time = 0
 
-        # self.health = 0 # for debugging without getting killed
+        self.direction = -1
 
-        self.weapon = Melee(self.position, (-Melee.width/2 + 7, Melee.height/2 + self.height/3 - 8), (-5,Melee.height), self.width,-1, -10)
+        # self.health = 0 # for debugging without getting killed
 
+        self.weapon = Melee(self.position, (-Melee.width / 2 + 7, Melee.height / 2 + self.height / 3 - 8),
+                            (-5, Melee.height), self.width, -1, -10)
 
     def update(self, delta, target=None):
         super().update(delta)
-        if target is not None and self.dizzy_time == 0:
-            self.follow_target(target,stop_dist=self.weapon.width * 0.99)
-            if random.random() < 4.5/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
-                self.weapon.swing()
-                target.attack(self, self.weapon)
+        if not self.attacked and target is not None and self.dizzy_time == 0:
+            self.follow_target(target)
+            if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
+                target.attack(self, self.weapon, self.direction)
+                print('attack')
         self.dizzy_time -= delta
-        self.dizzy_time = max(0,self.dizzy_time)
-
+        self.dizzy_time = max(0, self.dizzy_time)
 
         # Deals with collision and applying velocity
         self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
 
         if self.velocity.x == 0:
-            direction = 0
+            self.direction = 0
         else:
-            direction = math.copysign(1,self.velocity.x)
-        self.weapon.update(delta,self.position, direction)
+            self.direction = math.copysign(1, self.velocity.x)
+        self.weapon.update(delta, self.position, self.direction)
+
+        # print(self.velocity)
 
     def knockout(self, node):
         self.dizzy_time = 100
         self.modify_health(-25, None)
-        node.push2(math.copysign(1,self.velocity.x))
+        node.on_ground = False
+        node.push(math.copysign(1, node.velocity.x), 0.25, -2.25)
         # self.crouch(1000)
 
     def draw(self, surf):
         self.weapon.draw(surf)
         super(Enemy, self).draw(surf)
+        pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2)
diff --git a/Game.py b/Game.py
index bac0cb13e73e7cc5229105f715945c41d1ba0b83..3068fb4234180366173bb56cfc128522cf5753cf 100644 (file)
--- a/Game.py
+++ b/Game.py
@@ -68,13 +68,13 @@ class Game:
         # self.pet.update(delta, self.player, self.camera_pos)
 
     def draw(self, surf):
-        screen.fill((0, 191, 255))
-
+        # screen.fill((0, 191, 255))
+        # screen.fill((255,255,255))
+        sky = pg.image.load("Assets/world/SKY.png")
+        surf.blit(sky,(0,0))
         self.Transition.draw(surf, self.player.position, [40, -250], 120, 625)
 
-        # 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)
diff --git a/Levels/Level3.txt b/Levels/Level3.txt
new file mode 100644 (file)
index 0000000..0bbc3fe
--- /dev/null
@@ -0,0 +1,15 @@
+none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|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
+1150.0,0.0|1100.0,0.0|1100.0,50.0|1150.0,50.0|1150.0,100.0|1100.0,100.0|1100.0,150.0|1150.0,150.0|1150.0,200.0|1150.0,300.0|1150.0,250.0|1100.0,200.0|1100.0,250.0|1100.0,300.0|1100.0,550.0|1100.0,500.0|1100.0,450.0|1100.0,400.0|1100.0,350.0|1150.0,350.0|1150.0,400.0|1150.0,450.0|1150.0,500.0|1150.0,550.0|1150.0,600.0|1150.0,700.0|1150.0,650.0|1100.0,600.0|1100.0,650.0|1100.0,700.0|150.0,650.0|300.0,650.0|550.0,650.0|800.0,650.0|1000.0,850.0|1150.0,750.0|1100.0,750.0|1100.0,800.0|1150.0,800.0|1150.0,850.0|1100.0,850.0|1050.0,850.0|1050.0,800.0|1000.0,800.0|950.0,800.0|950.0,850.0|900.0,850.0|900.0,800.0|850.0,850.0|800.0,850.0|750.0,850.0|700.0,850.0|600.0,800.0|550.0,800.0|500.0,800.0|450.0,800.0|400.0,800.0|350.0,800.0|300.0,800.0|250.0,800.0|200.0,800.0|150.0,800.0|100.0,800.0|50.0,800.0|0.0,800.0|0.0,850.0|50.0,850.0|100.0,850.0|150.0,850.0|200.0,850.0|250.0,850.0|300.0,850.0|350.0,850.0|400.0,850.0|450.0,850.0|500.0,850.0|550.0,850.0|600.0,850.0|650.0,850.0|650.0,800.0|700.0,800.0|750.0,800.0|800.0,800.0|850.0,800.0|0.0,700.0|1000.0,700.0|0.0,650.0|0.0,600.0|0.0,550.0|0.0,500.0|0.0,450.0|0.0,400.0|0.0,350.0|0.0,300.0|0.0,250.0|0.0,200.0|0.0,0.0|0.0,50.0|0.0,100.0|0.0,150.0|50.0,0.0|100.0,0.0|150.0,0.0|200.0,0.0|250.0,0.0|300.0,0.0|350.0,0.0|400.0,0.0|450.0,0.0|500.0,0.0|550.0,0.0|600.0,0.0|650.0,0.0|700.0,0.0|750.0,0.0|800.0,0.0|850.0,0.0|900.0,0.0|950.0,0.0|1000.0,0.0|1000.0,50.0|1000.0,100.0|1000.0,150.0|1000.0,200.0|1000.0,250.0|1000.0,300.0|1000.0,350.0|1000.0,400.0|1000.0,450.0|1000.0,500.0|1000.0,550.0|1000.0,600.0|1000.0,650.0|1050.0,0.0|1050.0,50.0|1050.0,100.0|1050.0,150.0|1050.0,200.0|1050.0,250.0|1050.0,300.0|1050.0,350.0|1050.0,400.0|1050.0,450.0|1050.0,500.0|1050.0,550.0|1050.0,600.0|1050.0,650.0|1050.0,700.0|0.0,750.0|1050.0,750.0|1000.0,750.0|950.0,700.0|900.0,700.0|850.0,700.0|800.0,700.0|750.0,700.0|700.0,700.0|650.0,700.0|600.0,700.0|550.0,700.0|500.0,700.0|450.0,700.0|400.0,700.0|350.0,700.0|300.0,700.0|250.0,700.0|200.0,700.0|150.0,700.0|100.0,700.0|50.0,700.0|50.0,750.0|100.0,750.0|150.0,750.0|200.0,750.0|250.0,750.0|300.0,750.0|350.0,750.0|400.0,750.0|450.0,750.0|500.0,750.0|550.0,750.0|600.0,750.0|650.0,750.0|700.0,750.0|750.0,750.0|800.0,750.0|850.0,750.0|900.0,750.0|950.0,750.0
+PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLAYER|ENEMY|ENEMY|ENEMY|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER
+
+
+
+
+
+
+
+
+
+
+
+
index eef9d33e90c727c07627b154a1e1575b6b21c624..2111e2a27f2a799d632bd6ca770c706c8aa15187 100644 (file)
@@ -1,12 +1,12 @@
 from Setup import *
 from Block import Block
 from Function.createText import createText
+from Actors import Actor
+
 
 class PhysicsBody:
-    speed = 0.2
-    jump_strength = 1
-    gravity = 0.098
-    friction = 0.9
+    gravity = Actor.gravity
+    friction = Actor.friction
     invincibility_time = 150
 
     def __init__(self, pos, vel, width, height, colour, collision_layer, collision_mask):
@@ -19,7 +19,7 @@ class PhysicsBody:
 
         self.dead = False
 
-        self.movable =True
+        self.movable = True
         self.attacked = False
         self.invincibility_frames = 0
 
@@ -27,31 +27,26 @@ class PhysicsBody:
         self.collision_layer = collision_layer
         self.collision_mask = collision_mask  # the layer the actor detects collisions against
 
-    def update(self, delta, test=None):
-        self.invincibility_frames -= delta
-        self.invincibility_frames = max(self.invincibility_frames, 0)
-        if self.invincibility_frames == 0:
-            self.attacked = False
-        # Apply friction so the enemy isn't walking on ice
+    def update(self, delta, test=None, test2=None):
         if self.on_ground:
             self.velocity.x *= self.friction
 
-        # Apply gravity
         self.velocity.y += self.gravity
 
+
         self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
-        # print(self.position)
-    def attack(self, enemy, weapon):
-        self.push(enemy)
+
+        if self.on_ground:
+            self.attacked = False
+
+    def attack(self, enemy, weapon, direction):
+        self.push(direction, 2, -1)
         self.attacked = True
         self.invincibility_frames = self.invincibility_time
 
-    def push(self, enemy):
-        v = enemy.weapon.direction
-        # if enemy.velocity.x != pg.Vector2(0,0):
-        #     v = enemy.velocity.normalize().x
+    def push(self, direction, strength=1, y=-1):
+        self.velocity += pg.Vector2(direction * strength, y)
 
-        self.velocity += pg.Vector2(0.5 * v, -1)
     def move_and_collide(self, pos, vel, delta):
         pos.x += vel.x * delta
         collision_rect = self.get_collision_rect(pos)
@@ -60,18 +55,19 @@ class PhysicsBody:
                 if thing == self:
                     continue
                 if collision_rect.colliderect(thing.get_collision_rect()):
-                    if thing.movable:
-                        if vel.x > 0:
-                            thing.position.x = pos.x + self.width
-                        elif vel.x < 0:
-                            thing.position.x = pos.x - thing.width
+                    if thing.movable:
+                        if vel.x > 0:
+                            thing.position.x = pos.x + self.width
+                        elif vel.x < 0:
+                            thing.position.x = pos.x - thing.width
                     if vel.x > 0:
                         pos.x = thing.position.x - self.width
-                        vel.x = min(vel.x, 0)
+                        vel.x = min(vel.x, 0)
                     elif vel.x < 0:
                         pos.x = thing.position.x + thing.width
-                        vel.x = max(vel.x, 0)
+                        vel.x = max(vel.x, 0)
                     collision_rect = self.get_collision_rect(pos)
+
         self.on_ground = False
         pos.y += vel.y * delta
         collision_rect = self.get_collision_rect(pos)
@@ -86,8 +82,8 @@ class PhysicsBody:
                         self.on_ground = True
                     elif vel.y < 0:
                         pos.y = thing.position.y + thing.height
-                        vel.y = max(vel.y, 0)
-                    collision_rect = self.get_collision_rect(pos)
+                        vel.y = max(vel.y, 0)
+                    collision_rect = self.get_collision_rect(pos)
         return pos, vel
 
     def get_collision_rect(self, pos=None):
@@ -98,4 +94,3 @@ class PhysicsBody:
     def draw(self, surf):
         # print(self.position, self.velocity)
         pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8)
-
index 726156da432e2d3bfc18e80d164a1e607fc2d508..5fb029d8a3015fd0276000079ec98fd72596ac25 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -1,5 +1,6 @@
 import pygame.key
 
+import Setup
 from Setup import *
 import time
 from Actors import Actor
@@ -19,7 +20,7 @@ class Player(Actor):
     attack_gif = Image.open("Assets/player/Sword_Slash.gif")
     attack_frames = []
     for i in range(attack_gif.n_frames):
-        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (200,200)))
+        attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (200, 200)))
 
     width, height = idle_frames[0].get_size()
 
@@ -46,9 +47,9 @@ class Player(Actor):
         self.starting_potions = 999
         self.potion_bag = [Potion(self)]
         for i in range(self.starting_potions):
-            self.potion_bag.append(Potion(self)) # use one liner
+            self.potion_bag.append(Potion(self))  # use one liner
 
-        self.weapon = Sword(self.position, (0,0), self.width, -1)
+        self.weapon = Sword(self.position, (0, 0), self.width, -1)
         self.targets = can_hurt
 
         self.direction = -1
@@ -56,7 +57,8 @@ class Player(Actor):
         self.state = "IDLE"
         self.current_frame = 0
         self.display = self.idle_frames[0]
-        self.display_offsets = {"weapon": pg.Vector2(0, 0), "player":pg.Vector2(0,0)}
+        self.display_offsets = {"weapon": pg.Vector2(0, 0), "player": pg.Vector2(0, 0)}
+
 
     # def attack(self, enemy, weapon):
     #     super(Player, self).attack(enemy, weapon)
@@ -64,7 +66,6 @@ class Player(Actor):
     #     self.state = "ATTACK"
     #     print('a')
 
-
     def update(self, delta):
         super().update(delta)
 
@@ -89,7 +90,7 @@ class Player(Actor):
         self.weapon.update(delta, self.position, self.direction)
 
         if self.state == "IDLE":
-            self.display_offsets["player"] = pg.Vector2(0,0)
+            self.display_offsets["player"] = pg.Vector2(0, 0)
 
             frame = math.floor(self.current_frame)
             if self.direction == 1:
@@ -105,29 +106,29 @@ class Player(Actor):
             # 1 - 10 up, 11 down by 1, 12 - 18 down by 2, 19-20 down 1 FIX THIS
             frame += 1
             if 3 < frame < 12:
-                self.display_offsets["weapon"] = pg.Vector2( 3, -2)
+                self.display_offsets["weapon"] = pg.Vector2(3, -2)
             else:
-                self.display_offsets["weapon"] = pg.Vector2( 3, -5)
+                self.display_offsets["weapon"] = pg.Vector2(3, -5)
             self.current_frame = (self.current_frame + 0.1) % len(self.idle_frames)
         elif self.state == "ATTACK":
             frame = math.floor(self.current_frame)
             if self.direction == 1:
                 self.display = self.attack_frames[math.floor(frame)]
-                self.display_offsets["player"] = pg.Vector2(-50,-50)
+                self.display_offsets["player"] = pg.Vector2(-50, -50)
 
             elif self.direction == -1:
                 self.display = pg.transform.flip(self.attack_frames[math.floor(frame)], True, False)
-                self.display_offsets["player"] = pg.Vector2(-100,-50)
+                self.display_offsets["player"] = pg.Vector2(-100, -50)
 
             else:
                 self.direction = prev_direction
                 if prev_direction == 1:
-                    self.display_offsets["player"] = pg.Vector2(-50,-50)
+                    self.display_offsets["player"] = pg.Vector2(-50, -50)
 
                     self.display = self.attack_frames[math.floor(frame)]
                 elif prev_direction == -1:
                     self.display = pg.transform.flip(self.attack_frames[math.floor(frame)], True, False)
-                    self.display_offsets["player"] = pg.Vector2(-100,-50)
+                    self.display_offsets["player"] = pg.Vector2(-100, -50)
 
             self.current_frame += 0.4
             if math.floor(self.current_frame) == self.attack_gif.n_frames:
@@ -178,29 +179,37 @@ class Player(Actor):
             if self.state != "ATTACK":
                 self.state = "ATTACK"
                 self.current_frame = 0
-            elif self.state == "ATTACK":
-                if math.floor(self.current_frame) > 2:
-                    for mask in self.targets:
-                        for enemy in mask:
-                            if not enemy.attacked and self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()):
-                                enemy.attack(self, self.weapon)
+        if self.state == "ATTACK":
+            if 12 > math.floor(self.current_frame) > 6:
+                for mask in self.targets:
+                    for enemy in mask:
+                        # if not enemy.attacked and self.weapon.get_collision_rect().colliderect(
+                        #         enemy.get_collision_rect()):
 
+                        if not enemy.attacked and get_display_rect(self.weapon.get_collision_rect()).colliderect(
+                                get_display_rect(enemy.get_collision_rect())):
+                            enemy.attack(self, self.weapon, self.direction)
 
     def draw(self, surf):
         if self.state == "IDLE":
             # self.weapon.draw(surf, self.display_offsets["weapon"])
             if self.direction == 1:
-                surf.blit(pg.transform.flip(self.weapon.img, True, True), get_display_rect(self.get_collision_rect()).topleft+pg.Vector2(-25,55) + self.display_offsets["weapon"])
+                surf.blit(pg.transform.flip(self.weapon.img, True, True),
+                          get_display_rect(self.get_collision_rect()).topleft + pg.Vector2(-25, 55) +
+                          self.display_offsets["weapon"])
             elif self.direction == -1:
-                surf.blit(pg.transform.flip(self.weapon.img, False, True), get_display_rect(self.get_collision_rect()).topleft+pg.Vector2(0,55) + self.display_offsets["weapon"])
+                surf.blit(pg.transform.flip(self.weapon.img, False, True),
+                          get_display_rect(self.get_collision_rect()).topleft + pg.Vector2(0, 55) +
+                          self.display_offsets["weapon"])
         surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + self.display_offsets["player"])
         # 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, (255,0,0),get_display_rect(self.weapon.get_collision_rect()),width=3)
-        # pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8)
+        pg.draw.rect(surf, (255, 0, 0), get_display_rect(self.weapon.get_collision_rect()), width=3)
 
+        pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2)
 
+        # 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
@@ -220,12 +229,8 @@ class Player(Actor):
         # text_rect = current_health_display.get_rect(center=background_rect.center)
         # surf.blit(current_health_display, text_rect)
 
-
-
     def potion_cooldown_timer(self):
         while self.potion_cooldown > 0:
             self.potion_cooldown -= 1
-            print(self.potion_cooldown)
+            print(self.potion_cooldown)
             time.sleep(1)
-
-    
index b9e8cb6f07e784b37619e7172927aa6646ea1698..a0bc8d88c1e0a2abd2421ef3d14fd97a9acc738f 100644 (file)
--- a/Setup.py
+++ b/Setup.py
@@ -6,7 +6,10 @@ from os import listdir, path
 
 pg.init()
 
+display_info = pg.display.Info()
+
 SCREEN_WIDTH, SCREEN_HEIGHT = 1080, 640
+# SCREEN_WIDTH, SCREEN_HEIGHT = display_info.current_w, display_info.current_h-10
 dimensions = (SCREEN_WIDTH, SCREEN_HEIGHT)
 center = pg.Vector2(dimensions) / 2
 
@@ -55,4 +58,4 @@ def pil_to_game(img):
 
 def get_gif_frame(img, frame):
     img.seek(frame)
-    return img.convert(FORMAT)
\ No newline at end of file
+    return img.convert(FORMAT)
diff --git a/main.py b/main.py
index 1475966f819a766db857a63cf1a0e77eb56cc37c..ec8eb8511090ad751c694f80d2f3d67a74c79dd3 100644 (file)
--- a/main.py
+++ b/main.py
@@ -14,7 +14,7 @@ is_running = True
 # scene = TransitionScene()
 scene = DevLevelSelect()
 old_level = 0
-level = 1
+level =1
 next_level = 0
 
 while is_running:
@@ -44,6 +44,8 @@ while is_running:
                 scene = Game(1)
             case 2:
                 scene = Game(2)
+            case 3:
+                scene = Game(3)
         old_level = level
 
     scene.update(delta)