Пример #1
0
 def add_scores(self):
     picked_one = False
     x = self.scene.game.game_resolution.x / 2 - 120
     y = self.scene.game.game_resolution.y / 2 - 70
     label = text.Text("Top Scores",
                       "big",
                       V2(x - 60, y),
                       PICO_WHITE,
                       multiline_width=200)
     label.layer = 10
     label.visible = False
     self.highscores.append(label)
     self.scene.ui_group.add(label)
     places = [
         '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th',
         '10th'
     ]
     for i, score in enumerate(save.SAVE_OBJ.get_highscores()):
         color = PICO_WHITE
         if score == int(self.score) and not picked_one:
             color = PICO_YELLOW
             picked_one = True
         t1 = text.Text(places[i], "small", V2(x - 40, i * 18 + y + 20),
                        color)
         t1.offset = (1, 0)
         t1.layer = 10
         t1._recalc_rect()
         t2 = text.Text("%d" % score, "big", V2(x, i * 18 + y + 20), color)
         t2.layer = 10
         self.scene.ui_group.add(t1)
         self.scene.ui_group.add(t2)
         t1.visible = False
         t2.visible = False
         self.highscores.extend([t1, t2])
Пример #2
0
    def rebuild(self):
        for ci in self._controls:
            ci['control'].kill()
        self._controls = []

        self.add(SimpleSprite(V2(0, 0), "assets/shopgraphic.png"), V2(24, 0))
        self.add(Text("Shop", "logo", V2(0, 0), multiline_width=140),
                 V2(90, 12))

        btn = Button(V2(0, 0), "Done", "big", self.on_done, color=PICO_WHITE)
        self.add(btn, V2(310, 260) - V2(btn.width, btn.height))

        self.add(text.Text("O2", "small", V2(0, 0), PICO_LIGHTGRAY),
                 V2(210, 165))
        self.add(
            text.Text(get_time_string(game.Game.inst.run_info.o2), "big",
                      V2(0, 0), PICO_WHITE), V2(210, 175))

        self.add(text.Text("Credits", "small", V2(0, 0), PICO_LIGHTGRAY),
                 V2(210, 200))
        self.add(
            text.Text("%dC" % game.Game.inst.run_info.credits, "big", V2(0, 0),
                      PICO_WHITE), V2(210, 210))

        self.add_panel(V2(0, 0), self.store_data['offerings'][0])
        self.add_panel(V2(1, 0), self.store_data['offerings'][1])
        self.add_panel(V2(0, 1), self.store_data['offerings'][2])

        self.redraw()
        self.add_all_to_group(self.groups()[0])
Пример #3
0
    def add_score_part(self, name, score):
        x = self.scene.game.game_resolution.x / 2 - 90
        y = (len(self.score_parts) //
             2) * 24 + self.scene.game.game_resolution.y / 2 - 70
        tname = text.Text(name,
                          "small",
                          V2(x, y),
                          PICO_WHITE,
                          multiline_width=200,
                          shadow=PICO_BLACK)
        tname.layer = 10
        self.scene.ui_group.add(tname)
        self.score_parts.append(tname)
        tname.visible = False
        tname.initial_x = tname.x

        tscore = text.Text(str(score),
                           "small",
                           V2(x + 160, y),
                           PICO_YELLOW,
                           multiline_width=120,
                           shadow=PICO_BLACK)
        tscore.layer = 10
        self.scene.ui_group.add(tscore)
        self.score_parts.append(tscore)
        tscore.visible = False
        tscore.initial_x = tscore.x
Пример #4
0
 def setup_text(self):
     # Put any constantly updated text fields for the battle here
     self.x_name_text = text.Text('name',
                                  X_NAME_LOCATION,
                                  NAME_SIZE,
                                  NAME_COLOR,
                                  NAME_BG_COLOR,
                                  xy='x')
     self.y_name_text = text.Text('name',
                                  Y_NAME_LOCATION,
                                  NAME_SIZE,
                                  NAME_COLOR,
                                  NAME_BG_COLOR,
                                  xy='y')
     self.x_hp_text = text.Text('hp',
                                X_HP_LOCATION,
                                HP_SIZE,
                                HP_COLOR,
                                HP_BG_COLOR,
                                xy='x')
     self.y_hp_text = text.Text('hp',
                                Y_HP_LOCATION,
                                HP_SIZE,
                                HP_COLOR,
                                HP_BG_COLOR,
                                xy='y')
     self.message_text = text.Text('battle_message', MESSAGE_LOCATION,
                                   MESSAGE_SIZE, MESSAGE_COLOR,
                                   MESSAGE_BG_COLOR)
     self.text_objects = [
         self.x_name_text, self.y_name_text, self.x_hp_text, self.y_hp_text,
         self.message_text
     ]
Пример #5
0
def gameScene(state, screen, frameTime, gameClock, diff):
    """this is called when it's time to play the game,
returns the new screen state"""
    # set up player and the game map
    mapRect = pygame.rect.Rect(50, 50, 700, 500)
    player = snake.Snake()
    fruit = food.Food(player.bodyList)
    if diff == 0:
        cooldown = 100
    elif diff == 1:
        cooldown = 75
    elif diff == 2:
        cooldown = 50
    else:
        print("Difficulty selection failed, check the code")
    growSnake = False

    # initialises the score, as well as the font and the rect
    # which is used to define position and size of text (required for drawing)
    score = 0
    scoreText = text.Text("Score: " + str(score), color=(100, 0, 100))

    framesPerSec = text.Text()
    framesPerSec.rect.bottomleft = (0, 600)

    # main game loop of the game, only quits at change of game scene state
    while state == 1:

        frameTime += gameClock.tick(60)

        # logic updates
        if fruit.eaten(player):
            fruit.spawnFood()

            score += 10
            scoreText.text = "Score: " + str(score)

            growSnake = True

        # will only displace the snake if the cooldown is over
        if frameTime >= cooldown:
            growSnake, state = player.update(growSnake, state, mapRect)
            frameTime = 0

        framesPerSec.text = str(gameClock.get_fps())[:6]

        # drawing to the screen
        screen.fill((0, 150, 255))

        pygame.draw.rect(screen, (0, 0, 0), mapRect, 3)

        player.draw(screen)
        fruit.draw(screen)
        scoreText.draw(screen)
        framesPerSec.draw(screen)

        pygame.display.flip()

    return state, score
Пример #6
0
	def draw(self, surface):
		leftscore = str(self.getLeftScore())
		rightscore = str(self.getRightScore())
		leftText = text.Text(leftscore, self.mX, self.mY)
		leftText.setColor((255,255,255))
		leftText.draw(surface)
		rightText = text.Text(rightscore, self.mX + self.mWidth , self.mY)	
		rightText.setColor((255,255,255))
		rightText.draw(surface)
Пример #7
0
    def __init__(self, width, height):
        # Define length of game periods
        self.mSetupTime = Timer.FULL_SETUP_TIME
        self.mMatchTime = Timer.FULL_MATCH_TIME
        self.mEndGameTime = Timer.FULL_ENDMATCH_TIME

        # display dimensions
        self.mWidth = width
        self.mHeight = height

        # Wall-clock
        wall_size = int(self.mHeight * Timer.WALL_CLOCK_SIZE)
        self.mWallClock = text.Text("0:00 AM", int(0.95 * self.mWidth),
                                    self.mHeight - wall_size)
        self.mWallClock.setFont("latinmodernromancaps", wall_size)
        self.mWallClock.alignRight()

        # Round Number
        self.mRoundNumber = 0
        round_size = int(self.mHeight * Timer.ROUND_SIZE)
        self.mRoundNumberText = text.Text("Round: 0", int(0.05 * self.mWidth),
                                          self.mHeight - round_size)
        self.mRoundNumberText.setFont("latinmodernromancaps", round_size)
        self.mRoundNumberText.alignLeft()

        # Font selection and clock placement
        size = int(self.mHeight * Timer.MAIN_CLOCK_SIZE)
        y = int(0.50 * self.mHeight) - int(max(wall_size, round_size))
        self.mText = text.Text("0:00", int(0.50 * self.mWidth), y)
        self.mText.setFont("latinmodernromancaps", size)

        # Color selection
        self.mSetupBackground = (255, 255, 0)  # yellow
        self.mSetupColor = (0, 0, 0)

        self.mMatchBackground = (0, 255, 0)  # green
        self.mMatchColor = (0, 0, 0)

        self.mBackground = self.mSetupBackground

        self.mText.setColor(self.mSetupColor)
        self.mWallClock.setColor(self.mSetupColor)
        self.mRoundNumberText.setColor(self.mSetupColor)
        self.reset()
        self.setText()

        # beginning of match
        self.mStartSound = pygame.mixer.Sound("wav/start.wav")
        # end of match
        self.mEndSound = pygame.mixer.Sound("wav/end.wav")
        # 30 seconds to go sound
        self.mEndGameSound = pygame.mixer.Sound("wav/end-game.wav")
        # early termination
        self.mStopSound = pygame.mixer.Sound("wav/stop.wav")

        return
Пример #8
0
 def setup_text(self):
     self.text_objects = {}
     for text_type in TEXT_TYPES:
         if text_type in IMPORTANT_TYPES:
             self.text_objects[text_type] = text.Text(
                 text_type, LOCATIONS[text_type], TEXT_SIZE_IMPORTANT,
                 TEXT_COLOR_IMPORTANT, TEXT_BG)
         else:
             self.text_objects[text_type] = text.Text(
                 text_type, LOCATIONS[text_type], TEXT_SIZE_NORMAL,
                 TEXT_COLOR_NORMAL, TEXT_BG)
Пример #9
0
    def render(self):
        self.screen.fill((255, 255, 255))

        # drawing destination floor caption for every person in the building
        self.draw_captions()
        self.elevator.display_targets(self.screen)

        text.Text("use up and down arrow keys to move, space to load and unload people and have fun :D", 160, 30).draw(self.screen)
        text.Text("press 'r' to restart and spawn a new building", 350, 60).draw(self.screen)
        text.Text("oh, and you can press 'escape' to cease the experience", 300, 90).draw(self.screen)
        if self.building_is_cleared:
            text.Text("You've done it! Everyone got to the floors they wanted!", 300, 730).draw(self.screen)

        self.all_sprites.draw(self.screen)
Пример #10
0
    def __init__(self, parent):

        # Assign attributes from input
        self.parent = parent

        # Set the display to draw to and the clock for timing
        self.display = parent.game_display
        self.clock = parent.clock

        # Set the background
        self.background_large = pygame.image.load(
            "resources/menubackground.png").convert()
        self.background_small = pygame.image.load(
            "resources/menubackgroundsmall.png").convert()

        self.background = self.background_large

        # Create the content of the menu
        self.play_button = Button("resources/menubuttons.png",
                                  ((0, 0, 360, 80), (360, 0, 360, 80)), 300,
                                  426, lambda: self.game.run(True))
        self.quit_button = Button("resources/menubuttons.png",
                                  ((0, 80, 360, 80), (360, 80, 360, 80)), 262,
                                  502, "quit")
        self.continue_button = Button("resources/menubuttons.png",
                                      ((0, 160, 360, 80), (360, 160, 360, 80)),
                                      338, 350, lambda: self.game.run(False))

        self.title_big = text.Text("Stealth", 200, 165, 100)
        self.title_small = text.Text("Stealth", 150, 124, 80)

        # Fill the group with everything on that screen of the menu
        self.main_menu = pygame.sprite.Group()
        self.main_menu.add(self.play_button)
        self.main_menu.add(self.quit_button)
        self.main_menu.add(self.continue_button)
        self.main_menu.add(self.title_big)

        # The screen that is currently displayed
        self.current_screen = None

        # Lag mode
        self.lagging = False

        if self.parent.small:
            self.toggle_lag()

        # Create an instance of the game class
        self.game = g.Game(self)
Пример #11
0
 def __init__(self, startDate, endDate, delta, format):
     group.Group.__init__(self)
     coord = (0, 0)
     for date in datetimeIterator(startDate, endDate, delta[0]):
         dateString = text.Text(date.strftime(format))
         coord = (coord[0] + delta[1], coord[1] + delta[2])
         self.append(Label(dateString, coord, 0))
Пример #12
0
def generateMonthlyStrings(startDate, endDate):
    year = startDate.year
    endYear = endDate.year

    month = startDate.month
    endMonth = endDate.month

    labels = list()
    while year < endYear or month < endMonth:
        d = date(year, month, 1)

        if month == 1:
            format = "%b %y"
        else:
            format = "%b"

        dateString = text.Text(d.strftime(format))

        labels.append(dateString)

        month += 1
        if month > 12:
            month = 1
            year += 1

    return labels
Пример #13
0
    def start(self):
        self.background_group = pygame.sprite.Group()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()

        self.control_prompts = [
            ('Press [*x*] (Confirm button)','confirm'),
            ('Press [*circle*] (Back button)','back'),
            ('Press [*square*] (Order Ships button)','action'),
            ('Press [*triangle*] (Upgrade button)','special'),
            ('Press the button you want to use for Fast Forward','game_speed'),
            ('Press the button you want to use for Pause','menu'),
        ]
        self.control_index = -1
        self.control_text = text.Text("", "small", (game.RES[0]/2, game.RES[1]/2), multiline_width=300)
        self.control_text.offset = (0.5, 0.5)
        self.ui_group.add(self.control_text)
        self.bindings = {
            1:"confirm",
            2:"back",
            0:"action",
            3:"special",
            4:"game_speed",
            9:"menu",
            8:"cheat1"
        }
        self.set_next_control_prompt()
Пример #14
0
 def __init__(self):
     self.running = True
     centerx, height = settings.WIDTH // 2, settings.HEIGHT
     self.title = text.Text("PACMAN-ish",
                            pos=(centerx, 1 * height // 9),
                            color=colors.LIGHT_RED,
                            font=FONT3)
     self.button = {
         'start':
         text.ClickableText("Start",
                            pos=(centerx, 3 * height // 9),
                            font=FONT,
                            hovered_font=FONT2),
         'menu':
         text.ClickableText("Menu",
                            pos=(centerx, 5 * height // 9),
                            font=FONT,
                            hovered_font=FONT2),
         'quit':
         text.ClickableText("Quit",
                            pos=(centerx, 7 * height // 9),
                            font=FONT,
                            hovered_font=FONT2),
     }
     self.buttons = pygame.sprite.Group(self.button.values())
Пример #15
0
    def start(self):
        self.background_group = pygame.sprite.LayeredDirty()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()

        self.game.player_inputs = []
        
        self.player_index = 0

        res = self.game.game_resolution
        self.instructions = text.Text(
            "Click or press START to join the battle!",
            "small",
            V2(res.x/2, 40),
            multiline_width=400,
        )
        self.instructions.offset = (0.5, 0)

        self.ui_group.add(self.instructions)

        self.back = button.Button(V2(10,10), "[*circle*] Back", "big", self.on_back)
        self.ui_group.add(self.back)

        self.start_btn = button.Button(V2(res.x/2,res.y - 40), "[*x*] Ready", "big", None)
        self.start_btn.disabled = True
        self.start_btn.offset = (0.5, 0)
        self.start_btn.visible = False
        self.ui_group.add(self.start_btn)

        self.sm = states.Machine(MultiplayerUIState(self))
        self.game.input_mode = game.Game.INPUT_MULTIPLAYER
        self.player_panels = []
        self.mode = "add_players"
Пример #16
0
    def enter(self):
        super().enter()

        self.info = text.Text(
            "The hope of humanity is gone... or is it? You can lose your score, but carry on the struggle...",
            "small",
            self.scene.game.game_resolution / 2,
            multiline_width=250,
            shadow=PICO_BLACK)
        self.info.offset = (0.5, 0.5)
        self.info.layer = 10
        self.scene.ui_group.add(self.info)

        self.retry_button = Button(
            V2(self.scene.game.game_resolution.x / 3,
               self.scene.game.game_resolution.y * 0.6), "Continue", "big",
            self.on_retry)
        self.retry_button.offset = (0.5, 0.5)
        self.retry_button.layer = 10
        self.scene.ui_group.add(self.retry_button)

        self.give_up_button = Button(
            V2(self.scene.game.game_resolution.x * 2 / 3,
               self.scene.game.game_resolution.y * 0.6), "Game Over", "big",
            self.on_give_up)
        self.give_up_button.offset = (0.5, 0.5)
        self.give_up_button.layer = 10
        self.scene.ui_group.add(self.give_up_button)
Пример #17
0
    def initialize(self, scene):
        self.build()
        self.bg = pygame.sprite.Sprite()
        w = self.width + 10
        h = self.height + 20
        x = 120 - w / 2
        y = self.y_offset - h / 2
        self.bg.image = pygame.surface.Surface((w, h))
        self.bg.image.fill((247, 249, 223))
        pygame.draw.rect(self.bg.image, game.BGCOLOR, (1, 1, w - 2, h - 14), 1)
        pygame.draw.rect(self.bg.image, game.BGCOLOR, (1, h - 14, w - 2, 13),
                         0)
        self.bg.rect = (x, y, w, h)

        scene.tutorial_group.add(self.bg)
        for element in self.elements:
            element.rect = (element.rect[0] + x + 5, element.rect[1] + y + 5,
                            element.rect[2], element.rect[3])
            scene.tutorial_group.add(element)

        t = text.Text("Press Space to continue",
                      "small", (x + w / 2 - 59, y + h - 12),
                      border=False)
        self.elements.append(t)
        scene.tutorial_group.add(t)
Пример #18
0
    def start(self):
        self.background_group = pygame.sprite.Group()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()
        self.sm = states.Machine(states.UIEnabledState(self))
        self.bg = simplesprite.SimpleSprite(self.game.game_offset,
                                            "assets/intro-sm-1.png")
        self.bg.image = upscale.pixel(self.bg.image, 4)
        self.bg.pos = V2(
            self.game.game_resolution.x / 2 - self.bg.image.get_width() / 2,
            self.game.game_resolution.y / 2 - self.bg.image.get_height() / 2)
        self.background_group.add(self.bg)
        self.mockup = text.Text("Mockup Art", "big", V2(30, 30))
        self.ui_group.add(self.mockup)
        self.stage = 0

        self.time = 0
        self.tutorial_speed = 1
        self.tut = TutorialMessage("")
        self.tut.pos = V2(self.game.game_resolution.x / 2 - 172,
                          self.game.game_resolution.y - 54)
        self.tut._reposition_children()
        self.ui_group.add(self.tut)
        self.tut.add_all_to_group(self.ui_group)
        self.tut.set_visible(False)
Пример #19
0
    def __decorate(self, size):
        self.decour = list()
        self.text = text.Text((size, size), "scores")
        """ top row of border decour """
        r = pygame.Rect(0, 0, size, size)
        for x in range(0, self.rect.w / size):
            rc = r.copy()
            self.decour.append(rc)
            r.x += size
        """ sides of border decour """
        r.y += size
        r.x -= size
        self.decour.append(r.copy())
        r.x = 0
        self.decour.append(r.copy())
        """ middle row of border decour """
        r.y += size
        for x in range(0, self.rect.w / size):
            rc = r.copy()
            self.decour.append(rc)
            r.x += size

        r.y += size
        r.x -= size
        self.decour.append(r.copy())
        r.x = 0
        self.decour.append(r.copy())
        """ bottom row of border decour """
        r.y += size
        for x in range(0, self.rect.w / size):
            rc = r.copy()
            self.decour.append(rc)
            r.x += size
Пример #20
0
def read_files(essay_list, number, essay_name):
    for i in range(1, 87):
        if i in essay_name:
            essay = open("data\\" + str(i) + ".txt", "r")
            author = essay.readline().rstrip(" \n")
            essay = essay.readline().rstrip("\n").lower()
            for punction in string.punctuation:
                if punction == '.' or punction == '!' or punction == "?":
                    if number == 1:
                        essay = essay.replace(punction, " " + punction)
                    elif number == 2:
                        essay = essay.replace(
                            punction, " token " + str(punction) + " <s>")
                    else:
                        essay = essay.replace(
                            punction,
                            " token token " + str(punction) + " <s> <s>")
                elif punction == "<" or punction == ">":
                    continue
                else:
                    essay = essay.replace(punction, " ")

            new = essay.split(" ")
            if number == 2:
                new = ["<s>"] + new
            if number == 3:
                new = ["<s>"] + ["<s>"] + new
            new = [k for k in new if k]
            book = text.Text(author, essay, new)
            essay_list.append(book)
Пример #21
0
    def start(self):
        self.background_group = pygame.sprite.LayeredDirty()
        self.game_group = pygame.sprite.LayeredDirty()
        self.ui_group = pygame.sprite.LayeredDirty()
        self.ignore_next_resize_event = False

        self.selected_item_index = 0

        self.items = {}

        x = self.game.game_resolution.x / 2 - 120
        y = self.game.game_resolution.y / 2 - 120

        if not self.game.save.get_setting("fullscreen"):
            self.game.make_resizable(True)

        self.menumanager = menu.Menu(self, V2(x, y))
        self.setup_menu()

        self.sm = states.Machine(states.UIEnabledState(self))

        self.drag_notice = text.Text("Drag window corner to resize",
                                     "small",
                                     V2(self.game.game_resolution.x / 2 - 70,
                                        self.game.game_resolution.y - 20),
                                     PICO_YELLOW,
                                     multiline_width=300)
        self.ui_group.add(self.drag_notice)
        self.drag_notice.visible = not self.game.save.get_setting("fullscreen")
Пример #22
0
    def render(self):
        self.screen.fill((255, 255, 255))

        self.txt.draw(self.screen)
        text.Text("Just write in something between 2 and 10 and press 'enter'", 20, 80).draw(self.screen)

        self.userInput.draw(self.screen)
Пример #23
0
def load():
    with open("text.txt", "r") as text:
        for l in text:
            dic = eval(l)
            texts[dic["name"]] = t.Text(**dic)

    print(texts)
Пример #24
0
 def create(self, scene, pos):
     super().create(scene, pos)
     self.title.on("mouse_down", lambda a, b: self.input_confirm())
     self.choice_text = text.Text("", "small", self.pos + V2(80, 0),
                                  PICO_BLUE)
     scene.ui_group.add(self.choice_text)
     self._update_choice_text()
Пример #25
0
    def __init__(self, scr, txt="How many floors will it be?"):
        SceneBase.__init__(self, scr)

        self.txt = text.Text(txt, 20, 20)
        self.userInput = text.TextBox('', 20, 50)

        self.render()
Пример #26
0
def main():
    global game
    global player
    pygame.init()
    game = Game()
    player = Player()
    for text_type in TEXT_TYPES:
        game.text_objects.append(text.Text(text_type))
Пример #27
0
 def __init__(self, planet, scene, pos):
     super().__init__(pos, "assets/warning.png", 19)
     self.planet = planet
     self.scene = scene
     self.wt = WARNINGTIME
     self.text = text.Text(str(WARNINGTIME), "small", self.pos + V2(7,6), PICO_RED)
     self.scene.ui_group.add(self.text)
     self._recalc_rect()
Пример #28
0
    def __init__(self, *args, **kwargs):
        super(Console, self).__init__(*args, **kwargs)

        self.x += self.width/2
        self.y += self.height/2
        
        self.textbox = text.Text('', size=self.size)
        self.textbox.background = Game.color('black')
Пример #29
0
 def create(self, scene, pos):
     self.pos = pos
     self.title = text.Text(self.label,
                            "small",
                            self.pos,
                            onhover=self.on_hover,
                            multiline_width=999)
     self.title.on("mouse_exit", lambda a, b: self.on_unhover())
     scene.ui_group.add(self.title)
Пример #30
0
 def __init__(self, scene, pos, ship):
     super().__init__(pos, "assets/warning.png", 19)
     self.scene = scene
     self.ship = ship
     self.wt = 10
     self.text = text.Text(str(10), "small", self.pos + V2(7,6), PICO_ORANGE, shadow=True)
     self.scene.ui_group.add(self.text)
     self._offset = (0.5,0.5)
     self._recalc_rect()