Exemple #1
0
    def __init__(self):
        pg.init()
        pg.font.init()
        pg.display.set_caption("TETRIS")

        self.sound_manager = SoundManager()
        pg.mixer.music.load("Sounds/Music.mp3")
        pg.mixer.music.set_volume(0.3)
        pg.mixer.music.play(-1)

        self.main_surface = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        self.playground_surf = pg.Surface(
            (GRID_SIZE[0] * CELL_SIZE * UI_SCALE,
             GRID_SIZE[1] * CELL_SIZE * UI_SCALE))
        self.next_surf = pg.Surface((220 * UI_SCALE, 220 * UI_SCALE))

        self.font = pg.font.Font("Fonts/ARCADECLASSIC.TTF",
                                 int(FONT_SIZE * UI_SCALE))

        if "top.scr" in os.listdir():
            with open("top.scr") as file:
                self.top = int(file.read())
        else:
            self.top = 0

        self.score = 0
        self.lines = 0

        self.colors = np.zeros(GRID_SIZE, dtype=object)
        self.grid_colliders = np.zeros(GRID_SIZE)

        self.cur_shape = Shape(self, 5, -1)
        self.next_shape = Shape(self, 5, -1)

        self.game_over = False
Exemple #2
0
    def __init__(self, resolution, level):
        super().__init__()
        self.sound = SoundManager()
        self.resolution = resolution
        self.state = res.STATE_RUNNING
        self.life = 3
        self.level = level
        self.standard_shader = StandardShaderProgram()
        self.delta = 0.00001
        self.light_setup = res.LightSetup(
            global_ambient=glm.vec3(0.3, 0.3, 0.3))
        self.controls = res.GameControlState()
        self.model_registry = res.ModelRegistry()
        self.camera_id = 0
        self.view_matrix = glm.mat4(1.0)
        self.maze_width = 30
        self.maze_length = 30
        self.maze = _setup_maze(self,
                                self.maze_width,
                                self.maze_length,
                                depth=1.5)

        self._setup_systems()
        self._setup_entities()
        self._setup_level_objects()
        self.update_resolution(resolution)
Exemple #3
0
def main():

    sm = SceneManager()
    sm.instantiate(sm)

    snd_mngr = SoundManager()
    snd_mngr.instantiate(snd_mngr)

    pl = Player('player.png', 400)
    pl.event.register_listener(snd_mngr.event_listener)
    pl.instantiate(pl, pygame.math.Vector2(0, 0), 0)

    item = Item()
    item.event.register_listener(pl.event_listener)
    item.instantiate(item)

    while (True):
        display.screen.fill((0, 50, 0))
        gb.updateAll()

        event = pygame.event.poll()
        if event.type == pygame.QUIT:
            break

        #text = text_field.create_text("Hello, World", ["comicsansms"], 72, (0, 128, 0))

        #display.screen.blit(text,
        #(320 - text.get_width() // 2, 240 - text.get_height() // 2))

        pygame.display.flip()
        utils.clock.tick(60)
Exemple #4
0
 def __init__(self):
     pygame.init()
     pygame.mixer.music.load('sounds/IDKMAN.wav')
     self.screen = pygame.display.set_mode(
         (800, 600)
     )
     pygame.display.set_caption('PacMan Portal')
     self.clock = pygame.time.Clock()
     self.score_keeper = ScoreController(screen=self.screen,
                                         sb_pos=((self.screen.get_width() // 5),
                                                 (self.screen.get_height() * 0.965)),
                                         items_image='cherry.png',
                                         itc_pos=(int(self.screen.get_width() * 0.6),
                                                  self.screen.get_height() * 0.965))
     self.maze = Maze(screen=self.screen, maze_map_file='maze_map.txt')
     self.life_counter = PacManCounter(screen=self.screen, ct_pos=((self.screen.get_width() // 3),
                                                                   (self.screen.get_height() * 0.965)),
                                       images_size=(self.maze.block_size, self.maze.block_size))
     self.level_transition = LevelTransition(screen=self.screen, score_controller=self.score_keeper)
     self.game_over = True
     self.pause = False
     self.player = PacMan(screen=self.screen, maze=self.maze)
     self.ghosts = pygame.sprite.Group()
     self.ghost_sound_manager = SoundManager(sound_files=['RunForestRun.wav', 'Eaten3.wav', 'babySharkPacman.wav'],
                                             keys=['blue', 'eaten', 'std'],
                                             channel=Ghost.GHOST_AUDIO_CHANNEL)
     self.ghost_active_interval = 2500
     self.ghosts_to_activate = None
     self.first_ghost = None
     self.other_ghosts = []
     self.spawn_ghosts()
     self.actions = {PacManPortalGame.START_EVENT: self.init_ghosts,
                     PacManPortalGame.REBUILD_EVENT: self.rebuild_maze,
                     PacManPortalGame.LEVEL_TRANSITION_EVENT: self.next_level}
Exemple #5
0
    def load(self):
        self.sprite_group = Group()

        self.label_font = self.res.font64
        self.button_play = Button(
            self.res, ((WIDTH - self.res.image_button.get_width()) / 2, 240),
            'Играть', self.sprite_group)
        self.button_drift = Button(
            self.res, ((WIDTH - self.res.image_button.get_width()) / 2, 300),
            'Дрифт', self.sprite_group)
        self.button_shop = Button(
            self.res, ((WIDTH - self.res.image_button.get_width()) / 2, 360),
            'Магазин', self.sprite_group)
        self.button_exit = Button(
            self.res, ((WIDTH - self.res.image_button.get_width()) / 2, 420),
            'Выход', self.sprite_group)

        self.dollars = Dollars(self.res, self.sprite_group)
        self.sm = SoundManager(None, None)
        self.sm.set_background(self.res.music_bg_menu, 0.3)

        # Задний фон для меню
        self.world = b2World()
        self.world.gravity = 0, 0
        self.contact_listener = ContactListener()
        self.world.contactListener = self.contact_listener
        self.obj_args = self.world, self.contact_listener, self.res
        self.animation_background = pygame.Surface((500, 300)).convert_alpha()
        self.animation_background.fill((0, 0, 0, 0))
        self.background_group = Group()
        self.spawn_random_car()
        self.spawn_timer = 0
        self.spawn_timeout = 1.5
        self.spawn_counter = 0
        self.background_camera = Camera(self.background_group)
Exemple #6
0
def main():
    GameData(SCREEN_TITLE)
    # SpriteCache()
    GameData.data['player_level'] = 1
    GameData.data['player_xp'] = 0
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
    sound_manager = SoundManager(window)
    loading_view = menu_views.LoadingMenuView(window, sound_manager)
    window.show_view(loading_view)
    arcade.run()
Exemple #7
0
 def __init__(self, root):
     self.root = root
     self.canvas = Canvas(master=self.root.root, width=448, height=448)
     self.canvas.pack(side=TOP)
     self.canvas.bind('<Motion>', self.motion)
     #self.canvas.bind('<MouseWheel>', self.zoom)
     self.canvas.bind('<Button-1>', self.click)
     self.canvas.bind('<B1-Motion>', self.click)
     self.has_image = False
     self.zoom_level = 0
     self.sound = SoundManager()
 def __init__(self, screen, score_controller, transition_time=5000):
     self.screen = screen
     self.score_controller = score_controller
     self.sound = SoundManager(['pacman-beginning.wav'], keys=['transition'],
                               channel=LevelTransition.TRANSITION_CHANNEL, volume=0.6)
     self.font = pygame.font.Font('fonts/LuckiestGuy-Regular.ttf', 32)
     self.ready_msg = self.font.render('Get Ready!', True, ScoreBoard.SCORE_WHITE)
     self.ready_msg_rect = self.ready_msg.get_rect()
     ready_pos = screen.get_width() // 2, int(screen.get_height() * 0.65)
     self.ready_msg_rect.centerx, self.ready_msg_rect.centery = ready_pos
     self.level_msg = None
     self.level_msg_rect = None
     self.transition_time = transition_time     # total time to wait until the transition ends
     self.transition_begin = None
     self.transition_show = False
 def __init__(self, screen, user, maze):
     self.screen = screen
     self.maze = maze
     self.user = user
     self.sound_manager = SoundManager(
         sound_files=['portal-open.wav', 'portal-travel.wav'],
         keys=['open', 'travel'],
         channel=PortalController.PORTAL_AUDIO_CHANNEL)
     self.blue_portal = pygame.sprite.GroupSingle(
     )  # portals as GroupSingle, which only allows one per group
     self.blue_projectile = None
     self.orange_portal = pygame.sprite.GroupSingle()
     self.orange_projectile = None
     # converter for projectile direction to portal direction
     self.portal_directions = {'l': 'r', 'r': 'l', 'u': 'd', 'd': 'u'}
Exemple #10
0
 def __create_game(self, gender, name, loadLast):
     self.started = True
     self.__clock = pygame.time.Clock()
     self.__sound_manager = SoundManager()
     app_loader = AppLoader(gender, name)
     bars_loader = app_loader.get_status_bars_loader()
     self.__game_man = app_loader.get_game_manager()
     if loadLast: self.load_game()
     # windows_controller asociado al screen
     self.windows_controller = SaludameWindowsController(
         self.__screen, self.__game_man)
     self.windows_controller.create_windows_and_activate_main(
         app_loader, self.__clock, bars_loader)
     #self.hotkeys_handler = HotKeyHandler()
     self.__game_man.start(self.windows_controller)
Exemple #11
0
    def load(self):
        super().load()

        self.button = Button(self.res, (WIDTH - 120, HEIGHT - 70), 'Меню',
                             self.sprite_group)
        self.minimap = Minimap(300, 240, self.sprite_group)
        self.conversation = Conversation(self.res, self.sprite_group)
        self.police_effect = PoliceEffect(self.sprite_group)

        self.sm = SoundManager(self.conversation, self.car, self.sprite_group)
        self.load_map(self.res.drift_map_path)
        self.sm.player_car = self.car
        self.sm.set_background(self.res.music_bg_menu, 0.1)

        self.car.queue_lines.extend(['Свободный режим'])
    def __init__(self, screen, maze):
        super().__init__()
        self.screen = screen
        self.radius = maze.block_size // 5
        self.maze = maze
        self.sound_manager = SoundManager(sound_files=['pacman-pellet-eat.wav', 'pacman-fruit-eat.wav',
                                                       'pacman-killed.wav', 'pacman-portal.wav'],
                                          keys=['eat', 'fruit', 'dead', 'portal'],
                                          channel=PacMan.PAC_AUDIO_CHANNEL)
        self.horizontal_images = ImageManager('pacman-horiz.png', sheet=True, pos_offsets=[(0, 0, 32, 32),
                                                                                           (32, 0, 32, 32),
                                                                                           (0, 32, 32, 32),
                                                                                           (32, 32, 32, 32),
                                                                                           (0, 64, 32, 32)],
                                              resize=(self.maze.block_size, self.maze.block_size),
                                              reversible=True)
        self.vertical_images = ImageManager('pacman-vert.png', sheet=True, pos_offsets=[(0, 0, 32, 32),
                                                                                        (32, 0, 32, 32),
                                                                                        (0, 32, 32, 32),
                                                                                        (32, 32, 32, 32),
                                                                                        (0, 64, 32, 32)],
                                            resize=(self.maze.block_size, self.maze.block_size),
                                            reversible=True)
        self.death_images = ImageManager('pacman-death.png', sheet=True, pos_offsets=[(0, 0, 32, 32),
                                                                                      (32, 0, 32, 32),
                                                                                      (0, 32, 32, 32),
                                                                                      (32, 32, 32, 32),
                                                                                      (0, 64, 32, 32),
                                                                                      (32, 64, 32, 32)],
                                         resize=(self.maze.block_size, self.maze.block_size),
                                         animation_delay=150, repeat=False)
        self.flip_status = {'use_horiz': True, 'h_flip': False, 'v_flip': False}
        self.spawn_info = self.maze.player_spawn[1]
        self.tile = self.maze.player_spawn[0]
        self.direction = None
        self.moving = False
        self.speed = maze.block_size // 7
        self.image, self.rect = self.horizontal_images.get_image()
        self.rect.centerx, self.rect.centery = self.spawn_info   # screen coordinates for spawn
        self.dead = False
        self.portal_controller = PortalController(screen, self, maze)   # controller object for portal

        # Keyboard related events/actions/releases
        self.event_map = {pygame.KEYDOWN: self.perform_action, pygame.KEYUP: self.reset_direction}
        self.action_map = {pygame.K_UP: self.set_move_up, pygame.K_LEFT: self.set_move_left,
                           pygame.K_DOWN: self.set_move_down, pygame.K_RIGHT: self.set_move_right,
                           pygame.K_q: self.blue_portal, pygame.K_w: self.orange_portal}
Exemple #13
0
    def load(self):
        self.levels = Level.levels
        self.level = self.levels[self.asm.main.completed_levels]
        self.is_over = False
        self.saved = False
        self.over_timer = 0
        self.over_timeout = 1
        self.text = self.level[1]

        super().load()

        self.button = Button(self.res, (WIDTH - 120, HEIGHT - 70), 'Меню',
                             self.sprite_group)
        self.minimap = Minimap(300, 240, self.sprite_group)
        self.conversation = Conversation(self.res, self.sprite_group)
        self.police_effect = PoliceEffect(self.sprite_group)
        self.energy_line = EnergyLine(self.res, self.sprite_group)
        self.dollars = Dollars(self.res, self.sprite_group, level=True)

        self.sm = SoundManager(self.conversation, self.car, self.sprite_group)
        self.load_map(self.level[0])
        self.sm.player_car = self.car
        self.sm.set_background(self.res.music_bg_game, 0.1)
Exemple #14
0
    def start(self):
        #spawn initial GameObjects here like so:
        self._game.instantiate(
            Background(self._game, "Background", "background.png", 0, 0))
        self._game.instantiate(
            SoundManager(self._game, "SoundManager", "unknown.png", -1, -1))
        self._game.instantiate(
            UIManager(self._game, "UIManager", "unknown.png", -1, -1))
        self.soundManager = self._game.getGameObjectByName("SoundManager")
        self.uiManager = self._game.getGameObjectByName("UIManager")

        #Music is here but I've disabled it for now
        #self.soundManager.play_music("background.wav")

        self._game.instantiate(
            Player(self._game, "Player", "player.png", 100, 500))
        self.player = self._game.getGameObjectByName("Player")

        for i in range(0, 9):
            self._game.instantiate(
                Enemy(self._game, "Enemy", "enemy.png", 80 * i, 50))

        self.scoreFont = pygame.font.Font('freesansbold.ttf', 16)
        self.gameOverFont = pygame.font.Font('freesansbold.ttf', 64)
Exemple #15
0
            if closed_counter % fps == 0 and closed_counter > 0:
                if prev_closed_counter < closed_counter:
                    sleep_frames = fps
                    closed_counter = 0
                    open_counter = 0

            closed_counter = max(closed_counter, 0)
            open_counter = max(open_counter, 0)

            # print('[open, closed, ratio] - [%s, %s, %s]' % (open_counter, closed_counter, ratio))

        frame_with_msg = new_frame
        # add a sleeping warning to the frame
        if sleep_frames > 0:
            if sleep_frames == fps:
                SoundManager(sleep_detected=True)
            cv2.putText(new_frame, 'Sleeping', (80, 350),
                        cv2.FONT_HERSHEY_SIMPLEX, 4, (0, 0, 255), 2,
                        cv2.LINE_AA)
            sleep_frames -= 1
        elif yawn_frames > 0:
            if yawn_frames == fps:
                SoundManager(sleep_detected=False)
            cv2.putText(new_frame, 'Drowsing', (80, 350),
                        cv2.FONT_HERSHEY_SIMPLEX, 4, (0, 140, 255), 2,
                        cv2.LINE_AA)
            yawn_frames -= 1

        cv2.imshow('frame', new_frame)

        frames.append(new_frame)
Exemple #16
0
import pygame
import GLOBALS
from sound_manager import SoundManager
from farm_game import FarmGame
from utils import init_screen

if __name__ == "__main__":
    pygame.init()
    pygame.font.init()
    GLOBALS.SCREEN_RES = (800, 600)
    screen = init_screen(GLOBALS.SCREEN_RES[0], GLOBALS.SCREEN_RES[1])
    pygame.display.set_caption('Trees and Boxes')

    GLOBALS.SOUND = SoundManager()

    try:
        game = FarmGame()
        game.run()
    except:
        pygame.quit()
        raise
Exemple #17
0
from constants import *
from camera import Camera
from player import Player
from level import Level
from lava import Lava
from configuration import Configuration
from sound_manager import SoundManager

pygame.init()
timer = pygame.time.Clock()

surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_icon(pygame.image.load('assets/gameicon.png'))
pygame.display.set_caption('Speluncraft without craft')

sound_manager = SoundManager()
conf = Configuration()

level = Level(CELL_SIZE, LEVEL_INITIAL_ROWS, LEVEL_INITIAL_COLS)
player = Player(level, 0, PLAYER_SPAWN_POSITION_COL * CELL_SIZE, (SURFACE_LEVEL - 1 )* CELL_SIZE)
lava = Lava()
camera = Camera()

font = pygame.font.SysFont("Verdana", 30)
font_instructions = pygame.font.SysFont("Verdana", 16)

mousex = 0
mousey = 0

player_score = 0
Exemple #18
0
MAIN_HERO = None
NOW_LEVEL = None
KOL_LEVELS = 8  # количество уровней

# параметры героев (урон, скорость, здоровье)
hero_parameters = namedtuple('hero_parameters', 'damage speed health')
# name: (damage, speed, health)
HEROES = {
    'Ninja Frog': hero_parameters(15, 6, 100),
    'Pink Man': hero_parameters(20, 5, 120),
    'Virtual Guy': hero_parameters(15, 7, 95),
    'Mask Dude': hero_parameters(15, 6, 100)
}

clock = pygame.time.Clock()
# группы спрайтов
all_sprites = pygame.sprite.Group()
bullets_group = pygame.sprite.Group()
checkpoints = pygame.sprite.Group()
player_group = pygame.sprite.Group()
fruits_group = pygame.sprite.Group()
backpacks_group = pygame.sprite.Group()
enemies_group = pygame.sprite.Group()
potions_group = pygame.sprite.Group()
chameleons = pygame.sprite.Group()
spikes_group = pygame.sprite.Group()
platforms = pygame.sprite.Group()

sound_manager = SoundManager()  # звуковой класс