]> Skullheadx's Git Forge - Pygame-Jam.git/commitdiff
added support for decor in editor
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sun, 10 Jul 2022 04:21:32 +0000 (00:21 -0400)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Sun, 10 Jul 2022 04:21:32 +0000 (00:21 -0400)
Block.py
LevelCreator.py
Levels/Level2.txt [new file with mode: 0644]
Player.py
TODO
Weapon.py
World.py

index 89bcf037c54a043d0bc1d671f375823edc1279f2..15b763a991cabcec68300111198b7619d34571f3 100644 (file)
--- a/Block.py
+++ b/Block.py
@@ -24,5 +24,5 @@ class Block:
         return pg.Rect(self.position, (self.width, self.height))
 
     def draw(self, surf):
-        pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=3)
+        pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=3)
         surf.blit(self.texture, get_display_rect(self.get_collision_rect()))
index 920f9ed31f28c814dac144f3b54022d404061fe5..e49021ac929fdde06f5a9c2a8decabb7ca6a3d9a 100644 (file)
@@ -12,6 +12,8 @@ class LevelCreator:
     canvas_layers = 5
     textures = [file[:file.index(".")] for file in listdir("Assets/world/blocks")]
     textures.append("NONE")
+    for file in listdir("Assets/world/decor"):
+        textures.append(file[:file.index(".")])
 
     def __init__(self):
         self.blocks = {"none": [[] for _ in range(self.canvas_layers)],
@@ -328,6 +330,9 @@ class EditorBlock:
     textures = {file[:file.index(".")]: pg.transform.scale(
         pg.image.load(path.join("Assets/world/blocks", file)), (50, 50)) for
         file in listdir("Assets/world/blocks")}
+    for file in listdir("Assets/world/decor"):
+        textures[file[:file.index(".")]] = pg.transform.scale(
+        pg.image.load(path.join("Assets/world/decor", file)), (50, 50))
     width, height = textures["PLACEHOLDER"].get_size()
 
     def __init__(self, pos, collision_layer, texture="PLACEHOLDER"):
diff --git a/Levels/Level2.txt b/Levels/Level2.txt
new file mode 100644 (file)
index 0000000..f3d24f2
--- /dev/null
@@ -0,0 +1,15 @@
+world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world
+900.0,150.0|950.0,150.0|900.0,200.0|950.0,200.0|850.0,250.0|800.0,250.0|750.0,250.0|700.0,250.0|650.0,250.0|600.0,250.0|550.0,250.0|500.0,250.0|450.0,250.0|400.0,250.0|350.0,250.0|300.0,250.0|250.0,250.0|200.0,250.0|150.0,250.0|100.0,250.0|50.0,250.0|0.0,250.0|150.0,200.0
+PURPLE_CRYSTAL|PURPLE_CRYSTAL|STONEDIRT|STONEDIRT|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLAYER
+
+
+
+
+
+
+
+
+
+
+
+
index e68021030741db005ce156707bad92e56eee6a22..2848799f4d53606e8b8da0ad6aa3e521f11d29dc 100644 (file)
--- a/Player.py
+++ b/Player.py
@@ -86,7 +86,7 @@ class Player(Actor):
         # else:
         #     self.direction = math.copysign(1, self.velocity.x)
         self.direction = math.copysign(1, pg.mouse.get_pos()[0] - get_display_point(self.position).x)
-        self.weapon.update(delta, self.position, self.direction)
+        self.weapon.update(delta, self.position, -self.direction)
 
         if self.state == "IDLE":
             self.display_offsets["player"] = pg.Vector2(0,0)
@@ -104,12 +104,10 @@ class Player(Actor):
                     self.display = pg.transform.flip(self.idle_frames[math.floor(frame)], True, False)
             # 1 - 10 up, 11 down by 1, 12 - 18 down by 2, 19-20 down 1 FIX THIS
             frame += 1
-            if 1 < frame < 10:
-                self.display_offsets["weapon"] = pg.Vector2(0, 2)
-            elif frame == 11 or frame == 19 or frame == 20:
-                self.display_offsets["weapon"] = pg.Vector2(0, 1)
+            if 3 < frame < 12:
+                self.display_offsets["weapon"] = pg.Vector2( 3, -2)
             else:
-                self.display_offsets["weapon"] = pg.Vector2(0, 0)
+                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)
@@ -188,7 +186,12 @@ class Player(Actor):
 
 
     def draw(self, surf):
-        # self.weapon.draw(surf, self.display_offsets["weapon"])
+        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"])
+            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(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)
diff --git a/TODO b/TODO
index 8daea4d50628c1aca0ea58986ff940a2de7ef267..52ebba9e01efcb72f53eec8e187d7d7b8cf83c6f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,10 @@
+IMPORTANT:
+- fix swing animation where u can start swing before animation ends
+- camera
+- weapon hitbox
+- physics for ragdolls
+
+
 Gameplay:
 - Make levels
 - Add save game functionality
index a36395fdcfb3c63aad3848f9b4f2c47b9774c7eb..d56a9baebe286ad50d09ef426ce83f91f4a8fbb0 100644 (file)
--- a/Weapon.py
+++ b/Weapon.py
@@ -4,6 +4,64 @@ from Setup import *
 
 
 class Melee:
+    img = pg.transform.scale(pg.image.load("Assets/SWORD.png"), (50, 50))
+    img,_ = rotate(pg.Vector2(img.get_rect().topright),img, -30,pg.Vector2(img.get_rect().bottomleft))
+    flipped_img = pg.transform.flip(img,True,False)
+    width,height = img.get_size()
+
+    def __init__(self, pos, offset, pivot, width,direction, damage):
+        self.position = pg.Vector2(pos)
+        self.offset = pg.Vector2(offset)
+        self.pivot = self.position + pg.Vector2(pivot)
+        self.holder_width = width
+
+        self.direction = direction
+
+        self.display = self.img
+        self.display_rect = self.display.get_rect()
+        self.swing_timer = 0
+        self.attacking = False
+
+        self.damage = damage
+
+    def update(self, delta, pos, direction):
+        self.position = pg.Vector2(pos)
+        self.pivot = self.position + self.offset + pg.Vector2(self.width/2, self.height/2)
+        if direction != 0:
+            self.direction = direction
+
+        if self.direction == -1:
+            angle = 25 * (math.sin(math.radians(self.swing_timer)))
+            self.display, self.display_rect = rotate(self.position + self.offset, self.img, angle,self.pivot)
+        elif self.direction == 1:
+            angle = -25 * (math.sin(math.radians(self.swing_timer)))
+            self.display, self.display_rect = rotate(self.position+ pg.Vector2(self.holder_width,0) + pg.Vector2(-self.offset.x, self.offset.y), self.flipped_img, angle,self.pivot + pg.Vector2(self.holder_width,0))
+
+        self.swing_timer -= delta
+        self.swing_timer = max(self.swing_timer, 0)
+        if self.swing_timer == 0:
+            self.attacking = False
+        else:
+            self.attacking = True
+
+    def get_collision_rect(self):
+        if self.direction == -1:
+            return pg.Rect(self.display_rect.topleft,(self.width, self.height))
+        elif self.direction == 1:
+            return pg.Rect(self.display_rect.topleft,(self.width, self.height))
+
+    def swing(self):
+        if True:
+            if self.swing_timer == 0:
+                self.swing_timer = 360
+
+    def draw(self, surf, display_offset = pg.Vector2(0,0)):
+        surf.blit(self.display, get_display_rect(self.get_collision_rect()).topleft + display_offset)
+        # pg.draw.circle(surf,(255,0,255),get_display_point(self.pivot),3)
+        # pg.draw.circle(surf,(0,255,0),get_display_point(self.position),3)
+
+
+class Sword:
     img = pg.transform.scale(pg.image.load("Assets/SWORD.png"), (40, 40))
     flipped_img = pg.transform.flip(img,True,False)
     width,height = img.get_size()
index e82f2fee97e6b2e2aebdd0c1ebfc9e04e9ed776d..04b7d4ec3819297a135d86223a043f6e828be3b3 100644 (file)
--- a/World.py
+++ b/World.py
@@ -1,6 +1,6 @@
 from Setup import *
 from Block import Block
-from os import path
+from os import path, listdir
 
 
 class World:
@@ -29,6 +29,8 @@ class World:
                     out[1] = (x, y)
                 elif t == "ENEMY":
                     out[0].append((x, y))
+                elif f"{t}.png" in listdir("Assets/world/decor"):
+                    self.blocks.append(Decor((x,y),self.collision_layer["none"],t))
                 else:
                     self.blocks.append(Block((x, y), self.collision_layer[l], t))
         return out
@@ -40,3 +42,20 @@ class World:
     def draw(self, surf):
         for block in self.blocks:
             block.draw(surf)
+
+
+class Decor:
+    textures = dict()
+    for file in listdir("Assets/world/decor"):
+        textures[file[:file.index(".")]] = pg.transform.scale(
+        pg.image.load(path.join("Assets/world/decor", file)), (50, 50))
+    def __init__(self, pos, collision_layer, img):
+        self.position = pg.Vector2(pos)
+        self.img = img
+        collision_layer.add(self)
+
+    def update(self, delta):
+        pass
+
+    def draw(self, surf):
+        surf.blit(self.textures[self.img],get_display_point(self.position))