Log In  

Cart #cardhanddemo-0 | 2020-09-30 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3


This is a demo on how to display the cards in a player's hand. Hope you find this useful!

--the amount of room for the cards to be in
hand_width = 96

--the size of the room in pixels
room_width = 128

--number of cards on screen
card_num = 0

--the width of the card in pixels
card_width = 12

--how many cards until they compress
card_fit_num = flr(hand_width/card_width)

function _update()

    --update card_num
    if btnp(❎) then
        card_num += 1
    end
    if btnp(🅾️) and card_num > 0 then
        card_num -= 1
    end
    --update hand_width
    if btn(⬆️) then
        hand_width += 1
    end
    if btn(⬇️) and hand_width > 12 then
        hand_width -= 1
    end
    card_fit_num = flr(hand_width/card_width)

end

function _draw()

    --draw stuff
    cls(1)
    print("card num:"..card_num,43,50,6)
    print("x to add card",37,58)
    print("c to retract card",29,64)
    print("⬆️⬇️ to change hand size",15,70)

    line(room_width/2-hand_width/2-2,98,room_width/2-hand_width/2-2,117)
    line(room_width/2-hand_width/2+hand_width+1,98,room_width/2-hand_width/2+hand_width+1,117)
    line(room_width/2-hand_width/2-2,98,room_width/2-hand_width/2+hand_width+1,98)
    line(room_width/2-hand_width/2-2,117,room_width/2-hand_width/2+hand_width+1,117)

    --where the magic happens
    if card_num > card_fit_num then
        for i=0,card_num-1 do
            spr(1,(room_width/2-hand_width/2)+(hand_width-card_width)*(i/(card_num-1)),100,2,2)
        end
    else
        for i=0,card_num-1 do
            spr(1,(room_width/2-hand_width/2)+hand_width/2-(card_width*(card_num/2))+(i*card_width),100,2,2)
        end
    end

end
P#82481 2020-09-30 23:27


[Please log in to post a comment]