Exemplo n.º 1
0
def VictoryScreen(screen,resolution,FPS = 60):

    running = True
    buttonsize = (int(resolution[0]/3),int(resolution[1]/10))
    buttonpos = (int(resolution[0]/2-buttonsize[0]/2),int(resolution[1]/2-buttonsize[1]/2))
    Interface = UI.UI(pygame.math.Vector2(0,0),resolution)

    Interface.items.append(UI.Button((buttonpos[0],int(buttonpos[1]+buttonsize[1]*1.25)), buttonsize, "Button-1.png", "VICTORY!", "arial",returnCONTINUE))
    Interface.items.append(UI.Button((buttonpos[0], int(resolution[1] - buttonsize[1] * 1.25)), buttonsize, "Button-1.png", "QUIT","arial",UI.QUIT))

    clock = pygame.time.Clock()


    while running:

        ###INPUT###
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            # only do something if the event is of type QUIT
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
        mousepos = pygame.mouse.get_pos()
        LeftMousePressed = pygame.mouse.get_pressed()[0]

        buttoninput = Interface.update(mousepos,LeftMousePressed)
        for i in buttoninput:
            if(i != None):
                running = False
                return i

        Interface.draw(screen)

        pygame.display.flip()
        clock.tick(FPS + 1)
Exemplo n.º 2
0
def NewGameScreen(screen,resolution,senarios,FPS = 60):
    
    running = True

    state = "None"

    buttonsize = (int(resolution[0]/5),int(resolution[1]/18))
    startbuttonpos = (int(buttonsize[0]),int(buttonsize[1]*2))
    SenarioList = UI.UI(pygame.math.Vector2(0,0),(resolution))

    SenarioButtons = UI.UI(pygame.math.Vector2(0,0),(int(startbuttonpos[0]),resolution[1]))
    SenarioButtons.items.append(UI.Button((int(buttonsize[0]/2),int(buttonsize[1]/2)),(int(buttonsize[0]/4),int(buttonsize[1])),"Button-1.png","↑","arial",returnUP))
    SenarioButtons.items.append(UI.Button((int(buttonsize[0]/2),int(resolution[1]-3*buttonsize[1]/2)),(int(buttonsize[0]/4),int(buttonsize[1])),"Button-1.png","↓","arial",returnDOWN))
    SenarioButtons.items.append(UI.Button((int(buttonsize[0]/6),int(resolution[1]-3*buttonsize[1]/2)),(int(buttonsize[0]/4),int(buttonsize[1])),"Button-1.png","←","arial",returnBACK))


    x= 0
    
    maxcharlength = 20
    for i in senarios:
        newpos = (startbuttonpos[0],int(startbuttonpos[1]+x*buttonsize[1]*1.1))
        text = i
        if(len(i) > maxcharlength):
            text = i[0:maxcharlength]+str("...")
        y = UI.Button(newpos,buttonsize,"Button-1.png",text,"arial",i)
        SenarioList.items.append(y)
        x+=1
    
    clock = pygame.time.Clock()
    

    z = 1
    while running:
        state = "NONE"

        ###INPUT###
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            # only do something if the event is of type QUIT
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
        mousepos = pygame.mouse.get_pos()
        LeftMousePressed = pygame.mouse.get_pressed()[0]
        
        buttoninput = SenarioList.update(mousepos,LeftMousePressed) + SenarioButtons.update(mousepos,LeftMousePressed)

        for i in buttoninput:
            if(i != None):
                #print(i)
                state = i

        if(state == "NONE"):
            pass
        elif (state == "UP"):
            if (SenarioList.pos[1] / (x * buttonsize[1] * 1.1) != -1):
                SenarioList.move(0, -buttonsize[1] * 1.1)

        elif (state == "DOWN"):
            if (SenarioList.pos[1] < 0):
                SenarioList.move(0, buttonsize[1] * 1.1)
            pass
        else:
            running = False
            return state

        #SenarioList.move(0,1)
        
        SenarioList.draw(screen)
        SenarioButtons.draw(screen)
        pygame.display.flip()
        clock.tick(FPS + 1)

    pass
def main(sim,
         screen,
         resolution,
         FPS: int = 60,
         Victory: bool = False,
         User: int = 1):

    # define a variable to control the main loop
    running = True
    # create a clock

    clock = pygame.time.Clock()

    font = pygame.font.SysFont(None, 72)

    # for checking updates for the renderer
    Update = 0
    # the selected and state values
    LastSelected = ""
    Selected = ""
    State = "None"
    # creates the game renderer
    GameWindow = GameRenderer.GameRender(0, 0, 720, 720, 36)
    #TexturePath = os.path.join(GraphicsPath, "Panzer3Pixel.png")
    #RawImage = pygame.image.load(TexturePath).convert()
    #setting up UI
    Interface = UI.UI(
        pygame.math.Vector2(int(resolution[0] * (9 / 16)), 0),
        pygame.math.Vector2(int(resolution[0] - resolution[1]),
                            int(resolution[1])))
    Interface.items.append(
        UI.Button(
            pygame.math.Vector2(int(Interface.size[0] * 0.05),
                                int(Interface.size[1] * 0.05)),
            (int(Interface.size[0] * 0.4), int(Interface.size[1] * 0.15)),
            "Button-1.png", "END TURN", "arial", UI.ENDB))
    Interface.items.append(
        UI.Button(
            pygame.math.Vector2(int(Interface.size[0] * 0.05),
                                int(Interface.size[1] * 0.25)),
            (int(Interface.size[0] * 0.4), int(Interface.size[1] * 0.05)),
            "Button-1.png", "MOVE", "arial", UI.MOVEB))
    Interface.items.append(
        UI.Button(
            pygame.math.Vector2(int(Interface.size[0] * 0.05),
                                int(Interface.size[1] * 0.35)),
            (int(Interface.size[0] * 0.4), int(Interface.size[1] * 0.05)),
            "Button-1.png", "FIRE", "arial", UI.FIREB))
    Interface.items.append(
        UI.Button(
            pygame.math.Vector2(int(Interface.size[0] * 0.75),
                                int(Interface.size[1] * 0.9)),
            (int(Interface.size[0] * 0.2), int(Interface.size[1] * 0.05)),
            "Button-1.png", "QUIT", "arial", UI.QUIT))
    #Interface.items.append(RawImage)

    ###Main Loop###
    while running:

        ###INPUT###
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            # only do something if the event is of type QUIT
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
        mousepos = pygame.mouse.get_pos()
        LeftMousePressed = pygame.mouse.get_pressed()[0]
        if (pygame.mouse.get_pressed()[1] == 1):
            State = "None"

        g = GameWindow.Update(mousepos, LeftMousePressed, sim.TankManager,
                              sim.MapManager)
        if (g != None):
            # print(g)
            Selected = g

        ButtonsInputs = Interface.update(mousepos, LeftMousePressed)
        for i in ButtonsInputs:
            if (i != None):
                State = i

        ###States###
        HILI = None
        if (State == "None"):
            if (Selected != ""):
                LastSelected = Selected
                Selected = ""
        elif (State == "MOVE"):

            if (Selected != "" and LastSelected != ""
                    and type(Selected) == tuple
                    and type(LastSelected) != tuple):

                sim.InputActionCommand(
                    str(LastSelected) + " MOVE " + str(Selected[0]) + "," +
                    str(Selected[1]))
                State = "None"
            elif (type(LastSelected) != tuple and LastSelected != ""):
                L = LastSelected.strip("TANK")
                L = int(L)
                t = sim.TankManager.Tanks[L]
                p = t.GetComponentFromType(Component.Position).pos
                movement = t.GetComponentFromType(
                    Component.Gamestats).MoveSpeed
                m = sim.MapManager.AvalibleMovementTiles(p, movement)
                HILI = GameWindow.HighLight(m, (255, 0, 0))
            elif (LastSelected == ""):
                State = "None"

        elif (State == "FIRE"):
            if (Selected != "" and LastSelected != ""
                    and type(Selected) != tuple
                    and type(LastSelected) != tuple):

                State = "None"
                sim.InputActionCommand(
                    str(LastSelected) + " FIRE " + str(Selected))
            elif (LastSelected != "" and type(LastSelected) != tuple):
                L = LastSelected.strip("TANK")
                L = int(L)
                t = sim.TankManager.Tanks[L]
                p = t.GetComponentFromType(Component.Position).pos
                r = t.GetComponentFromType(Component.Gamestats).MaxRange
                canhit = []
                for i in sim.TankManager.Tanks:
                    if (i != t):
                        m = i.GetComponentFromType(Component.Position).pos
                        distance = p.distance_to(m)
                        if (distance <= r):
                            canhit.append(m)
                HILI = GameWindow.HighLight(canhit, (255, 0, 0))

        elif (State == "END"):
            # print("END")
            sim.InputActionCommand("ENDTURN")
            State = "None"

        elif (State == "QUIT"):
            running = False
        ###End of States###

        if (Update == FPS):
            # sim.Attack(sim.TankManager.Tanks[0],sim.TankManager.Tanks[1])
            # sim.InputActionCommand("TANK01 MOVE 2,4")
            # sim.InputActionCommand("TANK00 MOVE 3,1")
            #print(str(LastSelected) + " "+str(Selected)+" " +str(State))
            # sim.EndTurn()
            GameWindow.MapRendered = False
            Update = 0
        else:
            Update += 1

        ############RENDER SCREEN#############
        screen.blit(GameWindow.RenderMap(sim.MapManager), (GameWindow.pos))

        screen.blit(GameWindow.RenderTanks(sim.TankManager), (GameWindow.pos))

        if (HILI != None):
            screen.blit(HILI, GameWindow.pos)

        Interface.draw(screen)

        DisplayFPS = font.render(str(round(clock.get_fps())), True, (0, 0, 0))
        screen.blit(DisplayFPS, (0, 0))
        ############Display Rendered Screen####
        pygame.display.flip()

        ###Check For victory###
        if (sim.Victory != None):
            if (sim.Victory[0] == User):
                return "VICTORY"
            else:
                return "DEFEAT"
            running = False

        clock.tick(FPS + 1)