Exemplo n.º 1
0
Arquivo: main.py Projeto: Luc4r/Rectov
def main():
  # Get JSON data:
  colors = getDataFromJSON("src/config/colors.json")
  scores = getDataFromJSON("src/data/scores.json")
  # Init game window
  pygame.init()
  pygame.display.set_caption("Rectov")
  screen = pygame.display.set_mode((1280, 720))
  screen.fill(colors["background"])
  # Main file objects
  transition = TransitionSurface(screen, colors)
  menu = Menu(screen, colors, scores)
  game = Game(screen, transition, colors, main)
  tutorial = Tutorial(screen, transition, colors, main)
  # Transition
  transition.fadeIn(background_function=menu.draw)
  # Display menu until user selects "play game" option
  while not menu.is_game_running and not menu.is_tutorial_running:
    # Draw menu
    menu.draw()
    # Update screen
    pygame.display.update()
  # Transition
  transition.fadeOut(background_function=menu.draw)
  # Initialize game
  if menu.is_game_running:
    game.start()
  # Initialize tutorial
  elif menu.is_tutorial_running:
    tutorial.start()
Exemplo n.º 2
0
def saveResultToJSON(new_result):
    path = "src/data/scores.json"
    scores_limit = 1000
    data = getDataFromJSON("src/data/scores.json")

    data_new = [new_result]
    if data:
        data.append(new_result)
        data_sorted = sorted(data,
                             key=operator.itemgetter('score'),
                             reverse=True)
        data_new = data_sorted[:scores_limit]

    with open(path, "w") as json_file:
        json.dump(data_new, json_file)
Exemplo n.º 3
0
 def __init__(self, screen, colors, camera, solid_tiles, walls, platforms,
              coins, enemies, finish, player, player_info, level_name):
     # Passed attributes
     self.screen = screen
     self.colors = colors
     self.camera = camera
     self.solid_tiles = solid_tiles
     self.walls = walls
     self.platforms = platforms
     self.coins = coins
     self.enemies = enemies
     self.finish = finish
     self.player = player
     self.player_info = player_info
     # Class attributes
     self.tiles_sheet = SpriteSheet(self.screen,
                                    self.colors,
                                    file_name="tiles.png",
                                    scaled_sprite_width=40,
                                    scaled_sprite_height=40)
     self.level_data = getDataFromJSON(
         "src/levels/{}.json".format(level_name))
     self.is_tutorial = "tutorial" in level_name
Exemplo n.º 4
0
Arquivo: Game.py Projeto: Luc4r/Rectov
import time
import pygame

from src.components.LoadingScreen import LoadingScreen
from src.components.EndGameScreen import EndGameScreen
from src.components.PauseScreen import PauseScreen
from src.components.UserInterface import UserInterface
from src.components.Level import Level
from src.components.Player import Player
from src.components.Camera import Camera

from src.utils.getDataFromJSON import getDataFromJSON
from src.utils.sleepWithDrawing import sleepWithDrawing

levels_data = getDataFromJSON("src/levels/levels-data.json")
clock = pygame.time.Clock()


class Game:
    def __init__(self, screen, transition, colors, quit_game):
        # Passed attributes
        self.screen = screen
        self.transition = transition
        self.colors = colors
        self.quit_game = quit_game
        # Class attributes
        self.level = levels_data["game"][0]  # starting level -> index 0
        self.game_info = {"pause": False}
        self.player_info = {
            "spawn": self.level["playerSpawnPoint"],
            "alive": True,
Exemplo n.º 5
0
import os
import pygame

from src.utils.getDataFromJSON import getDataFromJSON

textures_data = getDataFromJSON("src/config/texturesData.json")


class SpriteSheet:
    def __init__(self,
                 screen,
                 colors,
                 file_name,
                 scaled_sprite_width=None,
                 scaled_sprite_height=None):
        # Passed attributes
        self.screen = screen
        self.colors = colors
        self.file_name = file_name.split(".")[0]
        self.sprite_width = (scaled_sprite_width if scaled_sprite_width else
                             textures_data[self.file_name]["width"])
        self.sprite_height = (scaled_sprite_height if scaled_sprite_height else
                              textures_data[self.file_name]["height"])
        # Variables used to calculate sprites data
        columns = textures_data[self.file_name]["columns"]
        rows = textures_data[self.file_name]["rows"]
        total_sprites = columns * rows
        # Class attributes
        self.sheet = pygame.transform.scale(
            pygame.image.load(os.path.join("src", "img",
                                           file_name)).convert_alpha(),