def modify_health(self, amount, reason):
self.health += amount
if amount < 0:
- self.stun_time = -amount * 50
+ self.stun_time = -amount * 10
self.is_dead(reason)
def attack(self, enemy, weapon):
- self.modify_health(-10,"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:
# if enemy.velocity.x != pg.Vector2(0,0):
# v = enemy.velocity.normalize().x
- self.velocity += pg.Vector2(0.75 * v, -1)
+ self.velocity += pg.Vector2(v, -1)
def push2(self, direction):
- self.velocity += pg.Vector2(0.75 * direction, -1)
+ self.velocity += pg.Vector2(direction, -1)
def move_and_collide(self, pos, vel, delta):
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
class Block:
- width, height = SCREEN_WIDTH*4/5, 50
+ 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")}
+ width, height = textures["PLACEHOLDER"].get_size()
colour = (71, 77, 97)
- def __init__(self, pos, collision_layer):
+ def __init__(self, pos, collision_layer, texture="PLACEHOLDER"):
self.position = pg.Vector2(pos)
self.velocity = pg.Vector2(0,0) # So that we may have moving blocks
collision_layer.add(self)
+ self.texture = self.textures[texture]
+
self.movable = False
def update(self, delta):
- pass # when player "moves", it's actually the blocks
+ pass
def get_collision_rect(self):
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=5)
+ 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()))
self.movable = True
self.dizzy_time = 0
- # self.health = 0
+ 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)
+ 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)
from Enemy import Enemy
from Block import Block
from PhysicsBody import PhysicsBody
+from World import World
from EndScreen import EndScreen
class Game:
def __init__(self):
- self.collision_layer = {"world": set(), "player": set(), "enemy": set(), "pet": set()}
+ self.collision_layer = {"none":set(),"world": set(), "player": set(), "enemy": set(), "pet": set()}
self.player = Player(center, self.collision_layer["player"],
[self.collision_layer["enemy"], self.collision_layer["world"]],
[self.collision_layer["enemy"]])
# self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
+ self.world = World(self.collision_layer)
+
self.enemies = [Enemy((SCREEN_WIDTH *3/ 4, SCREEN_HEIGHT / 2), self.collision_layer["enemy"],
[self.collision_layer["player"], self.collision_layer["world"]])]
- self.blocks = [Block((-0, SCREEN_HEIGHT * 3 / 4), self.collision_layer["world"])]
+
self.scene = EndScreen()
self.level = 1
self.collision_layer["enemy"].remove(enemy)
self.collision_layer["enemy"].add(self.enemies[i])
- for block in self.blocks:
- block.update(delta)
+ self.world.update(delta)
# self.pet.update(delta, self.player, self.camera_pos)
def draw(self, surf):
screen.fill((255, 255, 255))
+ self.world.draw(surf)
for enemy in self.enemies:
enemy.draw(surf)
- for block in self.blocks:
- block.draw(surf)
+
self.player.draw(surf)
from Potion import Potion
from Weapon import Melee
+
class Player(Actor):
scale = 100
- factor = 640/scale
- crop = pg.Rect(179,169, 170, 401)
- idle_frames = [pygame.transform.scale(pg.image.load(path.join("Assets/player/idle", file)).subsurface(pg.Rect(179,169, 170, 401)), (50,100)) for file in listdir("Assets/player/idle")]
+ factor = 640 / scale
+ crop = pg.Rect(179, 169, 170, 401)
+ idle_frames = [
+ pg.transform.scale(pg.image.load(path.join("Assets/player/idle", file)).subsurface(pg.Rect(179, 169, 170, 401)),
+ (50, 100)) for file in listdir("Assets/player/idle")]
width, height = idle_frames[0].get_size()
colour = (52, 94, 235)
gravity = 0.098
friction = 0.7
-
def __init__(self, pos, collision_layer, collision_mask, can_hurt):
super().__init__(pos, collision_layer, collision_mask)
self.initial_position = pg.Vector2(pos)
self.lastValueL = False
self.lastPressedRight = datetime.utcnow()
self.lastValueR = False
- # self.areas = {"body":Area(self.position, pg.Vector2(0, self.height/2),self.width, self.height/2,Actor)}
+ self.areas = {"body": Area(self.position, pg.Vector2(0, self.height / 2), self.width, self.height / 2, Actor),
+ "head": Area(self.position, pg.Vector2(self.width * 1 / 3 * 1 / 2, -2), self.width * 2 / 3, 25,
+ Actor)}
self.potion_cooldown = 0
self.starting_potions = 999
for i in range(self.starting_potions):
self.potion_bag.append(Potion(self))
- self.weapon = Melee(self.position, (-Melee.width/2 + 7, Melee.height/2 + self.height/3 - 8), (-5,Melee.height), self.width,-1)
+ self.weapon = Melee(self.position, (-Melee.width / 2 + 7, Melee.height / 2 + self.height / 3 - 8),
+ (-5, Melee.height), self.width, -1, -25)
self.targets = can_hurt
self.direction = -1
self.state = "IDLE"
self.current_frame = 0
self.display = self.idle_frames[0]
- self.display_offsets = {"weapon":pg.Vector2(0,0)}
+ self.display_offsets = {"weapon": pg.Vector2(0, 0)}
def update(self, delta):
super().update(delta)
# Get and handle input
self.handle_input()
- #if self.potion_cooldown > 0:
- #threading.Thread(Potion.cooldown)
+ # if self.potion_cooldown > 0:
+ # threading.Thread(Potion.cooldown)
if len(self.potion_bag) > 0:
self.potion_bag[0].get_input(self)
if self.velocity.x == 0:
self.direction = 0
else:
- self.direction = math.copysign(1,self.velocity.x)
- self.weapon.update(delta,self.position, self.direction)
+ self.direction = math.copysign(1, self.velocity.x)
+ self.weapon.update(delta, self.position, self.direction)
if self.state == "IDLE":
frame = math.floor(self.current_frame)
# 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)
+ 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)
+ self.display_offsets["weapon"] = pg.Vector2(0, 1)
else:
- self.display_offsets["weapon"] = pg.Vector2(0,0)
+ self.display_offsets["weapon"] = pg.Vector2(0, 0)
self.current_frame = (self.current_frame + 0.1) % len(self.idle_frames)
return self.position - self.initial_position
-
-
def handle_input(self):
pressed = pygame.key.get_pressed()
if pressed[pg.K_w] or pressed[pg.K_UP] or pressed[pg.K_SPACE]:
self.jump()
if pressed[pg.K_a] or pressed[pg.K_LEFT]:
self.move_left()
- if(self.lastValueL == False):
+ if (self.lastValueL == False):
timeSincePressed = datetime.utcnow() - self.lastPressedLeft
timeSinceLastDash = datetime.utcnow() - self.lastDash
- if(timeSinceLastDash >= self.dashCooldown): self.dashPossible = True
- else: self.dashPossible = False
- if(timeSincePressed < self.timeBetweenDoublePress and self.dashPossible == True):
- self.move_left(self.dashSpeed) # change this to change how the player dashes (maybe replace with a custom dash function)
+ if (timeSinceLastDash >= self.dashCooldown):
+ self.dashPossible = True
+ else:
+ self.dashPossible = False
+ if (timeSincePressed < self.timeBetweenDoublePress and self.dashPossible == True):
+ self.move_left(
+ self.dashSpeed) # change this to change how the player dashes (maybe replace with a custom dash function)
self.dashPossible = False
self.lastDash = datetime.utcnow()
- self.lastPressedLeft = datetime.utcnow()
-
+ self.lastPressedLeft = datetime.utcnow()
+
if pressed[pg.K_d] or pressed[pg.K_RIGHT]:
self.move_right()
- if(self.lastValueR == False):
+ if (self.lastValueR == False):
timeSincePressed = datetime.utcnow() - self.lastPressedRight
timeSinceLastDash = datetime.utcnow() - self.lastDash
- if(timeSinceLastDash >= self.dashCooldown): self.dashPossible = True
- else: self.dashPossible = False
- if(timeSincePressed < self.timeBetweenDoublePress and self.dashPossible == True):
+ if (timeSinceLastDash >= self.dashCooldown):
+ self.dashPossible = True
+ else:
+ self.dashPossible = False
+ if (timeSincePressed < self.timeBetweenDoublePress and self.dashPossible == True):
self.lastDash = datetime.utcnow()
self.dashPossible = False
- self.move_right(self.dashSpeed) # change this to change how the player dashes (maybe replace with a custom dash function)
- self.lastPressedRight = datetime.utcnow()
-
+ self.move_right(
+ self.dashSpeed) # change this to change how the player dashes (maybe replace with a custom dash function)
+ self.lastPressedRight = datetime.utcnow()
+
self.lastValueL = pressed[pg.K_a] or pressed[pg.K_LEFT]
self.lastValueR = pressed[pg.K_d] or pressed[pg.K_RIGHT]
mouse_pressed = pg.mouse.get_pressed(3)
- if mouse_pressed[0]: # LMB
+ if mouse_pressed[0]: # LMB
if not self.weapon.attacking:
self.weapon.swing()
for mask in self.targets:
if self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()):
enemy.attack(self, self.weapon)
-
-
def draw(self, surf):
self.weapon.draw(surf, self.display_offsets["weapon"])
- # super().draw(surf)
surf.blit(self.display, get_display_rect(self.get_collision_rect()))
+ # 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)
# make sure the red part health bar always sits on the left
# sets bar to center of background bar, then subtracts 1/2 of blank space to put it on the left
foreground_rect.center = (
- background_rect.centerx - 1080 * 0.185 * ((1 - self.health * 0.01) / 2), background_rect.centery)
+ background_rect.centerx - 1080 * 0.185 * ((1 - self.health * 0.01) / 2), background_rect.centery)
pg.draw.rect(surf, (54, 54, 54), background_rect)
pg.draw.rect(surf, (255, 0, 0), foreground_rect)
class Melee:
- img = pg.transform.scale(pg.image.load("Assets/SWORD.png"), (40,40))
+ 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()
- def __init__(self, pos, offset, pivot, width,direction):
+ 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.swing_timer = 0
self.attacking = False
+ self.damage = damage
def update(self, delta, pos, direction):
self.position = pg.Vector2(pos)
--- /dev/null
+from Setup import *
+from Block import Block
+
+class World:
+
+ def __init__(self, collision_layer):
+ self.collision_layer = collision_layer
+ self.blocks = []
+ self.add_world()
+
+ def add_world(self):
+ for i in range(25):
+ self.blocks.append(Block((i * Block.width,SCREEN_HEIGHT*3/4),self.collision_layer["world"],"GRASS"))
+ self.blocks.append(Block((i * Block.width,SCREEN_HEIGHT*3/4 + Block.height),self.collision_layer["world"],"DIRT"))
+ if random.random() < 0.5:
+ self.blocks.append(
+ Block((i * Block.width, SCREEN_HEIGHT * 3 / 4 + Block.height * 2), self.collision_layer["world"],
+ "STONE"))
+ else:
+ self.blocks.append(
+ Block((i * Block.width, SCREEN_HEIGHT * 3 / 4 + Block.height * 2), self.collision_layer["world"],
+ "DIRT"))
+ self.blocks.append(Block((i * Block.width,SCREEN_HEIGHT*3/4 + Block.height * 3),self.collision_layer["world"],"STONE"))
+ self.blocks.append(Block((i * Block.width,SCREEN_HEIGHT*3/4 + Block.height * 4),self.collision_layer["world"],"STONE"))
+
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -1),self.collision_layer["none"],"TREEBARK"))
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -2),self.collision_layer["none"],"TREEBARK"))
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"TREEBARK"))
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"TREEBARK"))
+
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"LEAFS"))
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"LEAFS"))
+ self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -5),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 10,SCREEN_HEIGHT*3/4 + Block.height * -6),self.collision_layer["none"],"LEAFS"))
+
+ self.blocks.append(Block((Block.width * 9,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"LEAFS"))
+ self.blocks.append(Block((Block.width * 9,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"LEAFS"))
+ self.blocks.append(Block((Block.width * 9,SCREEN_HEIGHT*3/4 + Block.height * -5),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 9,SCREEN_HEIGHT*3/4 + Block.height * -6),self.collision_layer["none"],"LEAFS"))
+
+ self.blocks.append(Block((Block.width * 11,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"LEAFS"))
+ self.blocks.append(Block((Block.width * 11,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"LEAF"))
+ self.blocks.append(Block((Block.width * 11,SCREEN_HEIGHT*3/4 + Block.height * -5),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 11,SCREEN_HEIGHT*3/4 + Block.height * -6),self.collision_layer["none"],"LEAFS"))
+
+
+ # self.blocks.append(Block((Block.width * 12,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 12,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 12,SCREEN_HEIGHT*3/4 + Block.height * -5),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 8,SCREEN_HEIGHT*3/4 + Block.height * -3),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 8,SCREEN_HEIGHT*3/4 + Block.height * -4),self.collision_layer["none"],"LEAFS"))
+ # self.blocks.append(Block((Block.width * 8,SCREEN_HEIGHT*3/4 + Block.height * -5),self.collision_layer["none"],"LEAFS"))
+
+
+ def update(self, delta):
+ for block in self.blocks:
+ block.update(delta)
+
+ def draw(self, surf):
+ for block in self.blocks:
+ block.draw(surf)
case 1:
scene = Game()
old_level = level
-
scene.update(delta)
scene.draw(screen)