コード例 #1
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_hp_bar(renderer, sprite_layers, screen, hp_sprite, c_pos):
    sv = pk.load(open("./save.p", "rb"))
    hp_max = sv['max_hp']
    hp = hp_max
    #scaling down the hp image according to current hit points(hp) w.r.t. max hp
    c_hp = hp / hp_max * 99
    c_hp = int(c_hp)
    if (c_hp) > 0:
        test_image = "./images/hp_bar.png"
        original = Image.open(test_image)
        # Get dimensions of original picture
        width, height = original.size
        left = 0
        top = 0
        #giving the length as required
        right = c_hp
        bottom = height
        #crooing and saving the image
        cropped_example = original.crop((left, top, right, bottom))
        cropped_example.save('./images/test_hp.png')

        #creating the sprite, adding it and then rendering the screen
        c_hp_sprite = person.create_person(c_pos[0] - 450, c_pos[1] - 380,
                                           './images/test_hp.png')
        sprite_layers[2].add_sprite(c_hp_sprite)
        shifty1.render_update(renderer, sprite_layers, screen)

        pk.dump(sv, open("./save.p", "wb"))

        return [c_hp_sprite, hp]
コード例 #2
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_hp_bar(renderer,sprite_layers,screen,hp_sprite,c_pos):
    sv=pk.load(open("./save.p","rb"))
    hp_max=sv['max_hp']
    hp=hp_max
    #scaling down the hp image according to current hit points(hp) w.r.t. max hp
    c_hp = hp/hp_max * 99
    c_hp=int(c_hp)
    if (c_hp)>0:
        test_image = "./images/hp_bar.png"
        original = Image.open(test_image)
        # Get dimensions of original picture
        width, height = original.size
        left = 0
        top = 0
        #giving the length as required
        right = c_hp
        bottom = height
        #crooing and saving the image
        cropped_example = original.crop((left, top, right, bottom))
        cropped_example.save('./images/test_hp.png')

        #creating the sprite, adding it and then rendering the screen
        c_hp_sprite=person.create_person(c_pos[0]-450,c_pos[1]-380,'./images/test_hp.png')
        sprite_layers[2].add_sprite(c_hp_sprite)
        shifty1.render_update(renderer,sprite_layers,screen)

        pk.dump(sv,open("./save.p","wb"))

        return [c_hp_sprite,hp]
コード例 #3
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_s_a(renderer, sprite_layers, screen, c_pos):
    s_a = person.create_menu_bg(c_pos[0] + 500, c_pos[1] + 350,
                                './images/spec_arrow_interf_1.png')
    sprite_layers[2].add_sprite(s_a)
    shifty1.render_update(renderer, sprite_layers, screen)

    return s_a
コード例 #4
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_l_g(renderer,sprite_layers,screen,c_pos):
    #loading, creating sprite and rendering of the base image i.e no image -> plain image
    lg=person.create_menu_bg(c_pos[0]-504,c_pos[1]-390,'./images/level_gold_1.png')
    sprite_layers[2].add_sprite(lg)
    shifty1.render_update(renderer,sprite_layers,screen)

    return lg
コード例 #5
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_f_i(renderer, sprite_layers, screen, c_pos):
    f_i = person.create_menu_bg(c_pos[0] + 500, c_pos[1] + 350,
                                './images/interface_fight_1.png')
    sprite_layers[2].add_sprite(f_i)
    shifty1.render_update(renderer, sprite_layers, screen)

    return f_i
コード例 #6
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface(renderer, sprite_layers, screen, c_pos):

    interface = person.create_person(c_pos[0] - 512, c_pos[1] - 384,
                                     './images/interface1.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer, sprite_layers, screen)
    return interface
コード例 #7
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_xp_bar(renderer,sprite_layers,screen,xp_sprite,c_pos):
    sv=pk.load(open("./save.p","rb"))
    xp=float(sv['xp'])
    xp_max=float(h(sv['h_level']))
    c_xp = xp/xp_max * 99
    c_xp=int(c_xp)
    #If xp is the image lenght will be zero and then it will be out of range and give error
    #so c_xp is made 1 [not the xp]
    if c_xp==0:
        c_xp=1
    test_image = "./images/exp_bar.png"
    original = Image.open(test_image)
    width, height = original.size
    left = 0
    top = 0
    right = c_xp
    bottom = height
    cropped_example = original.crop((left, top, right, bottom))
    cropped_example.save('./images/test_xp.png')
    sprite_layers[2].remove_sprite(xp_sprite)


    c_xp_sprite=person.create_person(c_pos[0]-400,c_pos[1]-325,'./images/test_xp.png')
    sprite_layers[2].add_sprite(c_xp_sprite)
    shifty1.render_update(renderer,sprite_layers,screen)
    pk.dump(sv,open("./save.p","wb"))
    return c_xp_sprite
コード例 #8
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_xp_bar(renderer, sprite_layers, screen, xp_sprite, c_pos):
    sv = pk.load(open("./save.p", "rb"))
    xp = float(sv['xp'])
    xp_max = float(h(sv['h_level']))
    c_xp = xp / xp_max * 99
    c_xp = int(c_xp)
    #If xp is the image lenght will be zero and then it will be out of range and give error
    #so c_xp is made 1 [not the xp]
    if c_xp == 0:
        c_xp = 1
    test_image = "./images/exp_bar.png"
    original = Image.open(test_image)
    width, height = original.size
    left = 0
    top = 0
    right = c_xp
    bottom = height
    cropped_example = original.crop((left, top, right, bottom))
    cropped_example.save('./images/test_xp.png')
    sprite_layers[2].remove_sprite(xp_sprite)

    c_xp_sprite = person.create_person(c_pos[0] - 400, c_pos[1] - 325,
                                       './images/test_xp.png')
    sprite_layers[2].add_sprite(c_xp_sprite)
    shifty1.render_update(renderer, sprite_layers, screen)
    pk.dump(sv, open("./save.p", "wb"))
    return c_xp_sprite
コード例 #9
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_l_g(renderer, sprite_layers, screen, c_pos):
    #loading, creating sprite and rendering of the base image i.e no image -> plain image
    lg = person.create_menu_bg(c_pos[0] - 504, c_pos[1] - 390,
                               './images/level_gold_1.png')
    sprite_layers[2].add_sprite(lg)
    shifty1.render_update(renderer, sprite_layers, screen)

    return lg
コード例 #10
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_dragon_hp(renderer,sprite_layers,screen,dhp_sprite,c_pos,dhp):
    c_dhp = (dhp[0]* 400)/100
    c_dhp=int(c_dhp)
    if c_dhp==0:
        c_dhp=1
    test_image = "./images/dragon_health.png"
    original = Image.open(test_image)
    width, height = original.size
    left = 0
    top = 0
    right = c_dhp
    bottom = height
    cropped_example = original.crop((left, top, right, bottom))
    cropped_example.save('./images/test_dhp.png')
    sprite_layers[2].remove_sprite(dhp_sprite)


    c_dhp_sprite=person.create_person(c_pos[0]-400,c_pos[1],'./images/test_dhp.png')
    sprite_layers[2].add_sprite(c_dhp_sprite)
    shifty1.render_update(renderer,sprite_layers,screen)
    return c_dhp_sprite
コード例 #11
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_dragon_hp(renderer, sprite_layers, screen, dhp_sprite, c_pos, dhp):
    c_dhp = (dhp[0] * 400) / 100
    c_dhp = int(c_dhp)
    if c_dhp == 0:
        c_dhp = 1
    test_image = "./images/dragon_health.png"
    original = Image.open(test_image)
    width, height = original.size
    left = 0
    top = 0
    right = c_dhp
    bottom = height
    cropped_example = original.crop((left, top, right, bottom))
    cropped_example.save('./images/test_dhp.png')
    sprite_layers[2].remove_sprite(dhp_sprite)

    c_dhp_sprite = person.create_person(c_pos[0] - 400, c_pos[1],
                                        './images/test_dhp.png')
    sprite_layers[2].add_sprite(c_dhp_sprite)
    shifty1.render_update(renderer, sprite_layers, screen)
    return c_dhp_sprite
コード例 #12
0
ファイル: spooky.py プロジェクト: gautamvij/Projects
def demo_pygame(file_name):
    # parser the map (it is done here to initialize the
    # window the same size as the map if it is small enough)
    world_map = tiledtmxloader.tmxreader.TileMapParser().parse_decode(file_name)

    mixer.init()
    #background music
    sound = mixer.Sound('./sounds/bats.ogg')
    file = './sounds/spooky.ogg'
    m = mixer.music.load(file)
    mixer.music.play(-1);
    
    #set up a screen
    screen_width = min(950, world_map.pixel_width)
    screen_height = min(760, world_map.pixel_height)
    screen = pygame.display.set_mode((screen_width, screen_height))

    # load the images using pygame
    resources = tiledtmxloader.helperspygame.ResourceLoaderPygame()
    resources.load(world_map)

    # prepare map rendering
    assert world_map.orientation == "orthogonal"

    # renderer
    renderer = tiledtmxloader.helperspygame.RendererPygame()

    # create hero sprite
    hero_pos_x = 400
    hero_pos_y = 800
    hero = person.create_person(hero_pos_x, hero_pos_y ,'./images/hero_u2.png')
    
    # dimensions of the hero for collision detection
    hero_width = hero.rect.width
    hero_height = 3

    # cam_offset is for scrolling
    cam_world_pos_x = screen_width/2
    cam_world_pos_y = screen_height/2

    # set initial cam position and size
    renderer.set_camera_position_and_size(cam_world_pos_x, cam_world_pos_y, \
                                        screen_width, screen_height)

    # retrieve the layers
    sprite_layers = tiledtmxloader.helperspygame.get_layers_from_map(resources)

    # filter layers
    sprite_layers = [layer for layer in sprite_layers if not layer.is_object_group]

    # add the hero the the right layer, it can be changed using 0-9 keys
    sprite_layers[2].add_sprite(hero)
           
    # variables for the main loop
    clock = pygame.time.Clock()
    running = True
    speed=5
    health=100
    # set up timer for fps printing
    pygame.time.set_timer(pygame.USEREVENT,1000)
    mr=ml=md=mu=0
    #create portal to change map
    portal1 = pygame.Rect(19*20,42*20,180,20)

    #create the spooky guy
    vil=person.create_villager(file_name)
    sprite_layers[1].add_sprite(vil[0]['sprte'])
    
    # mainloop
    while running:
        dt = clock.tick(40)
        #update camera position as per hero's position
        if ( hero.rect.centery >=570):
            renderer.set_camera_position(475, 570)
            c_pos=(475,570)
        elif (hero.rect.centery <=380):
            renderer.set_camera_position(475, 380)
            c_pos=(475,380)
        else:
            renderer.set_camera_position(475,hero.rect.centery )
            c_pos=(475,hero.rect.centery)


                    
        # event handling
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.USEREVENT:
                print("fps: ", clock.get_fps())
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    running = False

                x=event.key
                if (vil!=None):
                    talk_result=talk.iftalk(0,x,vil,0,hero_pos_x,hero_pos_y,file_name)
                else:
                    talk_result=None


                if(talk_result[0]==1):
                    menutext=menu.create_menu_vil(0,file_name,talk_result[2])        
                    dialog_show=0                                                    
                    
                    txtim=person.create_text_img('./images/textbox.png',menutext,dialog_show)    
                    menu_ui=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,txtim)    
                    

                    sprite_layers[2].add_sprite(menu_ui)
                    shifty1.render_update(renderer,sprite_layers,screen)

                    #the loop for showing text box (again and again) till dialogues not completed
                    while(dialog_show<len(menutext)):
                        for event in pygame.event.get():
                            if event.type == pygame.KEYDOWN:
                                x=event.key
                                if(x==pygame.K_SPACE):
                                    sprite_layers[2].remove_sprite(menu_ui)             
                                    dialog_show +=1                                     
                                    if dialog_show==len(menutext):                      
                                        break
                                    
                                    txtim=person.create_text_img('./images/textbox.png',menutext, \
                                                                 dialog_show)
                                    menu_ui=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,\
                                                  txtim)                                
                                    
                                    sprite_layers[2].add_sprite(menu_ui)
                                    sv['spook']=1
                                    sv['talk_vil'][file_name][0]=1
                                    sv['talk_vil']['./maps/village2_inside.tmx'][2]=1
                                    pk.dump(sv,open("./save.p","wb"))

                        
                        shifty1.render_update(renderer,sprite_layers,screen)


                    menu.exit_menu(x)##an infite loop till 'x' is pressed
                    sprite_layers[2].remove_sprite(menu_ui)
                

        # find directions
       
        mov = movements1.hero_move(mr,ml,md,mu,hero_pos_x,hero_pos_y,hero,speed,sprite_layers[3])
        mr = mov[0]
        ml = mov[1]
        md = mov[2]
        mu = mov[3]
        hero_pos_x = mov[4]
        hero_pos_y = mov[5]

        sv=pk.load(open("./save.p","rb"))
        if(portal1.collidepoint(hero.rect.midbottom) and sv['talk_vil'][file_name][0]==1):
            portal=True
            running = False
            mixer.music.stop();
        
            
        # clear screen, might be left out if every pixel is redrawn anyway
        screen.fill((0, 0, 0))

        #render the map
        for sprite_layer in sprite_layers:
            if sprite_layer.is_object_group:
                # we dont draw the object group layers
                # you should filter them out if not needed
                continue
            else:
                renderer.render_layer(screen, sprite_layer)
        t=random.randint(0,1000)
        #based on random numnber play bats sound
        if(t<5):
            mixer.music.stop()
            sound.play(0)
            mixer.music.play(-1);
                          
            
        # changes to switch screen to game over
        pygame.display.flip()

    if portal==True:
        #change the map
        shifty1.demo_pygame('./maps/village2_inside.tmx',2)
コード例 #13
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_spec_arrow(renderer,sprite_layers,screen,c_pos):
    interface=person.create_person(c_pos[0]-700,c_pos[1]-100,'./images/spec_arrow_interf.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer,sprite_layers,screen)
    return interface
コード例 #14
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_s_a(renderer,sprite_layers,screen,c_pos):
    s_a=person.create_menu_bg(c_pos[0]+500,c_pos[1]+350,'./images/spec_arrow_interf_1.png')
    sprite_layers[2].add_sprite(s_a)
    shifty1.render_update(renderer,sprite_layers,screen)

    return s_a
コード例 #15
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_fight(renderer, sprite_layers, screen, c_pos):
    interface = person.create_person(c_pos[0] + 312, c_pos[1] + 150,
                                     './images/interface_fight.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer, sprite_layers, screen)
    return interface
コード例 #16
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_fight(renderer,sprite_layers,screen,c_pos):
    interface=person.create_person(c_pos[0]+312,c_pos[1]+150,'./images/interface_fight.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer,sprite_layers,screen)
    return interface
コード例 #17
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_spec_arrow(renderer, sprite_layers, screen, c_pos):
    interface = person.create_person(c_pos[0] - 700, c_pos[1] - 100,
                                     './images/spec_arrow_interf.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer, sprite_layers, screen)
    return interface
コード例 #18
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_f_i(renderer,sprite_layers,screen,c_pos):
    f_i=person.create_menu_bg(c_pos[0]+500,c_pos[1]+350,'./images/interface_fight_1.png')
    sprite_layers[2].add_sprite(f_i)
    shifty1.render_update(renderer,sprite_layers,screen)

    return f_i
コード例 #19
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface(renderer,sprite_layers,screen,c_pos):
    
    interface=person.create_person(c_pos[0]-512,c_pos[1]-384,'./images/interface1.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer,sprite_layers,screen)
    return interface
コード例 #20
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def warning_msg(map_name, renderer, sprite_layers, screen, c_pos, flag):
    ty = pk.load(open("./save.p", "rb"))
    #if gold is not enough to travel
    if (map_name == './maps/ship.tmx' and flag == 0):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((260, 70), 'Not enough Gold, Laddy', (0, 0, 0), font=font)
        imgtx.save('./images/ship_conf.png')
        ship_conf = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                          './images/ship_conf.png')
        sprite_layers[2].add_sprite(ship_conf)
        shifty1.render_update(renderer, sprite_layers, screen)
        i = 0
        while (i != 1):  ##Infinite loop until menu is to be removed
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN
                        and event.key == pygame.K_SPACE):
                    i = 1
            continue
        sprite_layers[2].remove_sprite(ship_conf)

    elif (map_name == './maps/ship.tmx' and flag == 1):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((260, 70),
                  'Gate not accessible right now', (0, 0, 0),
                  font=font)
        imgtx.save('./images/ship_conf.png')
        ship_conf = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                          './images/ship_conf.png')
        sprite_layers[2].add_sprite(ship_conf)
        shifty1.render_update(renderer, sprite_layers, screen)
        i = 0
        while (i != 1):  ##Infinite loop until menu is to be removed
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN
                        and event.key == pygame.K_SPACE):
                    i = 1
            continue
        sprite_layers[2].remove_sprite(ship_conf)

    #Flag=0-> showing the first message
    elif (map_name == './maps/hotel.tmx' and flag == 0):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((260, 70), 'Welcome to Crossroads Inn', (0, 0, 0), font=font)
        draw.text((260, 110),
                  '(P)ay 50 gold, stay here and recover your health',
                  (0, 0, 0),
                  font=font)
        draw.text((260, 150),
                  '                   Bac(k)', (0, 0, 0),
                  font=font)
        imgtx.save('./images/warning.png')
        warning = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                        './images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer, sprite_layers, screen)
        i = 0
        while (i != 1):
            #event handling -> P pressed-> pay 50 gold
            #                  K pressed-> go back
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_k):
                    i = 1
                    #"pos" list gives the co-ordinates where the hero will be standing after talking to receptionist
                    #if pos=None -> hero's position remains same
                    pos = None
                    sprite_layers[2].remove_sprite(warning)
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_p):
                    sprite_layers[2].remove_sprite(warning)
                    #if able to pay -> pay gold, increase health -> spawn in the hotel room("pos" list)
                    if (ty['gold'] >= 50):
                        ty['gold'] -= 50
                        hero_pos_x = 200
                        hero_pos_y = 920
                        pos = [hero_pos_x, hero_pos_y]
                        ty['hp'] = ty['max_hp']
                        i = 1
                        pk.dump(ty, open("./save.p", "wb"))
                    else:
                        #if pressed pay but dont have enough gold-> next message
                        warning_msg('./maps/hotel.tmx', renderer,
                                    sprite_layers, screen, c_pos, 1)
            continue
        return pos

    #Not enough gold message for the hotel map
    elif (map_name == './maps/hotel.tmx' and flag == 1):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((260, 70),
                  'You Dont have enough money', (0, 0, 0),
                  font=font)
        draw.text((260, 150),
                  '                   Bac(k)', (0, 0, 0),
                  font=font)
        imgtx.save('./images/warning.png')
        warning = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                        './images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer, sprite_layers, screen)
        i = 0
        while (i != 1):
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_k):
                    i = 1
            continue
        sprite_layers[2].remove_sprite(warning)

    #A common warning message to some places in the map -> pops up if the
    #condition for the message fulfilled in the parent file/function
    else:
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((260, 70), 'Something is missing', (0, 0, 0), font=font)
        imgtx.save('./images/warning.png')
        warning = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                        './images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer, sprite_layers, screen)
        return warning
コード例 #21
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def warning_msg(map_name,renderer,sprite_layers,screen,c_pos,flag):
    ty=pk.load(open("./save.p","rb"))
    #if gold is not enough to travel
    if (map_name=='./maps/ship.tmx' and flag==0):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf",30)
        draw.text((260,70),'Not enough Gold, Laddy',(0,0,0),font=font)
        imgtx.save('./images/ship_conf.png')
        ship_conf=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/ship_conf.png')
        sprite_layers[2].add_sprite(ship_conf)
        shifty1.render_update(renderer,sprite_layers,screen)
        i=0
        while(i!=1):                       ##Infinite loop until menu is to be removed
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE):
                    i=1
            continue
        sprite_layers[2].remove_sprite(ship_conf)

    elif (map_name=='./maps/ship.tmx' and flag==1):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf",30)
        draw.text((260,70),'Gate not accessible right now',(0,0,0),font=font)
        imgtx.save('./images/ship_conf.png')
        ship_conf=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/ship_conf.png')
        sprite_layers[2].add_sprite(ship_conf)
        shifty1.render_update(renderer,sprite_layers,screen)
        i=0
        while(i!=1):                       ##Infinite loop until menu is to be removed
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE):
                    i=1
            continue
        sprite_layers[2].remove_sprite(ship_conf)

    #Flag=0-> showing the first message
    elif (map_name=='./maps/hotel.tmx' and flag==0):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf",30)
        draw.text((260,70),'Welcome to Crossroads Inn',(0,0,0),font=font)
        draw.text((260,110),'(P)ay 50 gold, stay here and recover your health',(0,0,0),font=font)
        draw.text((260,150),'                   Bac(k)',(0,0,0),font=font)
        imgtx.save('./images/warning.png')
        warning=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer,sprite_layers,screen)
        i=0
        while(i!=1):
            #event handling -> P pressed-> pay 50 gold
            #                  K pressed-> go back
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_k):
                    i=1
                    #"pos" list gives the co-ordinates where the hero will be standing after talking to receptionist
                    #if pos=None -> hero's position remains same
                    pos=None
                    sprite_layers[2].remove_sprite(warning)
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_p):
                    sprite_layers[2].remove_sprite(warning)
                    #if able to pay -> pay gold, increase health -> spawn in the hotel room("pos" list)
                    if(ty['gold']>=50):
                        ty['gold']-=50
                        hero_pos_x = 200
                        hero_pos_y = 920
                        pos=[hero_pos_x,hero_pos_y]
                        ty['hp']=ty['max_hp']
                        i=1
                        pk.dump(ty,open("./save.p","wb"))
                    else :
                        #if pressed pay but dont have enough gold-> next message
                        warning_msg('./maps/hotel.tmx',renderer,sprite_layers,screen,c_pos,1)
            continue
        return pos

    #Not enough gold message for the hotel map
    elif (map_name=='./maps/hotel.tmx' and flag==1):
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf",30)
        draw.text((260,70),'You Dont have enough money',(0,0,0),font=font)
        draw.text((260,150),'                   Bac(k)',(0,0,0),font=font)
        imgtx.save('./images/warning.png')
        warning=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer,sprite_layers,screen)
        i=0
        while(i!=1):
            for event in pygame.event.get():
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_k):
                    i=1
            continue
        sprite_layers[2].remove_sprite(warning)

    #A common warning message to some places in the map -> pops up if the
    #condition for the message fulfilled in the parent file/function
    else:
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf",30)
        draw.text((260,70),'Something is missing',(0,0,0),font=font)
        imgtx.save('./images/warning.png')
        warning=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/warning.png')
        sprite_layers[2].add_sprite(warning)
        shifty1.render_update(renderer,sprite_layers,screen)
        return warning
コード例 #22
0
def shop(c_pos,renderer,sprite_layers,screen,l_g):
	#variables for two while loops
	shopping = True
	inner = True
	sv=pk.load(open("./save.p","rb"))
	
	#costs of three swords
	costs1=100
	costs2=200
	costs3=300
	#cost of one arrow
	costa=5
	#cost of two armors
	costa1=100
	costa2=150
	#if discount is applicable
	if (sv['f_vil']==1):
		costs1-=30
		costs2-=50
		costs3-=70
		costa1-=30
		costa2-=50
	#list for number keys
	numkey=[pygame.K_1,pygame.K_2,pygame.K_3,pygame.K_4,pygame.K_5,pygame.K_6\
	,pygame.K_7,pygame.K_8]

	#main shopping loop
	while shopping:
		##Base image for upper and lower menu is same
		#Creating tne upper message using the base image
		imgtx = Image.open('./images/textbox.png')
		draw = ImageDraw.Draw(imgtx)
		font = ImageFont.truetype("./PAPYRUS.ttf",30)
		draw.text((270,70),'Welcome!!!',(0,0,0),font=font)
		imgtx.save('./images/shop1.png')
		## the above menu box
		shop_menu1=person.create_menu_bg(c_pos[0],c_pos[1]-768/2,'./images/shop1.png')
		
		imgtx2 = Image.open('./images/textbox.png')
		draw = ImageDraw.Draw(imgtx2)
		font = ImageFont.truetype("./PAPYRUS.ttf",30)
		draw.text((270,20),'What do you want to do?',(0,0,0),font=font)
		draw.text((350,60),'(B)uy',(0,0,0),font=font)
		draw.text((350,100),'(S)ell',(0,0,0),font=font)
		draw.text((350,140),'(L)eave',(0,0,0),font=font)
		imgtx2.save('./images/shop2.png')
		##lower menu box
		shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
		state='m'

		##states -> tell in which menu the player currently is
		#helps to navigate to next menu -> eg. "2" can be option on many menus leading to different ones
		while inner:
			#storing the gold, dagger, arrow count, and armor
			gold=sv['gold']
			sword_have=sv['dagger']
			arrow_c=sv['arrow_count']
			armr_hav=sv['sheild_first']

			##-------------------------Shopping start-------------------
			for event in pygame.event.get():
				if event.type == pygame.KEYDOWN:
					x=event.key
					##MAIN ---> BUY
					if(x==pygame.K_b and state=='m'):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((270,20),'What do you want to buy?',(0,0,0),font=font)
						draw.text((350,60),'Swords (1)           Armor(4)',(0,0,0),font=font)
						draw.text((350,100),'Arrow (2)           Bac(k)',(0,0,0),font=font)
						draw.text((350,140),'Repair Armor (3)',(0,0,0),font=font)						
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						#state changed to b-> buy menu
						state='b'
					##MAIN -> LEAVE
					elif(x==pygame.K_l and state=='m'):
						shopping = False
						inner=False

					##BACK TO -> MAIN -- FROM ALL
					elif(x==pygame.K_k and (state=='b' or state=='s' or state=='a' or state=='r1' \
						or state=='r2' or state=='r3' or state=='r4' or state=='arm' or\
						state=='conf' or state=='sl' or state=='ss' or state=='inv')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((270,20),'What do you want to do?',(0,0,0),font=font)
						draw.text((350,60),'(B)uy',(0,0,0),font=font)
						draw.text((350,100),'(S)ell',(0,0,0),font=font)
						draw.text((350,140),'(L)eave',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='m'

					##BUY -> SWORDS
					elif(x==pygame.K_1 and (state=='b')):
						sprite_layers[2].remove_sprite(shop_menu2)
						#print 'back'
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						swrd1='Longsword (1)      ' + str(costs1)
						swrd2='Two-Edged sword (2)      ' + str(costs2)
						swrd3='Katana (3)      ' + str(costs3)
						draw.text((350,20),swrd1,(0,0,0),font=font)
						draw.text((350,60),swrd2,(0,0,0),font=font)
						draw.text((350,100),swrd3,(0,0,0),font=font)
						draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='s'

					##BUY -> ARMOR
					elif(x==pygame.K_4 and (state=='b')):
						sprite_layers[2].remove_sprite(shop_menu2)
						#print 'back'
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						armr1='Leather(1)      ' + str(costa1)
						armr2='Chainmail (2)      ' + str(costa2)
						draw.text((350,20),armr1,(0,0,0),font=font)
						draw.text((350,60),armr2,(0,0,0),font=font)
						draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='arm'

					#ARMOR -> BUYING ARMOR 1
					elif(x==pygame.K_1 and (state=='arm')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						#if able to buy
						if (gold>=costa1):
							#Check that player can always buy/keep a sword
							if (gold-costa1<100 and sword_have==0):
								draw.text((350,60),'If you Buy this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								draw.text((350,20),'You bought Leather armor',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
								#if armor bought -> gold decrease, shield yes, its max hp, and total hp updated
								sv['gold']=gold-costa1
								sv['sheild_first']=1
								sv['sheild_maxhp']=60
								sv['sheild_hp']=60
								sv['eqp_armour']='lth'
								pk.dump(sv,open("./save.p","wb"))
						#insufficient gold
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#ARMOR -> BUYING ARMOR 2
					elif(x==pygame.K_2 and (state=='arm')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if armr_hav==1:
							draw.text((350,20),'You already have an armor...',(0,0,0),font=font)
							draw.text((350,60),'First you must sell it',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						elif (gold>=costa2):
							#Check that player can always buy/keep a sword
							if (gold-costa2<100 and sword_have==0):
								draw.text((350,60),'If you Buy this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								draw.text((350,20),'You bought Chainmail',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
								sv['gold']=gold-costa2
								sv['sheild_first']=1
								sv['sheild_maxhp']=70
								sv['sheild_hp']=70
								sv['eqp_armour']='chn'
								pk.dump(sv,open("./images/save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#SWORDS -> BUYING SWORD 1
					#same as buying an armor
					elif(x==pygame.K_1 and (state=='s')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if sword_have==1:
							draw.text((350,20),'You already have a sword...',(0,0,0),font=font)
							draw.text((350,60),'First you must sell it',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						elif (gold>=costs1):
							draw.text((350,20),'You bought Longsword',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
							sv['gold']=gold-costs1
							sv['dagger']=1
							#every melee weapon have different damage -> need to update which weapon
							sv['eqp_weapon']='sw1'
							pk.dump(sv,open("./save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#SWORDS -> BUYING SWORD 2
					elif(x==pygame.K_2 and (state=='s')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if sword_have==1:
							draw.text((350,20),'You already have a sword...',(0,0,0),font=font)
							draw.text((350,60),'First you must sell it',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						elif (gold>=costs2):
							sv['gold']=gold-costs2
							sv['dagger']=1
							sv['eqp_weapon']='sw2'
							pk.dump(sv,open("./save.p","wb"))
							draw.text((350,20),'You bought Two-Edged Sword',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
							
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#SWORDS -> BUYING SWORD 3
					elif(x==pygame.K_3 and (state=='s')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if sword_have==1:
							draw.text((350,20),'You already have a sword...',(0,0,0),font=font)
							draw.text((350,60),'First you must sell it',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						elif (gold>=costs3):
							draw.text((350,20),'You bought Katana',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
							sv['gold']=gold-costs3
							sv['dagger']=1
							sv['eqp_weapon']='sw3'
							pk.dump(sv,open("./save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#ARROWS -> BUYING ARROWS 1
					#same as armor and swords
					elif(x==pygame.K_1 and (state=='a')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if (gold>=costa):
							#Check that player can always buy/keep a sword
							if (gold-costa<100 and sword_have==0):
								draw.text((350,60),'If you buy this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								draw.text((350,20),'You bought one arrow',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
								sv['gold']=gold-costa
								sv['arrow_count'] +=1
								pk.dump(sv,open("./save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#ARROWS -> BUYING ARROWS 2 (10 arrows at price of 8)
					elif(x==pygame.K_2 and (state=='a')):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if (gold>=costa*8):
							#Check that player can always buy/keep a sword
							if ((gold-(costa*8))<100 and sword_have==0):
								draw.text((350,60),'If you Buy this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								draw.text((350,20),'You bought a big arrow pock',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
								sv['gold']=gold-(costa*8)
								sv['arrow_count'] +=10
								pk.dump(sv,open("./save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#ARROWS -> BUYING ARROWS 3 (20 arrows at price of 18)
					elif(x==pygame.K_3 and (state=='a')):
						sprite_layers[2].remove_sprite(shop_menu2)
						#print 'back'
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						if (gold>=costa*18):
							#Check that player can always buy/keep a sword
							if ((gold-(costa*18))<100 and sword_have==0):
								draw.text((350,60),'If you Buy this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								draw.text((350,20),'You bought a huge arrow pack',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
								sv['gold']=gold-(costa*18)
								sv['arrow_count'] +=20
								pk.dump(sv,open("./save.p","wb"))
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#BUY -> ARROWS
					elif(x==pygame.K_2 and (state=='b')):
						sprite_layers[2].remove_sprite(shop_menu2)
						#print 'back'
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((350,20),'Buy arrow (1)      5 Gold',(0,0,0),font=font)
						draw.text((350,60),'Buy 10 arrows (2)      40 Gold',(0,0,0),font=font)
						draw.text((350,100),'Buy 20 arrows (3)      90 Gold',(0,0,0),font=font)
						draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='a'

					#BUY TO REPAIR ARMOR (condition -> armor health ful )
					elif(x==pygame.K_3 and (state=='b') and sv['sheild_first']==1\
					and sv['sheild_hp']==sv['sheild_maxhp']):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((350,20),'Your armor is already at full health',(0,0,0),font=font)
						draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='r1'

					#BUY TO REPAIR ARMOR (condition -> armor health not full)
					elif(x==pygame.K_3 and (state=='b') and sv['sheild_first']==1\
					and sv['sheild_hp']<['sheild_maxhp']):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((350,20),'(R)epair armor      30 Gold',(0,0,0),font=font)
						draw.text((350,140),'Back',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='r2'

					#BUY TO REPAIR ARMOR (condition -> no armor )
					elif(x==pygame.K_3 and (state=='b') and sv['sheild_first']==0):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((350,20),'You have no armor to repair',(0,0,0),font=font)
						draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='r4'

					#REPAIR ARMOR -> NEXT (condition -> armr health not full )
					elif(x==pygame.K_r and (state=='r2')):
						sprite_layers[2].remove_sprite(shop_menu2)
						#if able to pay
						#Check that player can always buy/keep a sword
						if gold>=30:
							if (gold-30<100 and sword_have==0):
								draw.text((350,60),'If you repair this you cannot buy a sword',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
							else:
								sv['gold']=gold-30
								sv['sheild_hp']=50
								pk.dump(sv,open("./save.p","wb"))
								imgtx2 = Image.open('./images/textbox.png')
								draw = ImageDraw.Draw(imgtx2)
								font = ImageFont.truetype("./PAPYRUS.ttf",30)
								draw.text((350,20),'Your Armor is repaired',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								imgtx2.save('./images/shop2.png')
						#insufficient gold
						else:
							draw.text((350,20),'You Dont have enough gold',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
							imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='r3'

					#MAIN -> SELL
					elif(x==pygame.K_s and state=='m'):
						sprite_layers[2].remove_sprite(shop_menu2)
						#print 'menu'
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((270,20),'What do you want to sell?',(0,0,0),font=font)
						draw.text((350,60),'Swords (1)',(0,0,0),font=font)
						draw.text((350,100),'From Inventory (2)',(0,0,0),font=font)
						draw.text((350,160),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='sl'

					#SELL -> SWORD
					elif(x==pygame.K_1 and state=='sl'):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						draw.text((350,60),'Sell your Sword (1)',(0,0,0),font=font)
						draw.text((350,150),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='ss'

					#SELL SWORD -> NEXT
					elif(x==pygame.K_1 and state=='ss'):
						wpn=sv['eqp_weapon']
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						#if have no sword
						if wpn==None:
							draw.text((350,60),'You Dont have any sword',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						#if have sword
						#Check that player can always buy/keep a sword
						elif((gold+costs1-30)<100):
							draw.text((350,60),'If you sell this you cannot buy another one',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						else:
							if wpn=='sw1':
								sv['gold']=gold+costs1-30
							elif wpn=='sw2':
								sv['gold']=gold+costs2-60
							elif wpn=='sw2':
								sv['gold']=gold+costs3-120
							elif wpn=='dagger':
								sv['gold']=gold+50
							sv['eqp_weapon']=None
							sv['dagger']=0
							pk.dump(sv,open("./save.p","wb"))
							wpn='You sold '+wpn
							draw.text((350,60),wpn,(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

					#SELL -> SELL FROM INVENTORY
					elif(x==pygame.K_2 and state=='sl'):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)

						inv_len=len(sv['misc'])
						#inventory empty
						if inv_len==0:
							draw.text((350,60),'You dont have anything to sell',(0,0,0),font=font)
							draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						#Creating the text to show up
						else:
							inven=sv['misc']
							inven_item=[]#item names
							inven_cost=[]#item cost
							inven_str=[]#list for their concat string
							for i in range(0,inv_len,2):
								inven_item.append(inven[i])
								inven_cost.append(inven[i+1])

							#concatinating (along with "Back")
							for i in range(0,inv_len/2):	
								inven_list=inven_item[i]+'   '+str(inven_cost[i])+' ('+str(i+1)+')'
								inven_str.append(inven_list)
							inven_str.append('Bac(k)')

							#snippet for printing in two rows
							for j in range(20,150,40):
								if (len(inven_str))!=0:
									draw.text((350,j),inven_str[0],(0,0,0),font=font)
									inven_str.pop(0)
								else:
									break

							for j in range(20,150,40):
								if (len(inven_str))!=0:
									draw.text((700,j),inven_str[0],(0,0,0),font=font)
									inven_str.pop(0)
								else:
									break

						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='inv'

					#selecting item to sell from inventory
					elif(x in numkey and state=='inv'):
						sprite_layers[2].remove_sprite(shop_menu2)
						imgtx2 = Image.open('./images/textbox.png')
						draw = ImageDraw.Draw(imgtx2)
						font = ImageFont.truetype("./PAPYRUS.ttf",30)
						inv_len=len(sv['misc'])
						inven=sv['misc']
						#creation of concat string list
						inven_item=[]
						inven_cost=[]
						inven_str=[]
						for i in range(0,inv_len,2):
							inven_item.append(inven[i])
							inven_cost.append(inven[i+1])

						for i in range(0,inv_len/2):
							if int (chr(x))==i+1:
								item_str='You sold '+inven_item[i]
								#adding the gold to hero's gold
								sv['gold']=gold+inven_cost[i]
								#Poping the sold item
								sv['misc'].pop(i*2)
								sv['misc'].pop(i*2)
								draw.text((350,60),item_str,(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
								pk.dump(sv,open("./save.p","wb"))
							elif int(chr(x))>inv_len/2:
								draw.text((350,60),'Not that many items here',(0,0,0),font=font)
								draw.text((350,140),'Bac(k)',(0,0,0),font=font)
						imgtx2.save('./images/shop2.png')
						shop_menu2=person.create_menu_bg(c_pos[0],c_pos[1]+768/2-270,'./images/shop2.png')
						state='conf'

				#updating the gold interface
				menu.update_lg(l_g,c_pos)
				#removing all the sprites and adding the fresh ones
				sprite_layers[2].remove_sprite(shop_menu1)
				sprite_layers[2].remove_sprite(shop_menu2)
				sprite_layers[2].add_sprite(shop_menu1)
				sprite_layers[2].add_sprite(shop_menu2)
				#rendering
				shifty1.render_update(renderer,sprite_layers,screen)


		if shopping==False:
			#removing the sprites when leaving
			sprite_layers[2].remove_sprite(shop_menu1)
			sprite_layers[2].remove_sprite(shop_menu2)
			shifty1.render_update(renderer,sprite_layers,screen)
コード例 #23
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_dragon(renderer,sprite_layers,screen,c_pos):
    interface=person.create_person(c_pos[0]-400,c_pos[1],'./images/dragon_health_interface.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer,sprite_layers,screen)
    return interface
コード例 #24
0
def shop(c_pos, renderer, sprite_layers, screen, l_g):
    #variables for two while loops
    shopping = True
    inner = True
    sv = pk.load(open("./save.p", "rb"))

    #costs of three swords
    costs1 = 100
    costs2 = 200
    costs3 = 300
    #cost of one arrow
    costa = 5
    #cost of two armors
    costa1 = 100
    costa2 = 150
    #if discount is applicable
    if (sv['f_vil'] == 1):
        costs1 -= 30
        costs2 -= 50
        costs3 -= 70
        costa1 -= 30
        costa2 -= 50
    #list for number keys
    numkey=[pygame.K_1,pygame.K_2,pygame.K_3,pygame.K_4,pygame.K_5,pygame.K_6\
    ,pygame.K_7,pygame.K_8]

    #main shopping loop
    while shopping:
        ##Base image for upper and lower menu is same
        #Creating tne upper message using the base image
        imgtx = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((270, 70), 'Welcome!!!', (0, 0, 0), font=font)
        imgtx.save('./images/shop1.png')
        ## the above menu box
        shop_menu1 = person.create_menu_bg(c_pos[0], c_pos[1] - 768 / 2,
                                           './images/shop1.png')

        imgtx2 = Image.open('./images/textbox.png')
        draw = ImageDraw.Draw(imgtx2)
        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
        draw.text((270, 20), 'What do you want to do?', (0, 0, 0), font=font)
        draw.text((350, 60), '(B)uy', (0, 0, 0), font=font)
        draw.text((350, 100), '(S)ell', (0, 0, 0), font=font)
        draw.text((350, 140), '(L)eave', (0, 0, 0), font=font)
        imgtx2.save('./images/shop2.png')
        ##lower menu box
        shop_menu2 = person.create_menu_bg(c_pos[0], c_pos[1] + 768 / 2 - 270,
                                           './images/shop2.png')
        state = 'm'

        ##states -> tell in which menu the player currently is
        #helps to navigate to next menu -> eg. "2" can be option on many menus leading to different ones
        while inner:
            #storing the gold, dagger, arrow count, and armor
            gold = sv['gold']
            sword_have = sv['dagger']
            arrow_c = sv['arrow_count']
            armr_hav = sv['sheild_first']

            ##-------------------------Shopping start-------------------
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    x = event.key
                    ##MAIN ---> BUY
                    if (x == pygame.K_b and state == 'm'):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((270, 20),
                                  'What do you want to buy?', (0, 0, 0),
                                  font=font)
                        draw.text((350, 60),
                                  'Swords (1)           Armor(4)', (0, 0, 0),
                                  font=font)
                        draw.text((350, 100),
                                  'Arrow (2)           Bac(k)', (0, 0, 0),
                                  font=font)
                        draw.text((350, 140),
                                  'Repair Armor (3)', (0, 0, 0),
                                  font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        #state changed to b-> buy menu
                        state = 'b'
                    ##MAIN -> LEAVE
                    elif (x == pygame.K_l and state == 'm'):
                        shopping = False
                        inner = False

                    ##BACK TO -> MAIN -- FROM ALL
                    elif(x==pygame.K_k and (state=='b' or state=='s' or state=='a' or state=='r1' \
                     or state=='r2' or state=='r3' or state=='r4' or state=='arm' or\
                     state=='conf' or state=='sl' or state=='ss' or state=='inv')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((270, 20),
                                  'What do you want to do?', (0, 0, 0),
                                  font=font)
                        draw.text((350, 60), '(B)uy', (0, 0, 0), font=font)
                        draw.text((350, 100), '(S)ell', (0, 0, 0), font=font)
                        draw.text((350, 140), '(L)eave', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'm'

                    ##BUY -> SWORDS
                    elif (x == pygame.K_1 and (state == 'b')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #print 'back'
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        swrd1 = 'Longsword (1)      ' + str(costs1)
                        swrd2 = 'Two-Edged sword (2)      ' + str(costs2)
                        swrd3 = 'Katana (3)      ' + str(costs3)
                        draw.text((350, 20), swrd1, (0, 0, 0), font=font)
                        draw.text((350, 60), swrd2, (0, 0, 0), font=font)
                        draw.text((350, 100), swrd3, (0, 0, 0), font=font)
                        draw.text((350, 140), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 's'

                    ##BUY -> ARMOR
                    elif (x == pygame.K_4 and (state == 'b')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #print 'back'
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        armr1 = 'Leather(1)      ' + str(costa1)
                        armr2 = 'Chainmail (2)      ' + str(costa2)
                        draw.text((350, 20), armr1, (0, 0, 0), font=font)
                        draw.text((350, 60), armr2, (0, 0, 0), font=font)
                        draw.text((350, 140), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'arm'

                    #ARMOR -> BUYING ARMOR 1
                    elif (x == pygame.K_1 and (state == 'arm')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        #if able to buy
                        if (gold >= costa1):
                            #Check that player can always buy/keep a sword
                            if (gold - costa1 < 100 and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you Buy this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                draw.text((350, 20),
                                          'You bought Leather armor',
                                          (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                                #if armor bought -> gold decrease, shield yes, its max hp, and total hp updated
                                sv['gold'] = gold - costa1
                                sv['sheild_first'] = 1
                                sv['sheild_maxhp'] = 60
                                sv['sheild_hp'] = 60
                                sv['eqp_armour'] = 'lth'
                                pk.dump(sv, open("./save.p", "wb"))
                        #insufficient gold
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #ARMOR -> BUYING ARMOR 2
                    elif (x == pygame.K_2 and (state == 'arm')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if armr_hav == 1:
                            draw.text((350, 20),
                                      'You already have an armor...',
                                      (0, 0, 0),
                                      font=font)
                            draw.text((350, 60),
                                      'First you must sell it', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        elif (gold >= costa2):
                            #Check that player can always buy/keep a sword
                            if (gold - costa2 < 100 and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you Buy this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                draw.text((350, 20),
                                          'You bought Chainmail', (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                                sv['gold'] = gold - costa2
                                sv['sheild_first'] = 1
                                sv['sheild_maxhp'] = 70
                                sv['sheild_hp'] = 70
                                sv['eqp_armour'] = 'chn'
                                pk.dump(sv, open("./images/save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #SWORDS -> BUYING SWORD 1
                    #same as buying an armor
                    elif (x == pygame.K_1 and (state == 's')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if sword_have == 1:
                            draw.text((350, 20),
                                      'You already have a sword...', (0, 0, 0),
                                      font=font)
                            draw.text((350, 60),
                                      'First you must sell it', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        elif (gold >= costs1):
                            draw.text((350, 20),
                                      'You bought Longsword', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                            sv['gold'] = gold - costs1
                            sv['dagger'] = 1
                            #every melee weapon have different damage -> need to update which weapon
                            sv['eqp_weapon'] = 'sw1'
                            pk.dump(sv, open("./save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #SWORDS -> BUYING SWORD 2
                    elif (x == pygame.K_2 and (state == 's')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if sword_have == 1:
                            draw.text((350, 20),
                                      'You already have a sword...', (0, 0, 0),
                                      font=font)
                            draw.text((350, 60),
                                      'First you must sell it', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        elif (gold >= costs2):
                            sv['gold'] = gold - costs2
                            sv['dagger'] = 1
                            sv['eqp_weapon'] = 'sw2'
                            pk.dump(sv, open("./save.p", "wb"))
                            draw.text((350, 20),
                                      'You bought Two-Edged Sword', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')

                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #SWORDS -> BUYING SWORD 3
                    elif (x == pygame.K_3 and (state == 's')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if sword_have == 1:
                            draw.text((350, 20),
                                      'You already have a sword...', (0, 0, 0),
                                      font=font)
                            draw.text((350, 60),
                                      'First you must sell it', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        elif (gold >= costs3):
                            draw.text((350, 20),
                                      'You bought Katana', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                            sv['gold'] = gold - costs3
                            sv['dagger'] = 1
                            sv['eqp_weapon'] = 'sw3'
                            pk.dump(sv, open("./save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #ARROWS -> BUYING ARROWS 1
                    #same as armor and swords
                    elif (x == pygame.K_1 and (state == 'a')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if (gold >= costa):
                            #Check that player can always buy/keep a sword
                            if (gold - costa < 100 and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you buy this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                draw.text((350, 20),
                                          'You bought one arrow', (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                                sv['gold'] = gold - costa
                                sv['arrow_count'] += 1
                                pk.dump(sv, open("./save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #ARROWS -> BUYING ARROWS 2 (10 arrows at price of 8)
                    elif (x == pygame.K_2 and (state == 'a')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if (gold >= costa * 8):
                            #Check that player can always buy/keep a sword
                            if ((gold - (costa * 8)) < 100
                                    and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you Buy this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                draw.text((350, 20),
                                          'You bought a big arrow pock',
                                          (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                                sv['gold'] = gold - (costa * 8)
                                sv['arrow_count'] += 10
                                pk.dump(sv, open("./save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #ARROWS -> BUYING ARROWS 3 (20 arrows at price of 18)
                    elif (x == pygame.K_3 and (state == 'a')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #print 'back'
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        if (gold >= costa * 18):
                            #Check that player can always buy/keep a sword
                            if ((gold - (costa * 18)) < 100
                                    and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you Buy this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                draw.text((350, 20),
                                          'You bought a huge arrow pack',
                                          (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                                sv['gold'] = gold - (costa * 18)
                                sv['arrow_count'] += 20
                                pk.dump(sv, open("./save.p", "wb"))
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #BUY -> ARROWS
                    elif (x == pygame.K_2 and (state == 'b')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #print 'back'
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((350, 20),
                                  'Buy arrow (1)      5 Gold', (0, 0, 0),
                                  font=font)
                        draw.text((350, 60),
                                  'Buy 10 arrows (2)      40 Gold', (0, 0, 0),
                                  font=font)
                        draw.text((350, 100),
                                  'Buy 20 arrows (3)      90 Gold', (0, 0, 0),
                                  font=font)
                        draw.text((350, 140), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'a'

                    #BUY TO REPAIR ARMOR (condition -> armor health ful )
                    elif(x==pygame.K_3 and (state=='b') and sv['sheild_first']==1\
                    and sv['sheild_hp']==sv['sheild_maxhp']):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((350, 20),
                                  'Your armor is already at full health',
                                  (0, 0, 0),
                                  font=font)
                        draw.text((350, 140), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'r1'

                    #BUY TO REPAIR ARMOR (condition -> armor health not full)
                    elif(x==pygame.K_3 and (state=='b') and sv['sheild_first']==1\
                    and sv['sheild_hp']<['sheild_maxhp']):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((350, 20),
                                  '(R)epair armor      30 Gold', (0, 0, 0),
                                  font=font)
                        draw.text((350, 140), 'Back', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'r2'

                    #BUY TO REPAIR ARMOR (condition -> no armor )
                    elif (x == pygame.K_3 and (state == 'b')
                          and sv['sheild_first'] == 0):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((350, 20),
                                  'You have no armor to repair', (0, 0, 0),
                                  font=font)
                        draw.text((350, 140), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'r4'

                    #REPAIR ARMOR -> NEXT (condition -> armr health not full )
                    elif (x == pygame.K_r and (state == 'r2')):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #if able to pay
                        #Check that player can always buy/keep a sword
                        if gold >= 30:
                            if (gold - 30 < 100 and sword_have == 0):
                                draw.text(
                                    (350, 60),
                                    'If you repair this you cannot buy a sword',
                                    (0, 0, 0),
                                    font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                            else:
                                sv['gold'] = gold - 30
                                sv['sheild_hp'] = 50
                                pk.dump(sv, open("./save.p", "wb"))
                                imgtx2 = Image.open('./images/textbox.png')
                                draw = ImageDraw.Draw(imgtx2)
                                font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                                draw.text((350, 20),
                                          'Your Armor is repaired', (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                imgtx2.save('./images/shop2.png')
                        #insufficient gold
                        else:
                            draw.text((350, 20),
                                      'You Dont have enough gold', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                            imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'r3'

                    #MAIN -> SELL
                    elif (x == pygame.K_s and state == 'm'):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        #print 'menu'
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((270, 20),
                                  'What do you want to sell?', (0, 0, 0),
                                  font=font)
                        draw.text((350, 60),
                                  'Swords (1)', (0, 0, 0),
                                  font=font)
                        draw.text((350, 100),
                                  'From Inventory (2)', (0, 0, 0),
                                  font=font)
                        draw.text((350, 160), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'sl'

                    #SELL -> SWORD
                    elif (x == pygame.K_1 and state == 'sl'):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        draw.text((350, 60),
                                  'Sell your Sword (1)', (0, 0, 0),
                                  font=font)
                        draw.text((350, 150), 'Bac(k)', (0, 0, 0), font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'ss'

                    #SELL SWORD -> NEXT
                    elif (x == pygame.K_1 and state == 'ss'):
                        wpn = sv['eqp_weapon']
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        #if have no sword
                        if wpn == None:
                            draw.text((350, 60),
                                      'You Dont have any sword', (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                        #if have sword
                        #Check that player can always buy/keep a sword
                        elif ((gold + costs1 - 30) < 100):
                            draw.text(
                                (350, 60),
                                'If you sell this you cannot buy another one',
                                (0, 0, 0),
                                font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                        else:
                            if wpn == 'sw1':
                                sv['gold'] = gold + costs1 - 30
                            elif wpn == 'sw2':
                                sv['gold'] = gold + costs2 - 60
                            elif wpn == 'sw2':
                                sv['gold'] = gold + costs3 - 120
                            elif wpn == 'dagger':
                                sv['gold'] = gold + 50
                            sv['eqp_weapon'] = None
                            sv['dagger'] = 0
                            pk.dump(sv, open("./save.p", "wb"))
                            wpn = 'You sold ' + wpn
                            draw.text((350, 60), wpn, (0, 0, 0), font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                    #SELL -> SELL FROM INVENTORY
                    elif (x == pygame.K_2 and state == 'sl'):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)

                        inv_len = len(sv['misc'])
                        #inventory empty
                        if inv_len == 0:
                            draw.text((350, 60),
                                      'You dont have anything to sell',
                                      (0, 0, 0),
                                      font=font)
                            draw.text((350, 140),
                                      'Bac(k)', (0, 0, 0),
                                      font=font)
                        #Creating the text to show up
                        else:
                            inven = sv['misc']
                            inven_item = []  #item names
                            inven_cost = []  #item cost
                            inven_str = []  #list for their concat string
                            for i in range(0, inv_len, 2):
                                inven_item.append(inven[i])
                                inven_cost.append(inven[i + 1])

                            #concatinating (along with "Back")
                            for i in range(0, inv_len / 2):
                                inven_list = inven_item[i] + '   ' + str(
                                    inven_cost[i]) + ' (' + str(i + 1) + ')'
                                inven_str.append(inven_list)
                            inven_str.append('Bac(k)')

                            #snippet for printing in two rows
                            for j in range(20, 150, 40):
                                if (len(inven_str)) != 0:
                                    draw.text((350, j),
                                              inven_str[0], (0, 0, 0),
                                              font=font)
                                    inven_str.pop(0)
                                else:
                                    break

                            for j in range(20, 150, 40):
                                if (len(inven_str)) != 0:
                                    draw.text((700, j),
                                              inven_str[0], (0, 0, 0),
                                              font=font)
                                    inven_str.pop(0)
                                else:
                                    break

                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'inv'

                    #selecting item to sell from inventory
                    elif (x in numkey and state == 'inv'):
                        sprite_layers[2].remove_sprite(shop_menu2)
                        imgtx2 = Image.open('./images/textbox.png')
                        draw = ImageDraw.Draw(imgtx2)
                        font = ImageFont.truetype("./PAPYRUS.ttf", 30)
                        inv_len = len(sv['misc'])
                        inven = sv['misc']
                        #creation of concat string list
                        inven_item = []
                        inven_cost = []
                        inven_str = []
                        for i in range(0, inv_len, 2):
                            inven_item.append(inven[i])
                            inven_cost.append(inven[i + 1])

                        for i in range(0, inv_len / 2):
                            if int(chr(x)) == i + 1:
                                item_str = 'You sold ' + inven_item[i]
                                #adding the gold to hero's gold
                                sv['gold'] = gold + inven_cost[i]
                                #Poping the sold item
                                sv['misc'].pop(i * 2)
                                sv['misc'].pop(i * 2)
                                draw.text((350, 60),
                                          item_str, (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                                pk.dump(sv, open("./save.p", "wb"))
                            elif int(chr(x)) > inv_len / 2:
                                draw.text((350, 60),
                                          'Not that many items here',
                                          (0, 0, 0),
                                          font=font)
                                draw.text((350, 140),
                                          'Bac(k)', (0, 0, 0),
                                          font=font)
                        imgtx2.save('./images/shop2.png')
                        shop_menu2 = person.create_menu_bg(
                            c_pos[0], c_pos[1] + 768 / 2 - 270,
                            './images/shop2.png')
                        state = 'conf'

                #updating the gold interface
                menu.update_lg(l_g, c_pos)
                #removing all the sprites and adding the fresh ones
                sprite_layers[2].remove_sprite(shop_menu1)
                sprite_layers[2].remove_sprite(shop_menu2)
                sprite_layers[2].add_sprite(shop_menu1)
                sprite_layers[2].add_sprite(shop_menu2)
                #rendering
                shifty1.render_update(renderer, sprite_layers, screen)

        if shopping == False:
            #removing the sprites when leaving
            sprite_layers[2].remove_sprite(shop_menu1)
            sprite_layers[2].remove_sprite(shop_menu2)
            shifty1.render_update(renderer, sprite_layers, screen)
コード例 #25
0
ファイル: menu.py プロジェクト: akangupt/a-fiery-vengeance
def create_interface_dragon(renderer, sprite_layers, screen, c_pos):
    interface = person.create_person(c_pos[0] - 400, c_pos[1],
                                     './images/dragon_health_interface.png')
    sprite_layers[1].add_sprite(interface)
    shifty1.render_update(renderer, sprite_layers, screen)
    return interface