diff --git a/assets/fonts/MotomangucodeBold-3zde3.ttf b/assets/fonts/MotomangucodeBold-3zde3.ttf new file mode 100644 index 0000000000000000000000000000000000000000..af8243c5f17e1f32f11e25717b9fa2514e701b18 Binary files /dev/null and b/assets/fonts/MotomangucodeBold-3zde3.ttf differ diff --git a/game.py b/game.py index 35a7278e0db8e18d8d80cd2141a5076bc76439a8..e0d7c282635efd900da58302cae9332b0de9f82b 100644 --- a/game.py +++ b/game.py @@ -25,13 +25,18 @@ class Game: def __init__(self): self.levels = [] self.cursor = None + self.last_level = None self.stage = "Main Menu" self.is_open = True # Level 0 - self.cursor = 0 + self.levels.append(build_level("assets/levels/level0.json")) + self.levels.append(build_level("assets/levels/level1.json")) + self.levels.append(build_level("assets/levels/level2.json")) + def reload_levels(self): + self.levels = [] self.levels.append(build_level("assets/levels/level0.json")) self.levels.append(build_level("assets/levels/level1.json")) self.levels.append(build_level("assets/levels/level2.json")) @@ -42,41 +47,86 @@ class Game: self.is_open = False if event.type == pygame.USEREVENT: sound_victory() + self.reload_levels() + self.last_level = self.cursor + self.cursor = None + self.stage = "End Menu" if event.type == pygame.KEYDOWN: - for player in (self.levels[self.cursor]).players: - if event.key == pygame.K_LEFT: - player.move_left(self.levels[self.cursor].grid) - if event.key == pygame.K_RIGHT: - player.move_right(self.levels[self.cursor].grid) - if event.key == pygame.K_UP: - player.move_up(self.levels[self.cursor].grid) - if event.key == pygame.K_DOWN: - player.move_down(self.levels[self.cursor].grid) - - - self.levels[self.cursor].update(delta_time) + if self.cursor is not None: + if event.key == pygame.K_r: + self.levels[self.cursor].ask_for_reload = True + for player in (self.levels[self.cursor]).players: + if event.key == pygame.K_LEFT: + player.move_left(self.levels[self.cursor].grid) + if event.key == pygame.K_RIGHT: + player.move_right(self.levels[self.cursor].grid) + if event.key == pygame.K_UP: + player.move_up(self.levels[self.cursor].grid) + if event.key == pygame.K_DOWN: + player.move_down(self.levels[self.cursor].grid) + if event.type == pygame.KEYUP: + if self.cursor is not None: + if event.key == pygame.K_r: + self.levels[self.cursor].ask_for_reload = False + + if self.cursor is not None: + self.levels[self.cursor].update(delta_time) def render(self, surface): - draw_level(self.levels[self.cursor], surface.py_surface) + if self.cursor is not None: + draw_level(self.levels[self.cursor], surface.py_surface) - temp_surface = surface.py_surface.subsurface(pygame.Rect(0, 0, - self.levels[self.cursor].grid.size[0] * pixel_size, - self.levels[self.cursor].grid.size[ - 1] * pixel_size)).copy() + temp_surface = surface.py_surface.subsurface(pygame.Rect(0, 0, + self.levels[self.cursor].grid.size[0] * pixel_size, + self.levels[self.cursor].grid.size[ + 1] * pixel_size)).copy() - surface.py_surface.fill((0, 0, 0)) + surface.py_surface.fill((0, 0, 0)) - pygame.draw.rect(surface.py_surface, (255, 255, 255), pygame.Rect( + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect( int((surface.width - (self.levels[self.cursor].grid.size[0]) * pixel_size) / 2) - 5, int( (surface.height - (self.levels[self.cursor].grid.size[1]) * pixel_size) / 2) - 5, self.levels[self.cursor].grid.size[0] * pixel_size + 10, self.levels[self.cursor].grid.size[1] * pixel_size + 10)) + pygame.draw.rect(surface.py_surface, colors["Black"], pygame.Rect( + int((surface.width - (self.levels[self.cursor].grid.size[0]) * pixel_size) / 2) - 3, int( + (surface.height - (self.levels[self.cursor].grid.size[1]) * pixel_size) / 2) - 3, + self.levels[self.cursor].grid.size[0] * pixel_size + 6, + self.levels[self.cursor].grid.size[1] * pixel_size + 6)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect( + int((surface.width - (self.levels[self.cursor].grid.size[0]) * pixel_size) / 2) - 1, int( + (surface.height - (self.levels[self.cursor].grid.size[1]) * pixel_size) / 2) - 1, + self.levels[self.cursor].grid.size[0] * pixel_size + 2, + self.levels[self.cursor].grid.size[1] * pixel_size + 2)) surface.py_surface.blit(temp_surface, (int((surface.width - self.levels[self.cursor].grid.size[0] * pixel_size) / 2), int( (surface.height - self.levels[self.cursor].grid.size[1] * pixel_size) / 2))) - - #pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect()) - #pygame.draw.rect(surface.py_surface, colors["Black"], pygame.Rect()) - #pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect()) - #pygame.draw.rect(surface.py_surface, colors["darkblue"], pygame.Rect()) \ No newline at end of file + + x = (((surface.width - (self.levels[self.cursor].grid.size[0]) * pixel_size) / 2) - 5) / 2 - 75 + y = int((surface.height - (self.levels[self.cursor].grid.size[1]) * pixel_size) / 2) - 5 + + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect(x, y, 150, 100)) + pygame.draw.rect(surface.py_surface, colors["Black"], pygame.Rect(x + 2, y + 2, 146, 96)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect(x + 4, y + 4, 142, 92)) + pygame.draw.rect(surface.py_surface, colors["darkblue"], pygame.Rect(x + 5, y + 5, 140, 90)) + time_font = pygame.font.Font("assets/fonts/MotomangucodeBold-3zde3.ttf", 50) + time = self.levels[self.cursor].time + minutes = int(time / 60) + secondes = int(time - 60 * minutes) + timer_string = str(minutes) + ":" + str(secondes) + timer = time_font.render(timer_string, True, colors["ivoire"]) + surface.blit(timer, ((2 * x + 150) / 2 - timer.get_width() / 2, (2 * y + 100) / 2 - timer.get_height() / 2)) + + font = pygame.font.Font("assets/fonts/BulletTrace7-rppO.ttf", 40) + play_again_button = font.render("Hold R to Reload", True, colors["ivoire"]) + current_level = "Level " + str(self.cursor + 1) + level = font.render(current_level, True, colors["ivoire"]) + + y_bis = ((surface.height - (self.levels[self.cursor].grid.size[1]) * pixel_size) / 2) - 5 + \ + self.levels[self.cursor].grid.size[1] * pixel_size + 10 + + surface.blit(level, (surface.width / 2 - level.get_width() / 2, y / 2 - level.get_height() / 2)) + surface.blit(play_again_button, ( + surface.width / 2 - play_again_button.get_width() / 2, + (720 + y_bis) / 2 - play_again_button.get_height() / 2)) diff --git a/level/level.py b/level/level.py index 3e95d93407b1fda75874b64067aa4acf1d67be32..3ec6728b735023c1b3e0cc0f8db148edb89478c5 100644 --- a/level/level.py +++ b/level/level.py @@ -12,23 +12,27 @@ victory_event = pygame.event.Event(pygame.USEREVENT) class Level: - # starting positions of the players inside the grid + # Those parameters define the size of the grid that belongs to this level and also all the parameters for the + # players (the count, their colors at the beginning, their initial positions and event the final position they + # have to go to) def __init__(self, size, initial_positions, initial_colors, final_positions): self.grid = Grid(size) self.players = [] + self.final_positions = final_positions self.initial_positions = initial_positions self.initial_colors = initial_colors - self.finished = False - self.time=0 + self.finished = False # it's an indicator of the state of the level + + self.ask_for_reload = False + self.reload_timer = 0 + self.time = 0 # a level can have the concept of time : it helps to make dynamic things + for k in range( - len(initial_positions)): # sometimes there is two players and we can imagine a level with even more - # creation of the list of colors in rgb format - initial_colors_rgb = colors[self.initial_colors[k]] + len(initial_positions)): # sometimes there are two players and we can imagine a level with even more - self.players.append(Player( - initial_colors_rgb, initial_positions[k][0] * pixel_size, initial_positions[k][1] * pixel_size, 0, - 0)) + self.players.append(Player(colors[self.initial_colors[k]], initial_positions[k][0] * pixel_size, + initial_positions[k][1] * pixel_size)) self.grid.obstacles[initial_positions[k][0], initial_positions[k][1]] = Obstacle(self.initial_colors[k], False, @@ -37,15 +41,32 @@ class Level: self.grid.obstacles[final_positions[k][0], final_positions[k][1]] = Obstacle(self.initial_colors[k], False, False, True) - def update(self, delta_time): + def update(self, delta_time): # this function is called 60 times per second in average, so delta_time = 1/60 finished = True - for i in range(len(self.players)): + + for i in range(len(self.players)): # check if all players are at their final positions at the same time player = self.players[i] player.update(delta_time, self.grid) if int(player.position[0] / pixel_size) != self.final_positions[i][0] or int( player.position[1] / pixel_size) != self.final_positions[i][1]: finished = False - if finished and not self.finished: + + if finished and not self.finished: # if yes, trigger an event to tell the game to stop the current level pygame.event.post(victory_event) self.finished = True + self.time += delta_time + if self.ask_for_reload: + self.reload_timer += delta_time + + if self.reload_timer >= 1: + self.players = [] + + for k in range( + len(self.initial_positions)): + self.players.append(Player(colors[self.initial_colors[k]], self.initial_positions[k][0] * pixel_size, + self.initial_positions[k][1] * pixel_size)) + + self.ask_for_reload = False + self.reload_timer = 0 + self.time = 0 diff --git a/level/level_loader.py b/level/level_loader.py index ff1b3cfe2bc77a9614c0bc556914dd3ea347396f..dbfa97149709154ae8f86c1186e191f5619b674c 100644 --- a/level/level_loader.py +++ b/level/level_loader.py @@ -1,11 +1,12 @@ -###Imports### +# Imports # import json from level.level import Level from level.obstacle import Obstacle, colors -### build level function ''' +- build level function - + this function takes a level written in a json file it returns the level objet that can be read by our python code ''' diff --git a/level/obstacle.py b/level/obstacle.py index 9b41769c4776e242e5933b22df159cedcdf2685c..50ed5eb2ba0deadd385a224926d7021bb4543b0f 100644 --- a/level/obstacle.py +++ b/level/obstacle.py @@ -1,14 +1,18 @@ # dictionary of the used colors, in RGB (format understood by pygame) colors = {"red": (220, 20, 60), "blue": (106, 90, 205), "green": (154, 205, 50), "yellow": (255, 215, 0), - "darkgrey": (105, 105, 105), "darkblue": (2, 4, 55),"darkerblue" : (0,0,51), "ivoire" : (255,255,212), "Volkswagen Taupe" : (140, 134, 128), "Black" : (0,0,0)} -pixel_size = 44 + "darkgrey": (105, 105, 105), "darkblue": (2, 4, 55), "darkerblue": (0, 0, 51), "ivoire": (255, 255, 212), + "Volkswagen Taupe": (140, 134, 128), "Black": (0, 0, 0)} + +# this is the pixel size that defines everything : each tile in the grid has this size and even the player. +pixel_size = 40 # class obstacle that will be used in the grid, color is a key of the dictionnary class Obstacle: - def __init__(self, color, color_switcher=False, start= False, end=False): + # an obstacle is defined by its color and its behaviour (if it's a color_switcher etc...), the color is a string + # that refers to a key of 'colors' + def __init__(self, color, color_switcher=False, start=False, end=False): self.color = colors[color] self.color_switcher = color_switcher self.end = end self.start = start - diff --git a/level/player.py b/level/player.py index a3ea9c2327e6428d0196cf9e8c5933c1a58c5f3f..b4ed4dc91fe9f8f76147e2b0a39a6428f9e4f6de 100644 --- a/level/player.py +++ b/level/player.py @@ -10,13 +10,21 @@ from sound import sound_collision # ---------------- # class Player: - # Player object has a color, a position and a velocity - def __init__(self, color, x_init, y_init, x_velocity, y_velocity): + # Player object has a color (in RGB format, not in str) and a position + def __init__(self, color, x_init, y_init): self.color = color self.position = np.array([x_init, y_init]) self.render_position = np.array([x_init, y_init]) - self.destination = np.array([x_init, y_init]) + + # the destination parameter is updated when the player wants to move and the 'update' function + # manages the travel of the player from its current position to the destination position + + self.destination = np.array([x_init, + y_init]) + + # some variables that defines the characteristics of the player (like its speed, its ability to move, + # and its bouncing behaviour and finally some fun data about the last positions of the player) self.is_moving = False self.start_speed = 1000 @@ -27,26 +35,34 @@ class Player: self.bounce_time = 0 self.bounce_direction = np.array([0, 0]) + self.record_length = 4 + self.last_positions = [] + self.cursor = 0 + + # position of the player in the pixel format (on the surface the unit is the size of one pixel) def surface_position(self): return self.position + # position of the player on the grid (the unit is 'pixel_size') def level_position(self): x = int(self.position[0] / pixel_size) y = int(self.position[1] / pixel_size) return np.array([x, y]) + # this function calculates the destination of a player that wants to move on the horizontal axis def advance_x(self, grid, r1, r2): x, y = self.level_position() i = 0 active_color = self.color - for j in range(x, r1, r2): - if grid.obstacles[j, y] is None: + for j in range(x, r1, r2): # start at the position of the player and move on the horizontal axis + if grid.obstacles[j, y] is None: # if there is no obstacle, the player can go there i = j - x continue else: + # there are some exceptions if grid.obstacles[j, y].color_switcher: active_color = grid.obstacles[j, y].color i = j - x @@ -60,6 +76,7 @@ class Player: i = j - x continue + # if it's a basic obstacle let's break the loop : the player can't go on this tile if not grid.obstacles[j, y].color_switcher and not grid.obstacles[j, y].start and not grid.obstacles[ j, y].end and not ( grid.obstacles[j, y].color == active_color): @@ -67,6 +84,7 @@ class Player: return i + # same def advance_y(self, grid, r1, r2): x, y = self.level_position() i = 0 @@ -97,6 +115,7 @@ class Player: return i + # manges the calculus regarding the direction def calculate_destination(self, grid, direction): x, y = self.level_position() @@ -112,10 +131,11 @@ class Player: if direction == "up": return np.array([x, y + self.advance_y(grid, -1, -1)]) + # those are the functions that can be called from the game to move the player def move_up(self, grid): - self.bounce_direction = np.array([0, -1]) + self.bounce_direction = np.array([0, -1]) # changes the future bounce direction - if not self.is_moving: + if not self.is_moving: # the player can not move if it's alreadu moving self.destination = self.calculate_destination(grid, "up") * pixel_size self.is_moving = True @@ -141,6 +161,19 @@ class Player: self.is_moving = True def update(self, delta_time, grid): + # data for the motion_blur (and maybe something else) + + # record the last 'record_length' positions of the player + if len(self.last_positions) != self.record_length: + self.last_positions.append(self.render_position) + else: + self.last_positions[self.cursor] = self.render_position + self.cursor = (self.cursor + 1) % self.record_length + + # logical + + # manages the bounces with a sinusoidal function + if self.bounces: self.bounce_time = self.bounce_time + delta_time if self.bounce_amplitude == 0: @@ -156,6 +189,7 @@ class Player: self.render_position = self.position + self.bounce_direction * self.bounce_amplitude * np.sin( -20 * self.bounce_time) + # manages the movement of the player if (self.position == self.destination).all(): if self.is_moving: sound_collision() @@ -163,11 +197,13 @@ class Player: self.is_moving = False self.speed = self.start_speed else: - self.speed += self.start_speed * 8 * delta_time + self.speed += self.start_speed * 8 * delta_time # the speed increases in time distance = np.linalg.norm(self.destination - self.position) direction = (self.destination - self.position) / distance delta = self.speed * delta_time + # check that the next frame the player will not cross the destination (if the speed is too high) + if (direction == np.array([1, 0])).all(): if self.position[0] + delta > self.destination[0]: self.position[0] = self.destination[0] @@ -192,6 +228,8 @@ class Player: else: self.position[1] = self.position[1] - delta + # the player is on a color_switcher + x, y = self.level_position() if grid.obstacles[x, y] is not None: diff --git a/main.py b/main.py index 6ebfe95ec9bb0d0c469baa1f9a883bb68ac4245a..a7d41f2af716d2675ed6c53e6654b8804b910a1c 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ from render.draw_main_menu import draw_main_menu from render.surface import Surface from render.surface import events, flip from level.obstacle import colors +from render.draw_end_menu import draw_end_menu # ----------------- # @@ -22,15 +23,18 @@ def main(): while game.is_open: surface.clear((0, 0, 0)) + + game.update(float(1 / 60)) if game.stage == "Launched": - game.update(float(1 / 60)) game.render(surface) if game.stage == "Main Menu": - game.update(float(1 / 60)) draw_main_menu(surface, menu, game) + if game.stage == "End Menu": + draw_end_menu (surface, game) + flip() clock.tick(60) diff --git a/render/draw_end_menu.py b/render/draw_end_menu.py index e0bf37fa79ee2e946938b41bf3e0d49698fc40d0..b958945bdf5d92b7b12e9f9e27aa5cba53ee0e75 100644 --- a/render/draw_end_menu.py +++ b/render/draw_end_menu.py @@ -1,47 +1,100 @@ ### Imports import pygame -from surface import Surface, flip +from render.surface import Surface, flip +from game import Game +from level.obstacle import colors -colors = {"red": (220, 20, 60), "blue": (106, 90, 205), "green": (154, 205, 50), "yellow": (255, 215, 0), - "darkgrey": (105, 105, 105), "darkblue": (2, 4, 55), "white_yellow": (255,255,204)} +### drawing function -#surface = Surface(1280, 720, "test") +def draw_end_menu(surface, game): + # dimensions + height = surface.height + width = surface.width + button_width = 250 + button_height = 80 -###characteristics -height = 500 -width = 800 + surface.py_surface.fill(colors["darkblue"]) + # fonts + font = pygame.font.Font("assets/fonts/BulletTrace7-rppO.ttf", 60) + font_buttons = pygame.font.Font("assets/fonts/BulletTrace7-rppO.ttf", 30) -### drawing function + # title + title = font.render('VICTORY', True, colors["ivoire"]) + surface.py_surface.blit(title, ((width - title.get_width()) / 2, + (height - title.get_height()) / 2 - 200)) + + # play again button + play_again_button = font_buttons.render("Play again", True, colors["ivoire"]) + + text_width = play_again_button.get_width() + text_height = play_again_button.get_height() + + x_button1 = (width - play_again_button.get_width()) / 2 - 200 + y_button1 = (height - play_again_button.get_height()) / 2 + + x_rect1 = x_button1 - (button_width - text_width) / 2 + y_rect1 = y_button1 - (button_height - text_height) / 2 + + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect(x_rect1, y_rect1, button_width, button_height)) + pygame.draw.rect(surface.py_surface, colors["Black"], + pygame.Rect(x_rect1 + 1, y_rect1 + 1, button_width - 2, button_height - 2)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect1 + 5, y_rect1 + 5, button_width - 10, button_height - 10)) + pygame.draw.rect(surface.py_surface, colors["darkblue"], + pygame.Rect(x_rect1 + 6, y_rect1 + 6, button_width - 12, button_height - 12)) + + surface.py_surface.blit(play_again_button, (x_button1, y_button1)) + + # menu button + + menu_button = font_buttons.render("Menu", True, colors["ivoire"]) + + text_width = menu_button.get_width() + text_height = menu_button.get_height() + + x_button2 = (width - menu_button.get_width()) / 2 + 200 + y_button2 = (height - menu_button.get_height()) / 2 + + x_rect2 = x_button2 - (button_width - text_width) / 2 + y_rect2 = y_button2 - (button_height - text_height) / 2 + + pygame.draw.rect(surface.py_surface, colors["ivoire"], pygame.Rect(x_rect2, y_rect2, button_width, button_height)) + pygame.draw.rect(surface.py_surface, colors["Black"], + pygame.Rect(x_rect2 + 1, y_rect2 + 1, button_width - 2, button_height - 2)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect2 + 5, y_rect2 + 5, button_width - 10, button_height - 10)) + pygame.draw.rect(surface.py_surface, colors["darkblue"], + pygame.Rect(x_rect2 + 6, y_rect2 + 6, button_width - 12, button_height - 12)) + + surface.py_surface.blit(menu_button, (x_button2, y_button2)) + + if pygame.Rect(x_rect1, y_rect1, button_width, button_height).collidepoint(pygame.mouse.get_pos()): + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect1, y_rect1, button_width, button_height)) + pygame.draw.rect(surface.py_surface, colors["Black"], + pygame.Rect(x_rect1 + 1, y_rect1 + 1, button_width - 2, button_height - 2)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect1 + 5, y_rect1 + 5, button_width - 10, button_height - 10)) + pygame.draw.rect(surface.py_surface, colors["Volkswagen Taupe"], + pygame.Rect(x_rect1 + 6, y_rect1 + 6, button_width - 12, button_height - 12)) + + surface.py_surface.blit(play_again_button, (x_button1, y_button1)) + if pygame.mouse.get_pressed()[0]: + game.cursor = game.last_level + game.stage = "Launched" + + if pygame.Rect(x_rect2, y_rect2, button_width, button_height).collidepoint(pygame.mouse.get_pos()): + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect2, y_rect2, button_width, button_height)) + pygame.draw.rect(surface.py_surface, colors["Black"], + pygame.Rect(x_rect2 + 1, y_rect2 + 1, button_width - 2, button_height - 2)) + pygame.draw.rect(surface.py_surface, colors["ivoire"], + pygame.Rect(x_rect2 + 5, y_rect2 + 5, button_width - 10, button_height - 10)) + pygame.draw.rect(surface.py_surface, colors["Volkswagen Taupe"], + pygame.Rect(x_rect2 + 6, y_rect2 + 6, button_width - 12, button_height - 12)) -def draw_end_menu(surface): - x_position = (surface.width-width)/2 - y_position = (surface.height-height)/2 - pygame.draw.rect(surface.surface,colors["darkblue"],pygame.Rect(x_position,y_position,width,height)) - - # Victory - font_victory = pygame.font.Font("assets/fonts/GamepauseddemoRegular-RpmY6.otf", 80) - victory = font_victory.render("VICTORY", True, colors["white_yellow"]) - - # info 1 : "to play again press r" - font_info1 = pygame.font.Font("assets/fonts/GamepauseddemoRegular-RpmY6.otf", 50) - info1 = font_info1.render("To play again press R", True, colors["white_yellow"]) - - # info 2 : "to return to the main menu press M" - font_info2 = pygame.font.Font("assets/fonts/GamepauseddemoRegular-RpmY6.otf", 50) - info2 = font_info2.render("To return to the main menu press M", True, colors["white_yellow"]) - - # blit - surface.surface.blit(victory, (x_position+(width-victory.get_width())/2,y_position + 50)) - surface.surface.blit(info1, (x_position+(width-info1.get_width())/2,y_position + 200)) - surface.surface.blit(info2, (x_position+(width-info2.get_width())/2,y_position + 250)) - -#continuer = True -#while continuer : -# surface.clear(colors["darkblue"]) -# draw_end_menu(surface) -# flip() -# for event in pygame.event.get(): -# if event.type == pygame.QUIT: -# continuer = False + surface.py_surface.blit(menu_button, (x_button2, y_button2)) + if pygame.mouse.get_pressed()[0]: + game.stage = "Main Menu" diff --git a/render/draw_player.py b/render/draw_player.py index 0badb30f83be84f92a604212b950c200ef5a7a57..232aa7867dcf1f43bd5c3adaa00227fee3bc38b7 100644 --- a/render/draw_player.py +++ b/render/draw_player.py @@ -7,36 +7,26 @@ from level.obstacle import pixel_size draw_player is called upon to reprsent the player at all times for the viewer. """ -blur_length = 4 precision = 5 -positions = [] - -cursor = 0 def draw_player(player, surface): - global blur_length, positions, cursor, precision + global precision - if len(positions) != blur_length: - positions.append(player.render_position) - else: + if len(player.last_positions) == player.record_length: blur = pygame.Surface((pixel_size, pixel_size)) pygame.draw.rect(blur, (player.color[0] / 20, player.color[1] / 20, player.color[2] / 20), pygame.Rect(0, 0, pixel_size, pixel_size)) - for k in range(blur_length - 1): - initial = positions[k] - final = positions[k + 1] + for k in range(player.record_length - 1): + initial = player.last_positions[k] + final = player.last_positions[k + 1] delta = (final - initial) / precision for i in range(precision): blur_pos = initial + delta * i surface.blit(blur, (blur_pos[0], blur_pos[1]), special_flags=pygame.BLEND_RGB_ADD) - positions[cursor * 1] = player.render_position - - cursor = (cursor + 1) % blur_length - blur_surface = pygame.Surface((pixel_size, pixel_size)) pygame.draw.rect(blur_surface, (player.color[0] / 2, player.color[1] / 2, player.color[2] / 2), pygame.Rect(0, 0, pixel_size, pixel_size)) diff --git a/sound.py b/sound.py index 0218bdf5895afa3c011ed9a7bca9ee9c6980d229..f9f8799c7826786df86d9d6baba49d0e69b1c490 100644 --- a/sound.py +++ b/sound.py @@ -19,3 +19,9 @@ def sound_swipe(): def sound_background(): pass + +def sound_button(): + pass + +def sound_game_launched(): + pass \ No newline at end of file