Skip to content

Commit

Permalink
Add lava block and map 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Donot committed Nov 17, 2023
1 parent 4e23b35 commit 0e37501
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
8 changes: 8 additions & 0 deletions block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,13 @@ def apply_effect(self, game):
if self.type == "jump" and not game.player.is_buff_jump:
game.player.jumping_height /= BUFF_JUMP
game.player.is_buff_jump = True
if self.type == "lava":
self.go_to_spawn(game)
game.player.dx = 0
game.player.dy = 0


def go_to_spawn(self, game):
game.player.x, game.player.y = game.spawn_block.x + (game.spawn_block.width - game.player.width)/2, game.spawn_block.y - game.player.height - 20
def __str__(self):
return f"{self.type} : \n x,y : [{self.x},{self.y}]\n w,h : [{self.width},{self.height}]"
6 changes: 5 additions & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
FRICTION = 0.05
BUFF_JUMP = 3/2

PLAYER_WIDTH = SCREEN_WIDTH/40
PLAYER_HEIGHT = SCREEN_HEIGHT/20



Expand All @@ -19,4 +21,6 @@ class Color(Enum):
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BURGUNDY = (144, 12, 63)
LIGHT_GREEN = (218, 247, 166)
LIGHT_GREEN = (218, 247, 166)
LIGHT_GREY = (191, 191, 191)
DARK_GREY = (63, 63, 63)
13 changes: 11 additions & 2 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ def __init__(self, fps=60, maps=[0]):


def init_player(self):
self.player = Player(SCREEN_WIDTH/16, SCREEN_HEIGHT - 70, SCREEN_WIDTH/40, SCREEN_HEIGHT/20)

self.player = Player(self.spawn_block.x + (self.spawn_block.width - PLAYER_WIDTH)/2 , self.spawn_block.y - PLAYER_HEIGHT, PLAYER_WIDTH, PLAYER_HEIGHT)

def init_block(self, id_map):
self.blocks = generate_map(id_map)
self.spawn_block : Block = self.get_spawn_point()

def get_spawn_point(self):
for block in self.blocks:
if block.type == "spawn":
return block
return None


def start(self):
pygame.init()
Expand All @@ -26,8 +34,9 @@ def start(self):
for m in self.maps:
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Platformer")
self.init_player()
self.init_block(m)
self.init_player()

self.run()

pygame.quit()
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from game import *


g = Game(fps=60, maps=[0,1,2])
g = Game(fps=60, maps=[3])
36 changes: 28 additions & 8 deletions map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def generate_map(id):
return map1()
elif id == 2:
return map2()

elif id == 3:
return map3()
else:
return no_map()

Expand All @@ -22,6 +23,8 @@ def map0():
blocks = []

blocks.append(Block(0, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH, SCREEN_HEIGHT/30, Color.GREEN.value)) #ground
blocks.append(Block(SCREEN_WIDTH/16 - SCREEN_WIDTH/80, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH/20, SCREEN_HEIGHT/60, Color.LIGHT_GREY.value, type="spawn")) #spawn point

blocks.append(Block(SCREEN_WIDTH*3/16, SCREEN_HEIGHT*13/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BLUE.value))
blocks.append(Block(SCREEN_WIDTH/2 - SCREEN_WIDTH/8, SCREEN_HEIGHT*11/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BLUE.value))
blocks.append(Block(SCREEN_WIDTH*3/4 - SCREEN_WIDTH/8, SCREEN_HEIGHT*9/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BLUE.value))
Expand All @@ -37,7 +40,7 @@ def map0():
def map1():
blocks = []
blocks.append(Block(0, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH, SCREEN_HEIGHT/30, Color.GREEN.value)) #ground

blocks.append(Block(SCREEN_WIDTH/16 - SCREEN_WIDTH/80, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH/20, SCREEN_HEIGHT/60, Color.LIGHT_GREY.value, type="spawn")) #spawn point
#Mains horizontals platforms
blocks.append(Block(0, SCREEN_HEIGHT*3/4 - SCREEN_HEIGHT/30, SCREEN_WIDTH*13/16, SCREEN_HEIGHT/30, Color.BLUE.value))
blocks.append(Block(SCREEN_WIDTH*3/16, SCREEN_HEIGHT/2 - SCREEN_HEIGHT/30, SCREEN_WIDTH*13/16, SCREEN_HEIGHT/30, Color.BLUE.value))
Expand All @@ -63,17 +66,34 @@ def map1():
def map2():
blocks = []



blocks.append(Block(0, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH, SCREEN_HEIGHT/30, Color.GREEN.value)) #ground


blocks.append(Block(SCREEN_WIDTH/16 - SCREEN_WIDTH/80, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH/20, SCREEN_HEIGHT/60, Color.LIGHT_GREY.value, type="spawn")) #spawn point
blocks.append(Block(SCREEN_WIDTH*3/16, SCREEN_HEIGHT*13/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))
blocks.append(Block(SCREEN_WIDTH*3/4 - SCREEN_WIDTH/8, SCREEN_HEIGHT*9/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))
blocks.append(Block(SCREEN_WIDTH*3/32, SCREEN_HEIGHT*12/32, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))
blocks.append(Block(SCREEN_WIDTH*3/4 - SCREEN_WIDTH/8, SCREEN_HEIGHT*3/16, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))


blocks.append(Block(SCREEN_WIDTH*28/32, SCREEN_HEIGHT/8 - SCREEN_HEIGHT/30, SCREEN_WIDTH*3/80, SCREEN_HEIGHT/30, Color.YELLOW.value, type="win"))

return blocks


def map3():
blocks = []


blocks.append(Block(SCREEN_WIDTH/16 - SCREEN_WIDTH/80, SCREEN_HEIGHT/10, SCREEN_WIDTH/20, SCREEN_HEIGHT/30, Color.LIGHT_GREY.value, type="spawn")) #spawn point
blocks.append(Block(0, SCREEN_HEIGHT-SCREEN_HEIGHT/30, SCREEN_WIDTH, SCREEN_HEIGHT/30, Color.RED.value, type="lava")) #ground

blocks.append(Block((SCREEN_WIDTH - SCREEN_WIDTH/40)/2, 0, SCREEN_WIDTH/40, SCREEN_HEIGHT/2,Color.BLUE.value))

blocks.append(Block((SCREEN_WIDTH - SCREEN_WIDTH/40)/2, SCREEN_HEIGHT/2 + PLAYER_HEIGHT*3/2, SCREEN_WIDTH/40, SCREEN_HEIGHT/4,Color.BLUE.value))


blocks.append(Block(SCREEN_WIDTH*3/4,SCREEN_HEIGHT*3/4,SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))
blocks.append(Block((SCREEN_WIDTH - SCREEN_WIDTH/40)/2 + SCREEN_WIDTH/40, SCREEN_HEIGHT/2 - SCREEN_HEIGHT/30, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))
blocks.append(Block((SCREEN_WIDTH - SCREEN_WIDTH/40)/2 + SCREEN_WIDTH/40, SCREEN_HEIGHT/10 + SCREEN_HEIGHT/30, SCREEN_WIDTH/8, SCREEN_HEIGHT/30, Color.BURGUNDY.value, type="jump"))

blocks.append(Block(SCREEN_WIDTH - (SCREEN_WIDTH/16 - SCREEN_WIDTH/80) - SCREEN_WIDTH/20, SCREEN_HEIGHT/10, SCREEN_WIDTH/20, SCREEN_HEIGHT/30, Color.YELLOW.value, type="win"))


return blocks

0 comments on commit 0e37501

Please sign in to comment.