Exemplo n.º 1
0
    def __init__(self, pygame, res, surface, size, gameclock, game_manager):
        Screen.__init__(self, pygame, res, surface)

        # set up initial variables
        self.need_reset = False
        self.size = size
        self.result = 0
        self.i = 1
        self.coinlist = []
        self.gameclock = gameclock
        self.game_manager = game_manager
        self.timer = 0
        self.cart = Cart(res, self.size, surface)

        # set up texts
        self.time_text = res.basicFont.render('TIMER:', True, res.BLACK,
                                              res.WHITE)
        self.textbox = self.time_text.get_rect(center=(900, 170))
        self.point_text = res.basicFont.render('POINTS:', True, res.BLACK,
                                               res.WHITE)
        self.pointbox = self.point_text.get_rect(center=(100, 170))
        self.display_time = res.basicFont.render('0', True, res.BLACK,
                                                 res.WHITE)
        self.timebox = self.display_time.get_rect(center=(900, 200))
        self.score = res.basicFont.render(str(self.cart.points), True,
                                          res.BLACK, res.WHITE)
        self.scorebox = self.score.get_rect(center=(100, 200))
Exemplo n.º 2
0
 def __init__(self, pygame, res, surface, game_manager):
     Screen.__init__(self, pygame, res, surface)
     self.game_manager = game_manager
     self.font = pygame.font.SysFont('cambria', 60)
     self.font2 = pygame.font.SysFont('cambria', 30)
     self.buttons['Restart'] = Button(pygame, res, surface,
                                      [20, 290, 300, 50], "Restart")
     self.buttons['Back'] = Button(pygame, res, surface, [20, 360, 300, 50],
                                   "Back")
Exemplo n.º 3
0
 def __init__(self, pygame, res, surface):
     Screen.__init__(self, pygame, res, surface)
     self.font = pygame.font.SysFont('cambria', 60)
     self.font2 = pygame.font.SysFont('cambria', 30)
     self.buttons['Start Game'] = Button(pygame, res, surface,
                                         [20, 150, 300, 50], "Start Game")
     self.buttons['Tutorial'] = Button(pygame, res, surface,
                                       [20, 220, 300, 50], "Tutorial")
     self.buttons['Settings'] = Button(pygame, res, surface,
                                       [20, 290, 300, 50], "Settings")
     self.buttons['Exit'] = Button(pygame, res, surface, [20, 360, 300, 50],
                                   "Exit")
Exemplo n.º 4
0
def run_game():
    pygame.init()
    game_settings = Settings()
    screen = Screen(game_settings)
    pygame.display.set_caption("BOMBERMAN")
    character = Character(game_settings, screen.screen, (0, 0))
    character2 = Character(game_settings, screen.screen, (1, 1))
    bombs_handler = BombsHandler(Group(), Group())
    obstacles = Group()
    hard_obstacles = Group()
    explosions = Group()
    treasures = Group()
    obstacle_placer = ObstaclePlacer()
    obstacle_placer.create_obstacles(game_settings, screen.screen, obstacles)
    obstacle_placer.create_hard_obstacles(game_settings, screen.screen,
                                          hard_obstacles)
    joystick = Joystick()
    smile_of_fate = SmileOfFate(game_settings)
    latest_choices = (0, 0)
    controller = Controller()
    while True:
        pygame.event.pump()
        controller.check_events(game_settings, screen.screen, character,
                                bombs_handler.bombs[0], character2,
                                bombs_handler.bombs[1])
        character.update(obstacles, hard_obstacles)
        if joystick.is_joystick():
            latest_choices = controller.check_joystick_events(
                character2, joystick.is_joystick(), latest_choices)
        character2.update(obstacles, hard_obstacles)
        bombs_handler.update_bombs(bombs_handler.bombs[0], game_settings,
                                   screen.screen, explosions, obstacles,
                                   treasures, smile_of_fate)
        bombs_handler.update_bombs(bombs_handler.bombs[1], game_settings,
                                   screen.screen, explosions, obstacles,
                                   treasures, smile_of_fate)
        bombs_handler.kill_your_heroes(explosions, character, character2)
        if len(obstacles.sprites()) < 5:
            treasures.empty()
            character.reset_character_status()
            character2.reset_character_status()
            obstacle_placer.create_obstacles(game_settings, screen.screen,
                                             obstacles)
        smile_of_fate.player_collected_treasure(character, treasures)
        smile_of_fate.player_collected_treasure(character2, treasures)
        screen.update_screen(game_settings, character, obstacles,
                             bombs_handler.bombs[0], character2,
                             bombs_handler.bombs[1], hard_obstacles,
                             explosions, treasures)
Exemplo n.º 5
0
    def create_entities(self):
        screen = Screen(self.get_width(), self.get_height())
        screen.fill_screen((0, 0, 0))

        mid_line = pygame.Surface((5, self.get_height()))
        mid_line.fill((255, 255, 255))

        count_down_font = pygame.font.SysFont("Comic Sans MS", 100)
        player_one_score = 0
        player_two_score = 0

        screen = Screen(self.get_width(), self.get_height())
        screen.fill_screen((0, 0, 0))

        mid_line = pygame.Surface((5, self.get_height()))
        mid_line.fill((255, 255, 255))

        ball = Ball(screen.screen, 10)

        paddle_one = Paddle(screen, 20, 50)
        paddle_two = Paddle(screen, 960, 50)

        entities = {
            "screen": screen,
            "paddle_one": paddle_one,
            "paddle_two": paddle_two,
            "ball": ball,
            "player_one_score": player_one_score,
            "player_two_score": player_two_score,
            "mid_line": mid_line,
            "width": self.get_width(),
            "height": self.get_height(),
            "count_down_font": count_down_font
        }

        return entities
Exemplo n.º 6
0
def main():
    # 播放背景音乐,接收该参数,-1表示无限循环(默认循环播放一次)
    pygame.mixer.music.play(-1)
    # 创建主体窗口对象
    window = Screen()
    # 创建豌豆对象
    pea = Pea(window)
    # 创建一个时钟,优化运行速度的效果
    clock = pygame.time.Clock()

    while True:
        """
        1、设置游戏的主体窗口
        """
        # 填充背景色为黑色,因为豌豆在拖动时会留下拖动痕迹
        window.screen.fill((0, 0, 0))
        # 设置窗体的背景图片
        window.screen.blit(window.scale_background_image, window.scale_background_image_rect)

        """
        2、显示豌豆
        """
        # 显示豌豆
        pea.display()

        """
        3、事件监听处理,豌豆移动
        """
        # 创建事件对象
        control = Control()
        # 调用事件处理
        control.key_control(pea)

        # 豌豆上下移动
        if pea.is_move_up:
            pea.move_up()
        if pea.is_move_down:
            pea.move_down()

        """
        4、显示炮弹
        """
        # 每隔一段时间创建炮弹
        Bullet.interval += 1
        if pea.is_shout and Bullet.interval >= 15:
            Bullet.interval = 0
            pea.bullet_shout(window)

        for bullet in Bullet.bullet_list:
            # 炮弹显示
            bullet.display()
            # 炮弹移动
            bullet.move()

        """
        5、显示僵尸
        """
        # 每隔一段时间创建僵尸
        Zombie.interval += 1
        if Zombie.interval >= 15:
            Zombie.interval = 0
            Zombie.zombie_list.append(Zombie(pea, window))

        # 显示所有的僵尸
        for zombie in Zombie.zombie_list:
            # 僵尸显示
            zombie.display()
            # 僵尸移动
            zombie.move()

        # 更新图片
        pygame.display.update()
        # 帧频率
        clock.tick(60)
Exemplo n.º 7
0
 def __init__(self, pygame, res, surface):
     Screen.__init__(self, pygame, res, surface)
     self.font = pygame.font.SysFont('cambria', 60)
     self.font2 = pygame.font.SysFont('cambria', 30)
     self.buttons['Back'] = Button(pygame, res, surface, [20, 360, 300, 50],
                                   "Back")
Exemplo n.º 8
0
import pygame
from pygame import Rect

from src.application import Application
from src.screen import Screen
from src.widgets.button import Button

screen = Screen((500, 500))
app = Application("My cute application", 30)

btn = Button(Rect(0, 0, 50, 50), screen)
btn.connect(pygame.MOUSEBUTTONUP, lambda e: print("Hello"))

app.set_screen(screen)

app.run()
Exemplo n.º 9
0
import pygame
from src.menu import Menu, Button
from src.screen import Screen
from src.game import Game


def runGame(screen, tutorialMenu, fakeNewsMenu):
    game = Game(screen, tutorialMenu, fakeNewsMenu)
    game.run(screen)


pygame.init()

screen = Screen((1920, 1080), "Stop the count!", fullScreen=False)

tutorialMenu = Menu(pygame.image.load("assets/img/buildWall.jpg"), [], True)
button_quitMenu = Button((10, 10), (60, 60), "Back", tutorialMenu.stop)
button_quitMenu.build(screen)
tutorialMenu.buttons.append(button_quitMenu)

fakeNewsMenu = Menu(pygame.image.load("assets/img/fakeNews.jpg"), [], True)
button_quitMenu = Button((10, 10), (60, 60), "Back", fakeNewsMenu.stop)
button_quitMenu.build(screen)
fakeNewsMenu.buttons.append(button_quitMenu)

button_play = Button((300, 400), (300, 60),
                     "Play",
                     runGame,
                     screen=screen,
                     tutorialMenu=tutorialMenu,
                     fakeNewsMenu=fakeNewsMenu)