its very fun so pull now.
if amount < 0:
self.stun_time = -amount * 50
self.is_dead(reason)
-
+ def attack(self, enemy, weapon):
+ self.modify_health(-10,"enemy")
+ self.push(enemy)
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
self.velocity.x = customSpeed
def push(self, enemy):
- v = pg.Vector2(0,0)
- if enemy.velocity.x != v:
- v = enemy.velocity.normalize().x
+ v = enemy.weapon.direction
+ # if enemy.velocity.x != pg.Vector2(0,0):
+ # v = enemy.velocity.normalize().x
- self.velocity += pg.Vector2(v, -1)
+ self.velocity += pg.Vector2(0.5 * v, -1)
def move_and_collide(self, pos, vel, delta):
pos.x += vel.x * delta
if area.is_colliding(thing):
area.signal(thing)
if collision_rect.colliderect(thing.get_collision_rect()):
- # print(thing, pos, vel, thing.position, thing.velocity)
if vel.y > 0:
pos.y = thing.position.y - self.height
vel.y = min(vel.y, 0)
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,-5), self.width * 2/3, 25, Player, self.knockout)}
+ 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.dizzy_time = 0
+ # self.health = 0
+
self.weapon = Melee(self.position, (-Melee.width/2, Melee.height/2), (0, Melee.height), self.width,-1)
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.8 + self.width + target.width)
- if not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()):
+ if random.random() < 2.25/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)
self.dizzy_time -= delta
# Deals with collision and applying velocity
self.position, self.velocity = self.move_and_collide(self.position.copy(), self.velocity.copy(), delta)
- self.weapon.update(delta,self.position, math.copysign(1,self.velocity.x))
+ if self.velocity.x == 0:
+ direction = 0
+ else:
+ direction = math.copysign(1,self.velocity.x)
+ self.weapon.update(delta,self.position, direction)
def knockout(self, node):
- self.dizzy_time = 2500
- self.modify_health(-50, None)
+ self.dizzy_time = 100
+ self.modify_health(-25, None)
node.on_ground = True
node.jump()
# self.crouch(1000)
self.collision_layer = {"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.collision_layer["world"]],
+ [self.collision_layer["enemy"]])
# self.pet = Pet(center, self.collision_layer["pet"], [self.collision_layer["world"]])
self.enemies = [Enemy((SCREEN_WIDTH / 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.blocks = [Block((-0, SCREEN_HEIGHT * 3 / 4), self.collision_layer["world"])]
self.scene = EndScreen()
self.level = 1
from Setup import *
from Block import Block
+from Function.createText import createText
class PhysicsBody:
speed = 0.2
def __init__(self, pos, vel, width, height, colour, collision_layer, collision_mask):
self.position = pg.Vector2(pos)
self.velocity = pg.Vector2(vel)
- self.width, self.height = width, height
+ self.width, self.height = height, width
self.colour = colour
self.on_ground = False
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)
+ 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(0.5 * v, -1)
def move_and_collide(self, pos, vel, delta):
pos.x += vel.x * delta
collision_rect = self.get_collision_rect(pos)
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)
+
from Actors import Actor
from datetime import datetime, timedelta
from Potion import Potion
+from Weapon import Melee
class Player(Actor):
width, height = 25, 50
gravity = 0.098
friction = 0.7
- def __init__(self, pos, collision_layer, collision_mask):
+ def __init__(self, pos, collision_layer, collision_mask, can_hurt):
super().__init__(pos, collision_layer, collision_mask)
self.initial_position = pg.Vector2(pos)
self.dashCooldown = timedelta(seconds=2, microseconds=500000)
for i in range(self.starting_potions):
self.potion_bag.append(Potion(self))
+ self.weapon = Melee(self.position, (-Melee.width/2, Melee.height/2), (0, Melee.height), self.width,-1)
+ self.targets = can_hurt
+
def update(self, delta):
super().update(delta)
# 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
+ else:
+ direction = math.copysign(1,self.velocity.x)
+ self.weapon.update(delta,self.position, direction)
+
return self.position - self.initial_position
self.lastValueL = pressed[pg.K_a] or pressed[pg.K_LEFT]
self.lastValueR = pressed[pg.K_d] or pressed[pg.K_RIGHT]
- def attack(self, enemy, weapon):
- self.modify_health(-10,"enemy")
- self.push(enemy)
+ mouse_pressed = pg.mouse.get_pressed(3)
+ if mouse_pressed[0]: # LMB
+ if not self.weapon.attacking:
+ self.weapon.swing()
+ for mask in self.targets:
+ for enemy in mask:
+ if self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()):
+ enemy.attack(self, self.weapon)
+
+
def draw(self, surf):
+ self.weapon.draw(surf)
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)
self.player = player
def get_input(self, player):
- pressed_key = pygame.key.get_pressed()
+ pressed_key = pg.key.get_pressed()
if pressed_key[pg.K_1] and player.potion_cooldown == 0:
self.consume_potion(player)
import pygame as pg
import math
+import random
-import pygame.transform
-
-from Area import Area
pg.init()
width, height = collision_rect.w, collision_rect.h
return pg.Rect(pos - camera_offset, (width, height))
# return pg.Rect(pos, (width, height))
+
+from Area import Area
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)
- self.direction = direction
+ if direction != 0:
+ self.direction = direction
if self.direction == -1:
angle = 25 * (math.sin(math.radians(self.swing_timer)))
delta = 1000//fps
is_running = True
-scene = Menu()
-# scene = Game()
+# scene = Menu()
+scene = Game()
old_level = 0
level = 1