Example #1
0
def main(x=HALF_WIDTH // 4, y=HALF_HEIGHT - 50, heart=100, eat=100, energy=100, money=0, *inventory):
    player = Player(sprites, sc, x, y, heart, eat, energy, inventory, money)
    drawing = Drawing(sc, sc_map)
    pygame.mouse.set_visible(False)
    pygame.mixer.music.load('sound\\music\\Free Zen Spirit — Zen Spirit Music.mp3')
    pygame.mixer.music.play()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
        player.movement()
        sc.fill(BLACK)

        drawing.background(player.angle)
        walls = ray_casting_walls(player, drawing.textures)
        drawing.world(walls + [obj.object_locate(player) for obj in sprites.list_of_objects])
        drawing.fps(clock)
        pygame.draw.rect(sc, BLACK, (WIDTH - 400, 0, 700, HEIGHT))
        pygame.draw.rect(sc, BLACK, (0, 0, WIDTH, 30))
        pygame.draw.rect(sc, BLACK, (0, HEIGHT - 50, WIDTH, 100))
        pygame.draw.rect(sc, WHITE, (WIDTH - 400, 0, 700, HEIGHT - 300), 3)
        pygame.draw.rect(sc, WHITE, (WIDTH - 400, HEIGHT - 300, 700, 300), 3)
        player.draw_hp()

        pygame.display.flip()
        clock.tick(FPS)
        '''
Example #2
0
class GameField(BoxLayout):
    def __init__(self, overlay, **kwargs):
        super().__init__(**kwargs)
        # creating an interface
        self.controller = overlay
        self.size_hint = (.8, .8)
        self.orientation = 'vertical'
        # starting the gameloop
        self.event = Clock.schedule_interval(self.mainloop, 0)
        # create main canvas
        self.GAME = Widget()
        self.GAME.canvas = Canvas()
        self.add_widget(self.GAME)
        # game classes
        self.player = Player()
        self.sprites = Sprites()
        self.drawing = Drawing(self.GAME.canvas, None)

        # draw borders
        with self.canvas.after:
            Color(.05, .05, .05)
            Rectangle(pos=(0, 0), size=(NULLX, REAL_SCREEN_Y))
            Color(.01, .01, .01)
            Rectangle(pos=(NULLX, REAL_SCREEN_Y - NULLY),
                      size=(REAL_SCREEN_X - NULLX, NULLY))
            Color(.01, .01, .01)
            Rectangle(pos=(NULLX, 0), size=(REAL_SCREEN_X - NULLX, NULLY))
            Color(.05, .05, .05)
            Rectangle(pos=(REAL_SCREEN_X - NULLX, 0),
                      size=(REAL_SCREEN_X, REAL_SCREEN_Y))

    def mainloop(self, dt):
        self.controller.fps_label_update(dt)
        self.GAME.canvas.clear()

        # processing the movement
        for btn in self.controller.btns:
            if btn.state == 'down':
                self.player.lookbehind(btn.text)
            if self.controller.joystick.pad != [0.0, 0.0]:
                self.player.movement(self.controller.joystick)

        # draw
        self.drawing.background(self.player.angle)
        walls = ray_casting(self.player, self.drawing.textures)
        self.drawing.world(walls + [
            obj.object_locate(self.player)
            for obj in self.sprites.list_of_objects
        ])
        self.drawing.mini_map(self.player)
        # self.drawing.field(self.player)
        self.drawing.sight()
Example #3
0
pygame.init()
sc = pygame.display.set_mode((WIDTH, HEIGHT), pygame.DOUBLEBUF)
clock = pygame.time.Clock()

sc_map = pygame.Surface(MAP_RES)
sprites = Sprites()
player = Player(sprites)
drawing = Drawing(sc, sc_map, player, clock)
interaction = Interaction(player, sprites, drawing)

drawing.menu()
pygame.mouse.set_visible(False)

while True:

    player.movement()
    drawing.background()
    walls, wall_shot = ray_casting_walls(player, drawing.textures)
    drawing.world(
        walls + [obj.object_locate(player) for obj in sprites.list_of_objects])
    drawing.mini_map()
    drawing.player_weapon([wall_shot, sprites.sprite_shot])
    interaction.interaction_objects()
    interaction.npc_action()
    interaction.clear_world()
    interaction.check_win()
    drawing.hud()

    pygame.display.flip()
    #clock.tick()
Example #4
0
import pygame
from settings import *
from player import Player
import math
from map import world_map
from drawing import Drawing

pygame.init()
sc = pygame.display.set_mode((WIDTH, HEIGHT))
sc_map = pygame.Surface((WIDTH // MAP_SCALE, HEIGHT // MAP_SCALE))
clock = pygame.time.Clock()
player = Player()
drawing = Drawing(sc, sc_map)

# основной цикл программы
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    player.movement()
    sc.fill(BLACK)

    drawing.background(player.angle)
    drawing.world(player.pos, player.angle)
    drawing.fps(clock)
    drawing.mini_map(player)

    pygame.display.flip()
    clock.tick()
def GameMain(sc, playername):
    global enemy_healthBar
    #global enemy
    print("i have started the game")

    #If the player is in battle
    playerIsBattling = False

    #If the player clicks their inventory while in battle this should be True
    battleInvClicked = False
    exited = 0
    sc = pygame.display.set_mode((display_width, display_height))
    sc_map = pygame.Surface(MINIMAP_RES)

    clock = pygame.time.Clock()
    sprites = Sprites()

    #Initialize Player, Inventory, Equipment, Battle UI
    player = Player(playername)
    inventory = invClassHelpers.Inventory(player.startingItems)
    equipment = equipClassHelpers.Equipment()
    battleUI = battle_UIClassHelpers.BattleUI(player, inventory)
    heldItem = None
    # config.text1.append(player.pos)
    drawing = Drawing(sc, sc_map, None)
    second_screen = pygame.Surface((400, 300))
    second_screen.fill(black)
    healthBar = health.Bar(config.white, config.CHAR_DETAIL_FONT_LARGE,
                           (1285, 500), sc)

    #129 Enemy HP Bar, set to a new bar when encountering an enemy
    enemy = None

    while True:
        mouseX, mouseY = pygame.mouse.get_pos()
        sc.fill(black)
        player.movement()
        walls = ray_casting(player, drawing.textures)
        drawing.background(player.angle)
        drawing.world(walls + [
            obj.object_locate(player, healthBar)
            for obj in sprites.list_of_objects
        ])
        sc.blit(second_screen, (0, 0))
        # second_screen.blit(second_screen, (0, config.scroll_y))
        drawing.mini_map(player)
        drawing.ui_elements(player, sc)
        drawing.activities_panel(second_screen)

        if player.won and not playerIsBattling:
            encounter.boss_flag = True
            config.boss_initiate = True
            enemy = encounter.enemy_trigger(sc)
            encounter.in_battle = True
            playerIsBattling = True
            if enemy_healthBar == 0:
                enemy_healthBar = health.Bar(config.white,
                                             config.CHAR_DETAIL_FONT_LARGE,
                                             (100, 650), sc)

        if player.won is True and encounter.boss_defeated:
            transitions.win_screen(sc, player)
        #Player Health Bar & Enemy Health Bar
        healthBar.updateBar()
        if (playerIsBattling):
            enemy_healthBar.updateBar()

        equipment.createEquip()
        activities.iterate_over_input(second_screen, 20)
        if encounter.in_battle and not encounter.enemy_selected:
            enemy = encounter.enemy_trigger(sc)
            print("chose enemy in game")
            if enemy is not None:
                print("In game chose " + enemy.type)
            playerIsBattling = True
            if enemy_healthBar == 0:
                enemy_healthBar = health.Bar(config.white,
                                             config.CHAR_DETAIL_FONT_LARGE,
                                             (100, 650), sc)

        if encounter.in_battle and encounter.enemy_selected and enemy is not None:
            encounter.enemy_blit(sc, enemy)

        if (battleInvClicked):  #When the Open Inventory button is clicked
            inventory.createInventory()
            Button.check_Hover(inventory.back, sc)
            drawing.blitHeldItem(heldItem, mouseX, mouseY)
            drawing.blitMenuInfoBoxes(inventory, equipment)

        else:  #The player is in battle moves menu, not inventory
            battleUI.createBattleUI()

            #the hover check is what's blitting the actions to the screen each time also
            #battleUI.actions[0] to [3] is the player's moves. [4] is "Open Inventory"
            for button in battleUI.actions:
                Button.check_Hover(button, sc)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()

            #For if the player is in the Inventory and click a button
            elif event.type == pygame.MOUSEBUTTONDOWN and (battleInvClicked):
                #If they clicked "Back" in the Inventory, then go back and break out
                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and inventory.back.rect.collidepoint(
                        pygame.mouse.get_pos()):
                    battleInvClicked = False
                    break
                #Otherwise blit everything needed!
                heldItem, healthBar, player = drawing.inventoryEquipmentUI(
                    inventory, equipment, sc, event.type, event.button, mouseX,
                    mouseY, heldItem, healthBar, player)
                drawing.blitMenuInfoBoxes(inventory, equipment)

                if event.button == 4:
                    config.scroll_y = min(
                        config.scroll_y + 20, 0
                    )  #what happens when you scroll is that the activities panel goes
                    #black and then the text are repeated
                    #so you should use the second_screen recursively
                    print('up')
                if event.button == 5:
                    config.scroll_y = max(config.scroll_y - 20, -300)
                    print('down')
                    print(config.scroll_y)

            #129 BATTLE
            #If they left-click
            elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                if battleUI.actions[4].rect.collidepoint(
                        pygame.mouse.get_pos()):
                    battleInvClicked = True

                elif playerIsBattling:
                    if battleUI.actions[0].rect.collidepoint(
                            pygame.mouse.get_pos()):
                        enemy_healthBar.subtractHealth(player.attack)
                    elif battleUI.actions[1].rect.collidepoint(
                            pygame.mouse.get_pos()):
                        enemy_healthBar.subtractHealth(player.attack)
                    elif battleUI.actions[2].rect.collidepoint(
                            pygame.mouse.get_pos()):
                        enemy_healthBar.subtractHealth(player.attack)
                    elif battleUI.actions[3].rect.collidepoint(
                            pygame.mouse.get_pos()):
                        enemy_healthBar.subtractHealth(player.attack)
                    print(str(enemy_healthBar.currenthealth))
                    enemy_healthBar.updateBar()
                    #Mf got KO'ed bro
                    if enemy_healthBar.currenthealth == 0:
                        playerIsBattling = False
                        encounter.enemy_defeated(sc, player.won)
                    #Let the enemy whack the stupid player here
                    else:
                        damageTaken = player.defense - random.randint(
                            int(enemy.damage[0]), int(enemy.damage[1]))
                        #This means player defense is higher than the damage taken!!@#!@#!@# SO SET IT TO 0 SO THE DAMN PLAYER DONT GET WHACKED
                        if (damageTaken > 0): damageTaken = 0
                        healthBar.subtractHealth(
                            abs(damageTaken))  #Enemy does a range of damage
                        if (healthBar.currenthealth == 0):  #UR DEAD BRO
                            # To reset variables
                            encounter.player_death()
                            exited = 1

        if exited == 1:
            # Do different music here too
            gameDisplay_input = pygame.display.set_mode(
                (config.display_width, config.display_height))
            game_over_text = config.SPOOKY_BIG_FONT.render(
                'Game Over', True, config.red)
            gameDisplay_input.blit(
                game_over_text,
                (config.display_width / 3, config.display_height / 3))
            buttons = [
                Button("Return to Character Selection Screen", config.white,
                       pygame.font.Font("assets/fonts/CHILLER.ttf", 50),
                       (4 * config.display_width / 5,
                        4 * config.display_height / 5), gameDisplay_input)
            ]
            if (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1
                    and buttons[0].rect.collidepoint(pygame.mouse.get_pos())):
                character_selection(gameDisplay_input)
                # options_menu.options_menu(gameDisplay_input)

            # options_menu.lost(gameDisplay_input)

            # print("You suck")

        pygame.display.flip()
        clock.tick(60)
Example #6
0
# запуск основных функций
sprites = Sprites()
clock = pygame.time.Clock()
player = Player(sprites)
drawing = Drawing(sc, sc_map, player, clock)
interaction = Interaction(player, sprites, drawing)

# отрисовка меню
drawing.menu()
# запуск музыки
interaction.play_music()

while True:
    pygame.mouse.set_visible(False)
    player.movement()  # анализ нажатия клавиш
    drawing.background(player.angle)  # отрисовка неба и пола
    walls, wall_shot = ray_casting_walls(
        player, drawing.textures)  # улавливание стен лучами
    drawing.world(
        walls + [obj.object_locate(player)
                 for obj in sprites.list_of_objects])  # отрисовка мира
    drawing.fps(clock)  # счетчик фпс
    drawing.mini_map(player)  # миникарта
    drawing.player_weapon([wall_shot, sprites.sprite_shot])  # отрисовка оружия

    interaction.interaction_objects()
    interaction.npc_action(
    )  # анализ действия нпс. на данный момент бесполезно без ии
    interaction.clear_world(
    )  # удаление мертвых объектов из списка для анализа