Making a moving displayable clickable/shootable [SOLVED]

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
blakjak
Veteran
Posts: 224
Joined: Fri Dec 21, 2007 2:36 pm
Location: France
Contact:

Making a moving displayable clickable/shootable [SOLVED]

#1 Post by blakjak »

I'm wondering if something like that would be possible without needing a pygame framework.

I'm not looking for anything fancy, like an fps or whatever. I'm just wondering if it's possible within ren'py proper, to have an event where a moving displayable can be "shot at" by clicking on it with the mouse.
Once the displayable is shot, either the event jumps to a new label, or the displayable calls in another image ( like a target at the first that then becomes a target with a bullet hole ).

The idea came up playing " Crimsoness" in whitch there is a timer and an imagemap, but imagemap can't move can it ?
Also, could the cursor be crosshaired for just this event ?

Thanx for any input on this. :)
Last edited by blakjak on Mon Jan 26, 2009 8:57 am, edited 2 times in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Making a moving displayable "clickable" for a sniping event

#2 Post by PyTom »

You can certainly use ui.at with Move and an ui.imagebutton. You can also use user-defined displayables for more complexity and control.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

blakjak
Veteran
Posts: 224
Joined: Fri Dec 21, 2007 2:36 pm
Location: France
Contact:

Re: Making a moving displayable "clickable" for a sniping event

#3 Post by blakjak »

Thank you for your reply, I'll look into that.

blakjak
Veteran
Posts: 224
Joined: Fri Dec 21, 2007 2:36 pm
Location: France
Contact:

Re: Making a moving displayable "clickable" for a sniping event

#4 Post by blakjak »

Ok so I've come up with some sort of mini demo. Please unzip in the renpy main folder, and tell me what you guys think, I'm a beginner coder, so there may have things I overlooked.

BTW does anyone know if it is possible to have both a move function and a factorzoom on a displayable ? Like what exists for Rotozoom, but with Move ?
Attachments
game.zip
(638.81 KiB) Downloaded 71 times
Last edited by blakjak on Fri Jan 02, 2009 6:51 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Making a moving displayable "clickable" for a sniping event

#5 Post by PyTom »

Yeah, you can just compose Move and Zoom. Something like:

Code: Select all

ui.add(At("foo.png", FactorZoom(...), Move(...))
The one thing is that it may not be possible to FactorZoom a button. That's something I'm considering trying to address. The next release of Ren'Py will have a mildly more convenient way of doing this.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

blakjak
Veteran
Posts: 224
Joined: Fri Dec 21, 2007 2:36 pm
Location: France
Contact:

Re: Making a moving displayable clickable/shootable : solved

#6 Post by blakjak »

Ok well I think I'm doing something wrong here because I can't figure out how the ui.add function can control the ui.imagebutton's behaviour ( it does work very well but with an image only).

Code: Select all

    
    $ ui.add(At( "target.png", FactorZoom(1.0, 3.0, 2.0, opaque=False), center, Move((0.2, 0.5), (0.8, 0.5), 1.0, repeat=True, bounce=True,
                xanchor="center", yanchor="center")))   

    $ ui.at (FactorZoom(1.0, 3.0, 2.0, opaque=False), center, Move((0.2, 0.5), (0.8, 0.5), 1.0, repeat=True, bounce=True,
                  #xanchor="center", yanchor="center"))
    
    # Defining the u.i imagebutton for the target and specifying the label it calls.
    $ ui.imagebutton("target.png", "target.png", clicked=ui.returns (1))

    $ result = ui.interact()
    if result == 1:
                jump target_hit
No worries though, my aim was to have a moving dysplayable shootable, and that works fine.

Thank you again.

Jo'ogn
Veteran
Posts: 398
Joined: Sat Jul 12, 2008 1:31 pm
Projects: Kassiopeia [iVN]
Location: Deutschland
Contact:

Re: Making a moving displayable clickable/shootable : solved

#7 Post by Jo'ogn »

Looking good!
Widget
These are generally used with the ui functions, but may sometimes be used as displayables.
Now, can a moving clickable displayable be placed behind another image?

Afaik "ui." is on the transient layer and cannot be behind a shown scene on the master layer? I didn't try ui.layer in that respect, yet.

JQuartz
Eileen-Class Veteran
Posts: 1265
Joined: Fri Aug 31, 2007 7:02 am
Projects: 0 completed game. Still haven't made any meaningfully completed games...
Contact:

Re: Making a moving displayable clickable/shootable : solved

#8 Post by JQuartz »

I think you can. The concept is the more later you code an ui, the more front it becomes. The following code should show you the clickable behind another clickable.

Code: Select all

    $ ui.at(Move((0.0, 0.5, 1.0, 0.5), (0.5, 0.5, 0.5, 0.5), 1.0))
    $ ui.textbutton("Click Me!", clicked=ui.jumps('start'),xminimum=200, yminimum=200)
    $ ui.textbutton('hekko',clicked=ui.jumps('start'),xpos=0.4, ypos=0.4, xminimum=100, yminimum=100)
    $ ui.interact()
Edit: Turns out the there's an indentation problem with the given code. Edited it.
Last edited by JQuartz on Fri Jan 09, 2009 4:29 pm, edited 2 times in total.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.

electric
Regular
Posts: 155
Joined: Mon Nov 10, 2008 8:06 am
Location: France
Contact:

Re: Making a moving displayable clickable/shootable : solved

#9 Post by electric »

This is sweet, I could actually use this type of code in my project

blakjak
Veteran
Posts: 224
Joined: Fri Dec 21, 2007 2:36 pm
Location: France
Contact:

Re: Making a moving displayable clickable/shootable : solved

#10 Post by blakjak »

JQuartz wrote:I think you can. The concept is the more later you code an ui, the more front it becomes. The following code should show you the clickable behind another clickable.

Code: Select all

    $ ui.at(Move((0.0, 0.5, 1.0, 0.5), (0.5, 0.5, 0.5, 0.5), 1.0))
    $ ui.textbutton("Click Me!", clicked=ui.jumps('start'),xminimum=200, yminimum=200)
    $ ui.textbutton('hekko',clicked=ui.jumps('start'),xpos=0.4, ypos=0.4, xminimum=100, yminimum=100)
    $ ui.interact()
Edit: Turns out the there's an indentation problem with the given code. Edited it.
This is interesting, it means If the player cliks outside the moving displayable, then the clickable behind could act as a "missed your shot" region.

Correct me if I'm wrong but I recall that being discussed in a thread , specifically that having a button on top of another is not recommended ?

Anyway, I'll have to try this at home. thanx for the idea.

Post Reply

Who is online

Users browsing this forum: jeffster