예제 #1
0
def characterSetUp(x):
    # creates player object, creates inventory, creates field
    global field
    global player
    player = objects.player(x, 20)
    player.createInventory()
    field = objects.field(3)
    field.createField()
    print("CHARA CREATED")
예제 #2
0
def main():  # main starting function
    cls()  # clear the screen
    # generate player 1
    player1 = player(1)
    # generate player 2
    player2 = player(2)

    # generate pieces for player 1
    gen(player1)
    # generate pieces for player 2
    gen(player2)

    while not won:
        cls()
        # check if player 1 has won
        if playerWonCheck(player1):
            won = True
            gameOver(player1)
        # check if player 2 has won
        elif playerWonCheck(player2):
            won = True
            gameOver(player2)
예제 #3
0
def list(board):
    '''
    list sort all the entities finded with hitboxesFileReader by class, and store the data inside it
    it return the list of all the possible class finded
    '''
    #lists to fill
    player = []
    fish = []
    rat = []
    trash = []
    fspot = []
    walls = []
    cloud = []
    exit = []
    zrat = []
    
    #fill the lists
    for i in hitboxesFileReader(board.boardAdress):
        if i[0] == "p":
            player.append(o.player())
            player[-1].position["y1"] = i[1]
            player[-1].position["y2"] = i[3]
            player[-1].position["x1"] = i[2]
            player[-1].position["x2"] = i[4]
        elif i[0] == "f":
            fish.append(o.fish(i[0], board))
            fish[-1].position["y1"] = i[1]
            fish[-1].position["y2"] = i[3]
            fish[-1].position["x1"] = i[2]
            fish[-1].position["x2"] = i[4]
        elif i[0] == "r":
            rat.append(o.rat(i[0], board.environment))
            rat[-1].position["y1"] = i[1]
            rat[-1].position["y2"] = i[3]
            rat[-1].position["x1"] = i[2]
            rat[-1].position["x2"] = i[4]
        elif i[0] == "t":
            trash.append(o.trash(i[0], board.environment, i[2], i[4], i[1], i[3]))
        elif i[0] == "m" or i[0] == "c" or i[0] == "o" or i[0] == "i" or i[0] == "a" or i[0] == "e" or i[0] == "h" or i[0] == "l" or i[0] == "d":
            walls.append(o.item(i[0], board.environment))
            walls[-1].position["y1"] = i[1]
            walls[-1].position["y2"] = i[3]
            walls[-1].position["x1"] = i[2]
            walls[-1].position["x2"] = i[4]
        #---end if---
    #---end for---
    for i in board.boardata["zone"]:
        for j in board.boardata[i]:
            if i == "nt":
                cloud.append(o.entities("nt", board.environment))
                cloud[-1].position["y1"] = j["y1"]
                cloud[-1].position["y2"] = j["y2"]
                cloud[-1].position["x1"] = j["x1"]
                cloud[-1].position["x2"] = j["x2"]
            elif i == "ex":
                exit.append(o.exit("ex", board.environment))
                exit[-1].position["y1"] = j["y1"]
                exit[-1].position["y2"] = j["y2"]
                exit[-1].position["x1"] = j["x1"]
                exit[-1].position["x2"] = j["x2"]
                exit[-1].area = j["area"]
                exit[-1].x = j["x"]
                exit[-1].y = j["y"]
                exit[-1].force = j["force"]
            elif i == "s":
                fspot.append(o.item(i, board.environment))
                fspot[-1].position["y1"] = j["y1"]
                fspot[-1].position["y2"] = j["y2"]
                fspot[-1].position["x1"] = j["x1"]
                fspot[-1].position["x2"] = j["x2"]
            elif i == "zrat":
                zrat.append(o.zrat("zrat", board.environment))
                zrat[-1].min["y1"] = j[0]["y1"]
                zrat[-1].min["y2"] = j[0]["y2"]
                zrat[-1].min["x1"] = j[0]["x1"]
                zrat[-1].min["x2"] = j[0]["x2"]
                zrat[-1].max["y1"] = j[1]["y1"]
                zrat[-1].max["y2"] = j[1]["y2"]
                zrat[-1].max["x1"] = j[1]["x1"]
                zrat[-1].max["x2"] = j[1]["x2"]
                zrat[-1].position = zrat[-1].min
            #---end if---
        #---end for---
    #---end for---
    return player, fish, rat, trash, walls, cloud, exit, fspot, zrat
예제 #4
0
canvas.itemconfig(start_button, state='normal')
canvas.tag_bind(start_button, "<Button-1>", start_game)
while not start:
    #update and wait 1 / 60th of a second (1 fps)
    tk.update_idletasks()
    tk.update()
    time.sleep(1 / 60)

#hide text
canvas.itemconfig(start_button, state='hidden')

quit = False

while not quit:
    #init player and walls
    player = objects.player(canvas)

    #generate 5 walls
    walls = []
    for x in range(5):
        walls.append(objects.wall(canvas, x * spacing, spacing))

    while True:
        #set restart to false
        restart = False
        restart_text = canvas.create_text(80,
                                          canvas.winfo_height() - 32,
                                          text="Restart",
                                          state='hidden',
                                          font=("Arial", 22))
        quit_text = canvas.create_text(canvas.winfo_width() - 80,
예제 #5
0
        elif not collision_types['left'] and math.pi < theta < 3*math.pi/2:
            #player is right of block
            collision_types['left'] = True
            player.rect.left = block.rect.right
            player.addForce(math.pi, movement[0])
            movement = (0, movement[1])
            
    if collision_types['bottom']:
        player.airTimer = 0
    else:
        player.airTimer += 1


gameScene.update = gameUpdate
gameScene.postMoveUpdate = gameCollision
player = objects.player(gameScene)
player.setPosition((50, 700))
playerGroup = gameScene.groupSprites(player)
grappleGroup = gameScene.groupSprites([])
blockGroup = gameScene.groupSprites([])
y = 0
for i in game_map:
    x = 0
    for j in i:
        
        if j:
            terrain = j - 1
            block = objects.ground(terrain, gameScene)
            block.setPosition((x*TILE_SIZE, y*TILE_SIZE))
            blockGroup.add(block)
        x += 1
예제 #6
0
def gameloop(m1, m2, u1s, u2s, clock, wall_left, wall_right, friction_bool,
             friction):
    Start_time = str(datetime.datetime.now().time())
    Start_time = Start_time.split(':')
    Start_time = list(map(float, Start_time))
    black = (0, 0, 0)
    white = (255, 255, 255)
    red = (255, 0, 0)
    blue = (0, 0, 255)
    display_width = 720
    display_height = 720
    floor_height = 100
    dims = 50
    grav = 1
    a = 0.5
    playerStart_x = 500
    playerStart_y = 620
    #m1 = 1
    #n = 1
    time_m = 1
    #m2 = (100 ** (n)) * m1
    #m2 = 69
    p2x = 400
    #u1s = 0
    #u2s = 1
    global u1
    global u2
    u1 = u1s * time_m
    u2 = u2s * time_m
    coll = 0
    global u1_lst
    global u2_lst
    global t
    t.append(0)
    u1_lst.append(u1s)
    gameDisplay = pygame.display.set_mode((display_width, display_height))
    pygame.display.set_caption('Ai_Platformer')
    gameExit = False
    while not gameExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                t = []
                u1_lst = []
                u2_lst = []
                pygame.quit()
                #if event.type == pygame.KEYDOWN:
                #if event.key == pygame.K_SPACE:
                #a = -1
                #grav = -10
                '''if event.key == pygame.K_RIGHT:
                    u1 = speed
                elif event.key == pygame.K_LEFT:
                    u1 = -speed
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT:
                    u1 = 0
                if event.key == pygame.K_LEFT:
                    u1 = 0'''

        gameDisplay.fill(white)
        grav += a
        playerStart_y += grav
        if playerStart_y + dims >= display_height - floor_height:
            playerStart_y = display_height - floor_height - dims
            grav = 0
            a = 0
        else:
            a = 0.5

        if wall_right.get() == 1:
            if playerStart_x + dims >= display_width:
                playerStart_x = display_width - dims
                u1 = -u1
                #t.append(timer(Start_time))
                #u1_lst.append(u1)
                coll += 1
            if p2x + dims >= display_width:
                p2x = display_width - dims
                u2 = -u2
                coll += 1
        if wall_left.get() == 1:
            if playerStart_x <= 0:
                playerStart_x = 0
                u1 = -u1
                #t.append(timer(Start_time))
                #u1_lst.append(u1)
                coll += 1
            if p2x <= 0:
                p2x = 0
                u2 = -u2
                coll += 1

        if playerStart_x <= p2x + dims:
            playerStart_x = p2x + dims
            coll += 1
            u2m = ((2 * m1 * u1) / (m1 + m2)) + (((m2 - m1) * u2) / (m1 + m2))
            u1m = ((2 * m2 * u2) / (m2 + m1)) + (((m1 - m2) * u1) / (m2 + m1))
            u2 = u2m
            u1 = u1m
            #u1_lst.append(u1)
            #t.append(timer(Start_time))
        if p2x + dims >= playerStart_x:
            p2x = playerStart_x - dims

        objects.floor(gameDisplay, black, floor_height, display_width,
                      display_height)
        objects.player(gameDisplay, dims, dims, playerStart_x, playerStart_y,
                       red)
        objects.player(gameDisplay, dims, dims, p2x, playerStart_y, blue)
        if friction_bool.get() == 1:
            friction1 = friction
            friction2 = friction
            if u1 != 0:
                if u1 > 0:
                    u1f = u1 - 10 * friction1
                elif u1 < 0:
                    u1f = u1 + 10 * friction1
            else:
                friction1 = 0
            if u2 != 0:
                if u2 > 0:
                    u2f = u2 - 10 * friction1
                elif u2 < 0:
                    u2f = u2 + 10 * friction1
            else:
                friction2 = 0
            u1 = u1f
            u2 = u2f
        playerStart_x += u1
        p2x += u2
        #print(len(t), len(u1_lst))
        #print(u2, u1, coll)
        u1_lst.append(u1)
        u2_lst.append(u2)
        t.append(timer(Start_time))
        global speedtime
        speedtime = [u1_lst, t]
        pygame.display.update()
        clock.tick(60)