From: Skullheadx <704277@pdsb.net> Date: Mon, 11 Jul 2022 02:34:41 +0000 (-0400) Subject: Fixed Textures + combat X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.css?a=commitdiff_plain;h=86e11fdd25ca557a75e7f766800d71a3108336cb;p=Pygame-Jam.git Fixed Textures + combat --- diff --git a/Actors.py b/Actors.py index ddc158e..52ea841 100644 --- a/Actors.py +++ b/Actors.py @@ -2,7 +2,7 @@ from datetime import datetime, timedelta import threading from Setup import * -from PhysicsBody import PhysicsBody +# from PhysicsBody import PhysicsBody from Block import Block @@ -52,7 +52,7 @@ class Actor: self.stun_time = max(self.stun_time, 0) self.invincibility_frames -= delta self.invincibility_frames = max(self.invincibility_frames, 0) - if self.invincibility_frames == 0: + if self.invincibility_frames == 0 and self.on_ground: self.attacked = False for area in self.areas.values(): @@ -83,28 +83,34 @@ class Actor: self.stun_time = -amount * 10 self.is_dead(reason) - def attack(self, enemy, weapon): - self.modify_health(weapon.damage, "enemy") - self.push(enemy) - self.attacked = True - self.invincibility_frames = self.invincibility_time + def attack(self, enemy, weapon, direction): + if not self.attacked: + self.push(direction, 2, -1) + self.modify_health(weapon.damage, "enemy") + self.attacked = True + self.invincibility_frames = self.invincibility_time - 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 + def follow_target(self, node, follow_range=100000, stop_dist=115): + # if stop_dist is None: + # stop_dist = max(self.height, self.width) * 1.5 target = node.position # So that actor doesn't come up and hug u lol - if (self.position - target).length_squared() < pow(stop_dist, 2): + distance_between = ((self.position+pg.Vector2(self.width,self.height)/2) - (target+pg.Vector2(node.width,node.height)/2)).length_squared() + + if abs(self.position.x - target.x) < stop_dist: + self.velocity.x = 0 + return + if distance_between > follow_range ** 2: return - if target.x < self.position.x: + if target.x + node.width < self.position.x: self.move_left() elif target.x > self.position.x: self.move_right() - if target.y < self.position.y: + if not (target.y - node.height/2< self.position.y < target.y + node.height/2): self.jump() def jump(self): @@ -123,23 +129,20 @@ class Actor: def dash_right(self): pass - def move_left(self, customSpeed=speed): + def move_left(self, customSpeed=None): + if customSpeed is None: + customSpeed = self.speed if self.stun_time == 0: self.velocity.x = -customSpeed - def move_right(self, customSpeed=speed): + def move_right(self, customSpeed=None): + if customSpeed is None: + customSpeed = self.speed if self.stun_time == 0: self.velocity.x = customSpeed - 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(v, -1) - - def push2(self, direction): - self.velocity += pg.Vector2(direction, -1) + def push(self, direction, strength=1, y=-1): + self.velocity += pg.Vector2(direction * strength, y) def move_and_collide(self, pos, vel, delta): pos.x += vel.x * delta @@ -149,11 +152,11 @@ class Actor: if thing == self: continue if collision_rect.colliderect(thing.get_collision_rect()): - if thing.movable: - if vel.x > 0: - thing.position.x = pos.x + self.width - elif vel.x < 0: - thing.position.x = pos.x - thing.width + # if thing.movable: + # if vel.x > 0: + # thing.position.x = pos.x + self.width + # elif vel.x < 0: + # thing.position.x = pos.x - thing.width if vel.x > 0: pos.x = thing.position.x - self.width # vel.x = min(vel.x, 0) @@ -181,7 +184,7 @@ class Actor: self.coyote_time = datetime.utcnow() elif vel.y < 0: pos.y = thing.position.y + thing.height - vel.y = max(vel.y, 0) + # vel.y = max(vel.y, 0) # collision_rect = self.get_collision_rect(pos) return pos, vel diff --git a/Assets/player/DUSTCLOUD.gif b/Assets/player/DUSTCLOUD.gif new file mode 100644 index 0000000..b936052 Binary files /dev/null and b/Assets/player/DUSTCLOUD.gif differ diff --git a/Assets/world/blocks/LEAF.png b/Assets/unused/LEAF.png similarity index 100% rename from Assets/world/blocks/LEAF.png rename to Assets/unused/LEAF.png diff --git a/Assets/world/blocks/LEAFS.png b/Assets/unused/LEAFS.png similarity index 100% rename from Assets/world/blocks/LEAFS.png rename to Assets/unused/LEAFS.png diff --git a/Assets/world/blocks/TREEBARK.png b/Assets/unused/TREEBARK.png similarity index 100% rename from Assets/world/blocks/TREEBARK.png rename to Assets/unused/TREEBARK.png diff --git a/Assets/world/CLOUD.png b/Assets/world/CLOUD.png new file mode 100644 index 0000000..ad92278 Binary files /dev/null and b/Assets/world/CLOUD.png differ diff --git a/Assets/world/SKY.png b/Assets/world/SKY.png new file mode 100644 index 0000000..17aa286 Binary files /dev/null and b/Assets/world/SKY.png differ diff --git a/Assets/world/blocks/CORNERDIRT.png b/Assets/world/blocks/CORNERDIRT.png new file mode 100644 index 0000000..2343ebd Binary files /dev/null and b/Assets/world/blocks/CORNERDIRT.png differ diff --git a/Assets/world/blocks/CORNERGRASS.png b/Assets/world/blocks/CORNERGRASS.png new file mode 100644 index 0000000..feb8ed3 Binary files /dev/null and b/Assets/world/blocks/CORNERGRASS.png differ diff --git a/Assets/world/blocks/DIRT.png b/Assets/world/blocks/DIRT.png index 4998792..ec7ccf4 100644 Binary files a/Assets/world/blocks/DIRT.png and b/Assets/world/blocks/DIRT.png differ diff --git a/Assets/world/blocks/GRASS.png b/Assets/world/blocks/GRASS.png index 4ec4647..b25260d 100644 Binary files a/Assets/world/blocks/GRASS.png and b/Assets/world/blocks/GRASS.png differ diff --git a/Assets/world/blocks/SIDEDIRT.png b/Assets/world/blocks/SIDEDIRT.png new file mode 100644 index 0000000..163e8f8 Binary files /dev/null and b/Assets/world/blocks/SIDEDIRT.png differ diff --git a/Assets/world/blocks/STONE.png b/Assets/world/blocks/STONE.png index 7cf51fc..aef6c76 100644 Binary files a/Assets/world/blocks/STONE.png and b/Assets/world/blocks/STONE.png differ diff --git a/Assets/world/blocks/STONEDIRT.png b/Assets/world/blocks/STONEDIRT.png index 8d253bd..4ac1e4b 100644 Binary files a/Assets/world/blocks/STONEDIRT.png and b/Assets/world/blocks/STONEDIRT.png differ diff --git a/Assets/world/decor/PORTAL.gif b/Assets/world/decor/PORTAL.gif new file mode 100644 index 0000000..19a8e60 Binary files /dev/null and b/Assets/world/decor/PORTAL.gif differ diff --git a/Enemy.py b/Enemy.py index 6dc3c98..157ebed 100644 --- a/Enemy.py +++ b/Enemy.py @@ -4,51 +4,59 @@ from Player import Player from Actors import Actor from Weapon import Melee + class Enemy(Actor): width, height = 50, 100 speed = Actor.speed * 0.5 - jump_strength = Actor.jump_strength * 0.5 + # jump_strength = Actor.jump_strength * 0.5 colour = (235, 64, 52) - + friction = 0.9 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,-2), self.width * 2/3, 25, Player, self.knockout)} - self.movable = True + 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 = False self.dizzy_time = 0 - # self.health = 0 # for debugging without getting killed + self.direction = -1 - self.weapon = Melee(self.position, (-Melee.width/2 + 7, Melee.height/2 + self.height/3 - 8), (-5,Melee.height), self.width,-1, -10) + # 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, -10) 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.99) - if random.random() < 4.5/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) + if not self.attacked and target is not None and self.dizzy_time == 0: + self.follow_target(target) + if random.random() < 2/fps and not self.weapon.attacking and self.weapon.get_collision_rect().colliderect(target.get_collision_rect()): + target.attack(self, self.weapon, self.direction) + print('attack') self.dizzy_time -= delta - self.dizzy_time = max(0,self.dizzy_time) - + self.dizzy_time = max(0, self.dizzy_time) # 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 + self.direction = 0 else: - direction = math.copysign(1,self.velocity.x) - self.weapon.update(delta,self.position, direction) + self.direction = math.copysign(1, self.velocity.x) + self.weapon.update(delta, self.position, self.direction) + + # print(self.velocity) def knockout(self, node): self.dizzy_time = 100 self.modify_health(-25, None) - node.push2(math.copysign(1,self.velocity.x)) + node.on_ground = False + node.push(math.copysign(1, node.velocity.x), 0.25, -2.25) # self.crouch(1000) def draw(self, surf): self.weapon.draw(surf) super(Enemy, self).draw(surf) + pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2) diff --git a/Game.py b/Game.py index bac0cb1..3068fb4 100644 --- a/Game.py +++ b/Game.py @@ -68,13 +68,13 @@ class Game: # self.pet.update(delta, self.player, self.camera_pos) def draw(self, surf): - screen.fill((0, 191, 255)) - + # screen.fill((0, 191, 255)) + # screen.fill((255,255,255)) + sky = pg.image.load("Assets/world/SKY.png") + surf.blit(sky,(0,0)) self.Transition.draw(surf, self.player.position, [40, -250], 120, 625) - # screen.fill((255,255,255)) - # sky = pg.image.load("Assets/world/SKY.png") - # surf.blit(sky,(0,0)) + self.world.draw(surf) for enemy in self.enemies: enemy.draw(surf) diff --git a/Levels/Level3.txt b/Levels/Level3.txt new file mode 100644 index 0000000..0bbc3fe --- /dev/null +++ b/Levels/Level3.txt @@ -0,0 +1,15 @@ +none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|none|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world|world +1150.0,0.0|1100.0,0.0|1100.0,50.0|1150.0,50.0|1150.0,100.0|1100.0,100.0|1100.0,150.0|1150.0,150.0|1150.0,200.0|1150.0,300.0|1150.0,250.0|1100.0,200.0|1100.0,250.0|1100.0,300.0|1100.0,550.0|1100.0,500.0|1100.0,450.0|1100.0,400.0|1100.0,350.0|1150.0,350.0|1150.0,400.0|1150.0,450.0|1150.0,500.0|1150.0,550.0|1150.0,600.0|1150.0,700.0|1150.0,650.0|1100.0,600.0|1100.0,650.0|1100.0,700.0|150.0,650.0|300.0,650.0|550.0,650.0|800.0,650.0|1000.0,850.0|1150.0,750.0|1100.0,750.0|1100.0,800.0|1150.0,800.0|1150.0,850.0|1100.0,850.0|1050.0,850.0|1050.0,800.0|1000.0,800.0|950.0,800.0|950.0,850.0|900.0,850.0|900.0,800.0|850.0,850.0|800.0,850.0|750.0,850.0|700.0,850.0|600.0,800.0|550.0,800.0|500.0,800.0|450.0,800.0|400.0,800.0|350.0,800.0|300.0,800.0|250.0,800.0|200.0,800.0|150.0,800.0|100.0,800.0|50.0,800.0|0.0,800.0|0.0,850.0|50.0,850.0|100.0,850.0|150.0,850.0|200.0,850.0|250.0,850.0|300.0,850.0|350.0,850.0|400.0,850.0|450.0,850.0|500.0,850.0|550.0,850.0|600.0,850.0|650.0,850.0|650.0,800.0|700.0,800.0|750.0,800.0|800.0,800.0|850.0,800.0|0.0,700.0|1000.0,700.0|0.0,650.0|0.0,600.0|0.0,550.0|0.0,500.0|0.0,450.0|0.0,400.0|0.0,350.0|0.0,300.0|0.0,250.0|0.0,200.0|0.0,0.0|0.0,50.0|0.0,100.0|0.0,150.0|50.0,0.0|100.0,0.0|150.0,0.0|200.0,0.0|250.0,0.0|300.0,0.0|350.0,0.0|400.0,0.0|450.0,0.0|500.0,0.0|550.0,0.0|600.0,0.0|650.0,0.0|700.0,0.0|750.0,0.0|800.0,0.0|850.0,0.0|900.0,0.0|950.0,0.0|1000.0,0.0|1000.0,50.0|1000.0,100.0|1000.0,150.0|1000.0,200.0|1000.0,250.0|1000.0,300.0|1000.0,350.0|1000.0,400.0|1000.0,450.0|1000.0,500.0|1000.0,550.0|1000.0,600.0|1000.0,650.0|1050.0,0.0|1050.0,50.0|1050.0,100.0|1050.0,150.0|1050.0,200.0|1050.0,250.0|1050.0,300.0|1050.0,350.0|1050.0,400.0|1050.0,450.0|1050.0,500.0|1050.0,550.0|1050.0,600.0|1050.0,650.0|1050.0,700.0|0.0,750.0|1050.0,750.0|1000.0,750.0|950.0,700.0|900.0,700.0|850.0,700.0|800.0,700.0|750.0,700.0|700.0,700.0|650.0,700.0|600.0,700.0|550.0,700.0|500.0,700.0|450.0,700.0|400.0,700.0|350.0,700.0|300.0,700.0|250.0,700.0|200.0,700.0|150.0,700.0|100.0,700.0|50.0,700.0|50.0,750.0|100.0,750.0|150.0,750.0|200.0,750.0|250.0,750.0|300.0,750.0|350.0,750.0|400.0,750.0|450.0,750.0|500.0,750.0|550.0,750.0|600.0,750.0|650.0,750.0|700.0,750.0|750.0,750.0|800.0,750.0|850.0,750.0|900.0,750.0|950.0,750.0 +PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLAYER|ENEMY|ENEMY|ENEMY|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER|PLACEHOLDER + + + + + + + + + + + + diff --git a/PhysicsBody.py b/PhysicsBody.py index eef9d33..2111e2a 100644 --- a/PhysicsBody.py +++ b/PhysicsBody.py @@ -1,12 +1,12 @@ from Setup import * from Block import Block from Function.createText import createText +from Actors import Actor + class PhysicsBody: - speed = 0.2 - jump_strength = 1 - gravity = 0.098 - friction = 0.9 + gravity = Actor.gravity + friction = Actor.friction invincibility_time = 150 def __init__(self, pos, vel, width, height, colour, collision_layer, collision_mask): @@ -19,7 +19,7 @@ class PhysicsBody: self.dead = False - self.movable =True + self.movable = True self.attacked = False self.invincibility_frames = 0 @@ -27,31 +27,26 @@ class PhysicsBody: self.collision_layer = collision_layer self.collision_mask = collision_mask # the layer the actor detects collisions against - def update(self, delta, test=None): - self.invincibility_frames -= delta - self.invincibility_frames = max(self.invincibility_frames, 0) - if self.invincibility_frames == 0: - self.attacked = False - # Apply friction so the enemy isn't walking on ice + def update(self, delta, test=None, test2=None): if self.on_ground: self.velocity.x *= self.friction - # Apply gravity self.velocity.y += self.gravity + 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) + + if self.on_ground: + self.attacked = False + + def attack(self, enemy, weapon, direction): + self.push(direction, 2, -1) self.attacked = True self.invincibility_frames = self.invincibility_time - def push(self, enemy): - v = enemy.weapon.direction - # if enemy.velocity.x != pg.Vector2(0,0): - # v = enemy.velocity.normalize().x + def push(self, direction, strength=1, y=-1): + self.velocity += pg.Vector2(direction * strength, y) - 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) @@ -60,18 +55,19 @@ class PhysicsBody: if thing == self: continue if collision_rect.colliderect(thing.get_collision_rect()): - if thing.movable: - if vel.x > 0: - thing.position.x = pos.x + self.width - elif vel.x < 0: - thing.position.x = pos.x - thing.width + # if thing.movable: + # if vel.x > 0: + # thing.position.x = pos.x + self.width + # elif vel.x < 0: + # 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 pos.y += vel.y * delta collision_rect = self.get_collision_rect(pos) @@ -86,8 +82,8 @@ class PhysicsBody: self.on_ground = True elif vel.y < 0: pos.y = thing.position.y + thing.height - vel.y = max(vel.y, 0) - collision_rect = self.get_collision_rect(pos) + # vel.y = max(vel.y, 0) + # collision_rect = self.get_collision_rect(pos) return pos, vel def get_collision_rect(self, pos=None): @@ -98,4 +94,3 @@ class PhysicsBody: 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) - diff --git a/Player.py b/Player.py index 726156d..5fb029d 100644 --- a/Player.py +++ b/Player.py @@ -1,5 +1,6 @@ import pygame.key +import Setup from Setup import * import time from Actors import Actor @@ -19,7 +20,7 @@ class Player(Actor): attack_gif = Image.open("Assets/player/Sword_Slash.gif") attack_frames = [] for i in range(attack_gif.n_frames): - attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (200,200))) + attack_frames.append(pg.transform.scale(pil_to_game(get_gif_frame(attack_gif, i)), (200, 200))) width, height = idle_frames[0].get_size() @@ -46,9 +47,9 @@ class Player(Actor): self.starting_potions = 999 self.potion_bag = [Potion(self)] for i in range(self.starting_potions): - self.potion_bag.append(Potion(self)) # use one liner + self.potion_bag.append(Potion(self)) # use one liner - self.weapon = Sword(self.position, (0,0), self.width, -1) + self.weapon = Sword(self.position, (0, 0), self.width, -1) self.targets = can_hurt self.direction = -1 @@ -56,7 +57,8 @@ class Player(Actor): self.state = "IDLE" self.current_frame = 0 self.display = self.idle_frames[0] - self.display_offsets = {"weapon": pg.Vector2(0, 0), "player":pg.Vector2(0,0)} + self.display_offsets = {"weapon": pg.Vector2(0, 0), "player": pg.Vector2(0, 0)} + # def attack(self, enemy, weapon): # super(Player, self).attack(enemy, weapon) @@ -64,7 +66,6 @@ class Player(Actor): # self.state = "ATTACK" # print('a') - def update(self, delta): super().update(delta) @@ -89,7 +90,7 @@ class Player(Actor): self.weapon.update(delta, self.position, self.direction) if self.state == "IDLE": - self.display_offsets["player"] = pg.Vector2(0,0) + self.display_offsets["player"] = pg.Vector2(0, 0) frame = math.floor(self.current_frame) if self.direction == 1: @@ -105,29 +106,29 @@ class Player(Actor): # 1 - 10 up, 11 down by 1, 12 - 18 down by 2, 19-20 down 1 FIX THIS frame += 1 if 3 < frame < 12: - self.display_offsets["weapon"] = pg.Vector2( 3, -2) + self.display_offsets["weapon"] = pg.Vector2(3, -2) else: - self.display_offsets["weapon"] = pg.Vector2( 3, -5) + 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) if self.direction == 1: self.display = self.attack_frames[math.floor(frame)] - self.display_offsets["player"] = pg.Vector2(-50,-50) + self.display_offsets["player"] = pg.Vector2(-50, -50) elif self.direction == -1: self.display = pg.transform.flip(self.attack_frames[math.floor(frame)], True, False) - self.display_offsets["player"] = pg.Vector2(-100,-50) + self.display_offsets["player"] = pg.Vector2(-100, -50) else: self.direction = prev_direction if prev_direction == 1: - self.display_offsets["player"] = pg.Vector2(-50,-50) + self.display_offsets["player"] = pg.Vector2(-50, -50) self.display = self.attack_frames[math.floor(frame)] elif prev_direction == -1: self.display = pg.transform.flip(self.attack_frames[math.floor(frame)], True, False) - self.display_offsets["player"] = pg.Vector2(-100,-50) + self.display_offsets["player"] = pg.Vector2(-100, -50) self.current_frame += 0.4 if math.floor(self.current_frame) == self.attack_gif.n_frames: @@ -178,29 +179,37 @@ class Player(Actor): if self.state != "ATTACK": self.state = "ATTACK" self.current_frame = 0 - elif self.state == "ATTACK": - if math.floor(self.current_frame) > 2: - for mask in self.targets: - for enemy in mask: - if not enemy.attacked and self.weapon.get_collision_rect().colliderect(enemy.get_collision_rect()): - enemy.attack(self, self.weapon) + if self.state == "ATTACK": + if 12 > math.floor(self.current_frame) > 6: + for mask in self.targets: + for enemy in mask: + # if not enemy.attacked and self.weapon.get_collision_rect().colliderect( + # enemy.get_collision_rect()): + if not enemy.attacked and get_display_rect(self.weapon.get_collision_rect()).colliderect( + get_display_rect(enemy.get_collision_rect())): + enemy.attack(self, self.weapon, self.direction) def draw(self, surf): 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"]) + 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(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) # pg.draw.rect(surf, self.colour, get_display_rect(self.get_collision_rect()), border_radius=8) - pg.draw.rect(surf, (255,0,0),get_display_rect(self.weapon.get_collision_rect()),width=3) - # pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8) + pg.draw.rect(surf, (255, 0, 0), get_display_rect(self.weapon.get_collision_rect()), width=3) + pg.draw.rect(surf, (0, 255, 0), get_display_rect(self.get_collision_rect()), 2) + # pg.draw.rect(surf,self.colour,pg.Rect(center, (self.width, self.height)),border_radius=8) # # Healthbar Stuff # # bar is made of 2 rectanges, background which is just a simple rectange and foreground which goes on top and has a bit of math involved @@ -220,12 +229,8 @@ class Player(Actor): # text_rect = current_health_display.get_rect(center=background_rect.center) # surf.blit(current_health_display, text_rect) - - def potion_cooldown_timer(self): while self.potion_cooldown > 0: self.potion_cooldown -= 1 - print(self.potion_cooldown) + # print(self.potion_cooldown) time.sleep(1) - - diff --git a/Setup.py b/Setup.py index b9e8cb6..a0bc8d8 100644 --- a/Setup.py +++ b/Setup.py @@ -6,7 +6,10 @@ from os import listdir, path pg.init() +display_info = pg.display.Info() + SCREEN_WIDTH, SCREEN_HEIGHT = 1080, 640 +# SCREEN_WIDTH, SCREEN_HEIGHT = display_info.current_w, display_info.current_h-10 dimensions = (SCREEN_WIDTH, SCREEN_HEIGHT) center = pg.Vector2(dimensions) / 2 @@ -55,4 +58,4 @@ def pil_to_game(img): def get_gif_frame(img, frame): img.seek(frame) - return img.convert(FORMAT) \ No newline at end of file + return img.convert(FORMAT) diff --git a/main.py b/main.py index 1475966..ec8eb85 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ is_running = True # scene = TransitionScene() scene = DevLevelSelect() old_level = 0 -level = 1 +level =1 next_level = 0 while is_running: @@ -44,6 +44,8 @@ while is_running: scene = Game(1) case 2: scene = Game(2) + case 3: + scene = Game(3) old_level = level scene.update(delta)