From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sun, 10 Jul 2022 04:21:32 +0000 (-0400) Subject: added support for decor in editor X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=3b6e42fe7d58a2dedb07fc82963c4652d53eaf2a;p=Pygame-Jam.git added support for decor in editor --- diff --git a/Block.py b/Block.py index 89bcf03..15b763a 100644 --- 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())) diff --git a/LevelCreator.py b/LevelCreator.py index 920f9ed..e49021a 100644 --- a/LevelCreator.py +++ b/LevelCreator.py @@ -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 index 0000000..f3d24f2 --- /dev/null +++ b/Levels/Level2.txt @@ -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 + + + + + + + + + + + + diff --git a/Player.py b/Player.py index e680210..2848799 100644 --- 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 8daea4d..52ebba9 100644 --- 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 diff --git a/Weapon.py b/Weapon.py index a36395f..d56a9ba 100644 --- 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() diff --git a/World.py b/World.py index e82f2fe..04b7d4e 100644 --- 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))