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()))
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)],
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"):
--- /dev/null
+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
+
+
+
+
+
+
+
+
+
+
+
+
# 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)
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)
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)
+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
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()
from Setup import *
from Block import Block
-from os import path
+from os import path, listdir
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
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))