Help with burger stacking layeredimage logic

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Help with burger stacking layeredimage logic

#1 Post by GeeSeki »

So I'm working on a burger assembly thing and I've got a sorta-working prototype of it but the problem is that the ypos of the layers are all hardcoded.

Code: Select all

label lbl_burger_plate:
    $ on_plate.append(Ingredient.beefpatty.id)
    $ Ingredient.beefpatty.stock -= 1
    $ stacklayer.append("beefpatty")
    $ stacklayer_count += 1
    call lbl_check_plate
    call screen scr_drag_and_drop

layeredimage burgerstack:
        always:
            "/images/ingredients/ing_bottombun.png" xalign 0.5 ypos 550
        if stacklayer_count >= 1:
            "/images/ingredients/ing_[stacklayer[1]].png" xalign 0.5 ypos 500
        if stacklayer_count >= 2:
            "/images/ingredients/ing_[stacklayer[2]].png" xalign 0.5 ypos 450
        if stacklayer_count >= 3:
            "/images/ingredients/ing_[stacklayer[3]].png" xalign 0.5 ypos 400
        if stacklayer_count >= 4:
            "/images/ingredients/ing_[stacklayer[4]].png" xalign 0.5 ypos 350
        if stacklayer_count >= 5:
            "/images/ingredients/ing_[stacklayer[5]].png" xalign 0.5 ypos 300
        if stacklayer_count >= 6:
            "/images/ingredients/ing_[stacklayer[6]].png" xalign 0.5 ypos 250
        if stacklayer_count >= 7:
            "/images/ingredients/ing_[stacklayer[7]].png" xalign 0.5 ypos 200
        if stacklayer_count >= 8:
            "/images/ingredients/ing_[stacklayer[8]].png" xalign 0.5 ypos 150
        if stacklayer_count >= 9:
            "/images/ingredients/ing_[stacklayer[9]].png" xalign 0.5 ypos 100
        if stacklayer_count >= 10:
            "/images/ingredients/ing_[stacklayer[10]].png" xalign 0.5 ypos 50
I wanted to use a list to hold numeral values ( stacklayer_ypos = [] ) and then call it in the layeredimage

Code: Select all

if stacklayer_count >= 1:
            "/images/ingredients/ing_[stacklayer[1]].png" xalign 0.5 ypos stacklayer_ypos[1] 

but it won't let me use that? It only accepts variables, so then I tried putting stacklayer_ypos[1] into a variable and doing

Code: Select all

ypos stacklayer_ypos1
but that didn't work either.

I want it that ways because there may be instances where the player will add sauce and the sauce image won't nearly needed as much ypos distance as the solid fillings, and they would be able to add sauce on any layer. So I need the burger to look coherent for that instance. I want to be able to tell each layer how far up to go based on what the filling below it is.

Any help would be great, I've been scratching my head at this forever and what I have above is the best I can do.
Attachments
A preview of what it looks like, no sauce image is added yet
A preview of what it looks like, no sauce image is added yet

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Help with burger stacking layeredimage logic

#2 Post by Remix »

A dynamic composite might be simplest...

Code: Select all

init python:

    def burger_composite(st at):
        bun_height = 50 * (len(stacklayer)+1)
        return Composite(
            (400, bun_height), ### the size
            (0, bun_height - 50), "/images/ingredients/ing_bottombun.png", ### the base placed at image height minus 50
            ## extra layers comprehended through list flattening, placed at 50px higher per layer
            *[ f for g in 
                [((0, bun_height - (idx*50)), "/images/ingredients/ing_{}.png".format(k)) for idx, k in enumerate(stacklayer, start=2)]
                for f in g ] ), 0.1

image burgerstack = DynamicDisplayable(burger_composite)
Note: As burger gets taller, image too gets taller (so position it using an anchor at base)
Frameworks & Scriptlets:

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Help with burger stacking layeredimage logic

#3 Post by Remix »

For complex versions with variable height sauces and cheese etc we would need to first see your data setup for handling those values...

In general though, you just have a function to return a composite that is comprised of pairs of values representing:
(x pos, y pos), "the image"
Frameworks & Scriptlets:

User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Re: Help with burger stacking layeredimage logic

#4 Post by GeeSeki »

Remix wrote: Wed Apr 14, 2021 1:41 pm A dynamic composite might be simplest...

Code: Select all

init python:

    def burger_composite(st at):
        bun_height = 50 * (len(stacklayer)+1)
        return Composite(
            (400, bun_height), ### the size
            (0, bun_height - 50), "/images/ingredients/ing_bottombun.png", ### the base placed at image height minus 50
            ## extra layers comprehended through list flattening, placed at 50px higher per layer
            *[ f for g in 
                [((0, bun_height - (idx*50)), "/images/ingredients/ing_{}.png".format(k)) for idx, k in enumerate(stacklayer, start=2)]
                for f in g ] ), 0.1

image burgerstack = DynamicDisplayable(burger_composite)
Note: As burger gets taller, image too gets taller (so position it using an anchor at base)
I managed to get the burger to stack vertically upwards and "anchor" the bottombun in place but I still can't really change how many pixels each stack should go up by.

Code: Select all

def burger_composite(st, at):
        bun_height = (getattr(Ingredient, topstack).stackheight) * (len(stacklayer)+0) + 50
        return Composite(
            (468, bun_height), ### the size
            ## extra layers comprehended through list flattening, placed at 50px higher per layer
            *[ f for g in
                [((0, bun_height - (idx*50)), "/images/ingredients/ing_{}.png".format(k)) for idx, k in enumerate(stacklayer, start=1)]
                for f in g ] ), 0.1
I've added a topstack variable that grabs which ingredient was last placed so it can grab the Ingredient.(topstack).stackheight value.

Code: Select all

## Ingredients
init -14 python:
    class Ingredient:
        ## Ingredients
        bottombun = Ingredient(
            "bottombun",
            "Bottombun",
            grade = "S",
            price = 0,
            profit = 200,
            stock = 0,
            stackheight = 0
        )
        beefpatty = Ingredient(
            "beefpatty",
            "Beef Patty",
            grade = "F",
            price = 0,
            profit = 200,
            stock = 0,
            stackheight = 50
        )
        veggiepatty = Ingredient(
            "veggiepatty",
            "Veggie Patty",
            grade = "F",
            price = 0,
            profit = 200,
            stock = 0,
            stackheight = 5
        )
I played around with trying to work out the logic and calculations but I can't seem to get it. What I was thinking was having the game add all the stackheights together as each layer is added and that can be used to determine where to put the next layer but not sure how to do that.

Code: Select all

label lbl_veggie_plate:
    $ on_plate.append(Ingredient.veggiepatty.id)
    $ Ingredient.veggiepatty.stock -= 1
    $ stacklayer.append("veggiepatty")
    $ topstack = "veggiepatty"
    call lbl_check_plate
    call screen scr_drag_and_drop

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot]