Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 95 additions & 34 deletions Player.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Player(Tile):

def __init__(self, display, grid_pos, color, images=None):
super().__init__(display, grid_pos, color, collidable=True, images=None)
self.gravity = 3
self.speed = 10
self.gravity = 2.8
self.speed = 8
self.vel = pygame.math.Vector2(0, 0)
self.grounded = True
self.controlling_player = True
Expand All @@ -16,27 +16,78 @@ def __init__(self, display, grid_pos, color, images=None):
self.creature = None
self.can_jump = True
self.offset = pygame.math.Vector2(0, 600)
self.images = idle_anim_R
self.images = idle_anim[0]
self.summoning = False

def draw(self, offset):
if self.current_frame >=31: self.current_frame = 0
if self.images is not None:
print("-------------------")
if self.direction == 1:
self.images = idle_anim_R
image(self.display, self.images[self.frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
else:
self.images = idle_anim_L
image(self.display, self.images[self.frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
self.frame=(self.frame + 1) % len(self.images)
if self.summoning:

self.images = summon_anim[0]
if self.anim_frame>=len(self.images):
self.anim_frame = 0
self.summoning = False
self.controlling_player = not self.controlling_player
image(self.display, self.images[self.anim_frame],
(round(self.rect.x - self.offset.x),
round(self.rect.y - self.offset.y)))
self.images = summon_part[1]
if self.anim_frame - 2 >=0 and not self.creature == None:
image(self.display, self.images[self.anim_frame - 2],
(round(self.creature.rect.x - self.creature.offset.x),
round(self.creature.rect.y - self.creature.offset.y + SCALE)))
if self.current_frame %4 == 0: self.anim_frame+=1
elif self.vel.x == 0 and self.grounded :
self.images = idle_anim[0]
if self.anim_frame >= len(self.images): self.anim_frame = 0
image(self.display, self.images[self.anim_frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
if self.current_frame %4 == 0: self.anim_frame+=1
else:
self.images = walk_anim[0]
if self.anim_frame >= len(self.images): self.anim_frame = 0
image(self.display, self.images[self.anim_frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
if self.current_frame %4 == 0:self.anim_frame+=1

else:
if self.summoning:
self.images = summon_anim[1]
if self.anim_frame>=len(self.images):
self.anim_frame = 0
self.summoning = False
self.controlling_player = not self.controlling_player
image(self.display, self.images[self.anim_frame],
(round(self.rect.x - self.offset.x),
round(self.rect.y - self.offset.y)))
self.images = summon_part[1]
if self.anim_frame - 2 >=0 and not self.creature == None:
image(self.display, self.images[self.anim_frame - 2],
(round(self.creature.rect.x - self.creature.offset.x),
round(self.creature.rect.y - self.creature.offset.y + SCALE)))
if self.current_frame %4 == 0: self.anim_frame+=1

elif self.vel.x == 0 and self.grounded:
self.images = idle_anim[1]
if self.anim_frame >= len(self.images): self.anim_frame = 0
image(self.display, self.images[self.anim_frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
if self.current_frame %4 == 0:self.anim_frame+=1

else:
self.images = walk_anim[1]
if self.anim_frame >= len(self.images): self.anim_frame = 0
image(self.display, self.images[self.anim_frame], (round(self.rect.x - offset.x), round(self.rect.y - offset.y)))
if self.current_frame %4 == 0:self.anim_frame+=1
else:
print("Bbbbbbbbbbbbbbbbbbbbbbbbbb")
pygame.draw.rect(self.display, self.color,
(round(self.rect.x - offset.x), round(self.rect.y - offset.y), SCALE, SCALE))
if self.creature:
pygame.draw.rect(self.display, self.creature.color,
(round(self.creature.rect.x - offset.x), round(self.creature.rect.y - offset.y),
self.creature.rect.width, self.creature.rect.height))
# if self.creature:
# pygame.draw.rect(self.display, self.creature.color,
# (round(self.creature.rect.x - offset.x), round(self.creature.rect.y - offset.y),
# self.creature.rect.width, self.creature.rect.height))
self.current_frame+=1


def update(self, keys, tiles, time_passed=0):
self.update_pos(keys, tiles)
Expand Down Expand Up @@ -67,18 +118,20 @@ def update_pos(self, keys, tiles):
self.creature.collide(tiles)

def controls(self, moving_person, keys):
if keys[pygame.K_w] and moving_person.grounded and moving_person.can_jump:
moving_person.vel.y = -26
moving_person.grounded = False
if keys[pygame.K_a]:
moving_person.set_dir(-moving_person.speed, moving_person.vel.y)
moving_person.direction = -1
elif keys[pygame.K_d]:
moving_person.set_dir(moving_person.speed, moving_person.vel.y)
moving_person.direction = 1
else:
moving_person.set_dir(0, moving_person.vel.y)

if not self.summoning:
if keys[pygame.K_w] and moving_person.grounded and moving_person.can_jump:
moving_person.vel.y = -22
moving_person.grounded = False
if keys[pygame.K_a] :

moving_person.set_dir(-moving_person.speed, moving_person.vel.y)
moving_person.direction = -1

elif keys[pygame.K_d] :
moving_person.set_dir(moving_person.speed, moving_person.vel.y)
moving_person.direction = 1
else:
moving_person.set_dir(0, moving_person.vel.y)

def set_dir(self, dir_x, dir_y):
self.vel.update(dir_x, dir_y)
Expand Down Expand Up @@ -177,12 +230,12 @@ def __init__(self, display, grid_pos, color):
super().__init__(display, grid_pos, color, images=None)

self.disappear_timer = 0
self.destroy_creature_timer = 5000
self.destroy_creature_timer = 15000
self.destroy_creature = False

def update_timer(self, time_passed=0):
self.destroy_creature_timer -= time_passed

if self.destroy_creature_timer < 0:
self.destroy_creature = True

Expand All @@ -202,7 +255,7 @@ def __init__(self, display, grid_pos, color):
def check_pickup(self, tile):
return tile.movable and self.grab_box.colliderect(tile.rect) and not tile.drop

def pickup(self, tiles, movable_tiles, level):
def pickup(self, tiles, movable_tiles, level, player):
movable = self.convert_to_dict(movable_tiles)

self.grab_box = pygame.Rect(self.rect.x + (SCALE if self.direction == 1 else -SCALE / 2),
Expand All @@ -218,12 +271,20 @@ def pickup(self, tiles, movable_tiles, level):
i += 1

loc = round(self.stack[-1].rect.y / SCALE), round(self.stack[-1].rect.x / SCALE)
if not(level[loc[0]-1][loc[1]] in [0, 2] and level[loc[0]-2][loc[1]] in [0, 2]):
if not (level[loc[0] - 1][loc[1]] in [0, 2] and level[loc[0] - 2][loc[1]] in [0, 2]):
self.stack = []

fakerect = pygame.Rect(player.rect.x, player.rect.y + 4, player.rect.width, player.rect.height)
print(fakerect)
print(level[round(player.rect.y / SCALE)-2][round(player.rect.x / SCALE)])
if fakerect.colliderect(self.stack[-1].rect) and (
level[round(player.rect.y / SCALE)-2][round(player.rect.x / SCALE)] in [0, 2]):
player.rect.y -= SCALE * 2
elif not (level[round(player.rect.y / SCALE) - 2][round(player.rect.x / SCALE)] in [0, 2]):
self.stack = []
print(loc)
# if not level[location[1] - i - 1][location[0]] in [0, 2]:
# self.stack = []
# break
# if not level[location[1] - i - 1][location[0]] in [0, 2]:
# self.stack = []
# break

print(self.stack)
for i, box in enumerate(self.stack):
Expand Down
3 changes: 2 additions & 1 deletion Tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self, display, grid_pos, color, collidable=False, movable=False, im
self.goal = -1
self.id = 0
self.images = images
self.frame = 0
self.anim_frame = 0
self.current_frame = 1

# function for drawing tiles
def draw(self, offset):
Expand Down
Binary file modified __pycache__/Player.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/Tile.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/levels.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/settings.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def load_level(level):
if tile_type == 1:
tile = Tile(screen, (x, y), (100, 100, 100), collidable=True)
elif tile_type == 2:
player = Player(screen, (x, y), (0, 255, 0), images=idle_anim_R)
player = Player(screen, (x, y), (0, 255, 0), images=idle_anim[0])
elif tile_type == 3:
tiles.append(Tile(screen, (x, y), (255, 255, 255)))
tile = Tile(screen, (x, y), (0, 0, 255), collidable=True, movable=True)
Expand Down
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ def main():
# stops player movement if player presses summoning button (k)
if event.type == pygame.KEYUP:
if event.key == pygame.K_l and player.grounded and player.creature:

player.summoning =True
player.controlling_player = False
player.creature.update_timer(99999999)
if event.key == pygame.K_k and player.grounded:
if not player.creature:
player.controlling_player = True
player.summoning = True
summon_tile = player.check_tile_nearby(BASE_WORLD, movable_tiles)
if summon_tile is not None:
player.summon(summon_tile)
#add summon particle animation beside the summon animatoin
else:
player.creature.vel.x = 0

player.controlling_player = not player.controlling_player
player.vel.x = 0
player.controlling_player = not player.controlling_player


if event.key == pygame.K_SPACE:
if not player.controlling_player and player.creature:
if len(player.creature.stack) == 0:
player.creature.pickup(tiles, movable_tiles, BASE_WORLD)
player.creature.pickup(tiles, movable_tiles, BASE_WORLD,player.creature)
else:
for box in player.creature.stack:
box.picked_up = False
Expand Down
Binary file added monkey-jump/__MACOSX/._monkey-jump-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/__MACOSX/._monkey-jump-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added monkey-jump/monkey-jump-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
22 changes: 12 additions & 10 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pygame.init()
# size of screen in terms of tiles
grid_w, grid_h = 24, 20

DEFAULT_IMG_SIZE=(60,60)
SCALE = 60 # size of tiles in pixels
WIDTH, HEIGHT = 12 * SCALE, 10 * SCALE
screen = pygame.display.set_mode((WIDTH, HEIGHT))
Expand All @@ -18,7 +18,7 @@
# function for loading in images
def loadify(filename, scaling, flip=(False, False)):
img = pygame.image.load(filename).convert_alpha()
img = pygame.transform.scale(img, (img.get_width() * scaling, img.get_height() * scaling))
img = pygame.transform.scale(img, scaling)
img = pygame.transform.flip(img, flip[0], flip[1])
return img

Expand Down Expand Up @@ -63,11 +63,13 @@ def fade(surface, mode, draw_func, *draw_par):
pygame.time.delay(2)
clock.tick()

idle_anim = [[loadify(f"monkey-idle/monkey-idle_-{i+1}.png",1) for i in range(4)],
[loadify(f"monkey-idle/monkey-idle_-{i+1}.png",1, (True, False)) for i in range(4)]]
walk_anim = [[loadify(f"monkey-walk/monkey-walk-{i+1}.png",1) for i in range(8)],
[loadify(f"monkey-walk/monkey-walk-{i+1}.png",1, (True, False)) for i in range(8)]]
jump_anim = [[loadify(f"monkey-jump/monkey-jump-{i+1}.png",1) for i in range(7)],
[loadify(f"monkey-jump/monkey-jump-{i+1}.png",1, (True, False)) for i in range(7)]]
summon_anim = [[loadify(f"monkey-summoning/Summon-{i+2}.png",1) for i in range(9)],
[loadify(f"monkey-summoning/Summon-{i+2}.png",1, (True, False)) for i in range(9)]]
idle_anim = [[loadify(f"monkey-idle/monkey-idle_-{i+1}.png",DEFAULT_IMG_SIZE) for i in range(4)],
[loadify(f"monkey-idle/monkey-idle_-{i+1}.png",DEFAULT_IMG_SIZE, (True, False)) for i in range(4)]]
walk_anim = [[loadify(f"monkey-walk/monkey-walk-{i+1}.png",DEFAULT_IMG_SIZE) for i in range(8)],
[loadify(f"monkey-walk/monkey-walk-{i+1}.png",DEFAULT_IMG_SIZE, (True, False)) for i in range(8)]]
jump_anim = [[loadify(f"monkey-jump/monkey-jump-{i+1}.png",DEFAULT_IMG_SIZE) for i in range(7)],
[loadify(f"monkey-jump/monkey-jump-{i+1}.png",DEFAULT_IMG_SIZE, (True, False)) for i in range(7)]]
summon_anim = [[loadify(f"monkey-summoning/Summon-{i+2}.png",DEFAULT_IMG_SIZE) for i in range(9)],
[loadify(f"monkey-summoning/Summon-{i+2}.png",DEFAULT_IMG_SIZE, (True, False)) for i in range(9)]]
summon_part = [[loadify(f"monkey-summoning/Summon-{i+2}.png",DEFAULT_IMG_SIZE) for i in range(9)],
[loadify(f"summon-particles/Summon_Particles-{i+1}.png",DEFAULT_IMG_SIZE, (True, False)) for i in range(7)]]
Binary file added summon-particles/Summon_Particles-1.png
Binary file added summon-particles/Summon_Particles-2.png
Binary file added summon-particles/Summon_Particles-3.png
Binary file added summon-particles/Summon_Particles-4.png
Binary file added summon-particles/Summon_Particles-5.png
Binary file added summon-particles/Summon_Particles-6.png
Binary file added summon-particles/Summon_Particles-7.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-1.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-2.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-3.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-4.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-5.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-6.png
Binary file added summon-particles/__MACOSX/._Summon_Particles-7.png