Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Mon May 20, 2013 1:46 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Feb 07, 2012 10:51 pm 
Miko-Class Veteran
User avatar

Joined: Mon Dec 13, 2010 9:30 am
Posts: 842
Location: New Brunswick, Canada
Projects: Camp Renard
I am breaking this tutorial up in sections. This first part deals is the bare minimum to get you started.

This tutorial assumes you know the basics of programming in Ren'py and the basics of creating an image.

1. Start a new project

2. Add the hidden object code + the empty_* images to the game directory (can be found in the zip file attached to this post)

3. Create your image pack (Or just use mine :) )
Create images in your favorite image editor using layers: background, objects, foreground
Save as transparent png!
  • image_ground.png - base image with all objects
  • image_hover.png - just the hidden objects and anything over them
  • image_insensitive - base image with the objects how they look when found
  • image_sensitive_idle - just the hidden objects in hint mode
  • image_empty - not needed, but nice to have as a background
in the tutorial, I am using images called locker_*.png

4. Put the following code in script.rpy
Code:
image bg locker = "locker_empty.png"

init python:
    locker_items = []

##
# The game starts here.
label start:
   
    $ start = renpy.time.time()
    # this sets all the items back to not found
    $ resetItems(locker_items)
    # which image set to use
    $ hidden_files = "locker_%s.png"
    # randomize the list and pick 5 items
    $ hidden_items = renpy.random.sample(locker_items,0)
    # set number of hints
    $ num_hints = 3
    # set number of extra clicks
    $ num_clicks = 0
   
   
    scene bg locker
    "Get ready to find the items!"
   
    $ showitems = True
    call screen hidden_object
   
    scene bg locker
    $ elapsed = round(renpy.time.time() - start)
    "Result: [_return] in [elapsed] seconds with [num_clicks] extra clicks!"
 


5. And launch it!
Image

WHOA! What a boring game.

We are just running it to get at a useful tool in Renpy: The Developer menu!

6. Hit Shift+D to bring up the Developer menu
Image

7. Click on Image Location Picker

8. Choose your hover image to get the pixel locations of your objects

9. Highlight the area around the object
Image
The coordinates appear in the lower left of the screen

10. Now you have the laborous task of adding your items to the code using format:
locker_items.append(Item("Item Name", x,y,width,height))
For each item using the numbers given in the picker in the same order.


Now the init block should look like this:
Code:
 init python:
    locker_items = []
    locker_items.append(Item("teddy", 362,325,95,103))
    locker_items.append(Item("pen", 193,396,100,36))
    locker_items.append(Item("bookmark", 240,454,56,101))
    locker_items.append(Item("crackers",189,112,167,63))
    locker_items.append(Item("mirror",528,73,91,129))
    locker_items.append(Item("photo",515,296,98,99))
    locker_items.append(Item("pencil case",380,153,109,134))
    locker_items.append(Item("book",346,0,80,83))
    locker_items.append(Item("card",648,159,83,61))
    locker_items.append(Item("flower",295,238,43,48))

11. Change this line so you have items to find:
$ hidden_items = renpy.random.sample(locker_items,5)

12. Launch!

You now have a basic hidden object game

Susan
EDIT: Duplicate line in code


Attachments:
File comment: The basic files + the images used in the tutorial.
tutorial.zip [1.4 MiB]
Downloaded 200 times

_________________
In order to understand recursion, one must first understand recursion. (Anonymous)
Top
 Profile Send private message  
 
PostPosted: Wed Feb 08, 2012 2:46 am 
Eileen-Class Veteran
User avatar

Joined: Thu Oct 14, 2010 3:53 am
Posts: 1063
Location: NC, USA
Completed: Torrey & the Vampire, Faery Tale, Madaline's Missing Miscellany, Alchemical Ink, Yaoi Story, The Visitor, Erotic Story Generator, What Kind of Fiction Should YOU Write? (Quiz Game), Falling
Organization: Erotic Visions - VNs
I have no clue why, but when I apply your code to my game, I get this:
Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 103, in script
        call screen hidden_object
  File "game/HiddenObjectCode.rpy", line 361, in python
            imagebutton auto "empty_%s.png" action registerClick()
Exception: Not a displayable: None

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\execution.py", line 261, in run
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\ast.py", line 1413, in execute
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\ast.py", line 1426, in call
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\statements.py", line 100, in call
  File "common/00statements.rpy", line 540, in execute_call_screen
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\exports.py", line 1533, in call_screen
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\ui.py", line 237, in interact
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\core.py", line 1809, in interact
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\core.py", line 555, in replace_transient
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\core.py", line 825, in remove
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\core.py", line 753, in hide_or_replace
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\screen.py", line 176, in _hide
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\screen.py", line 245, in update
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\screenlang.py", line 1166, in __call__
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\python.py", line 977, in py_exec_bytecode
  File "game/HiddenObjectCode.rpy", line 361, in <module>
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\ui.py", line 435, in __call__
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\ui.py", line 711, in _imagebutton
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\display\behavior.py", line 681, in __init__
  File "J:\!Kenetic Novels\RenPy\renpy-6.13.8\renpy\easy.py", line 129, in displayable
Exception: Not a displayable: None

Windows-post2008Server-6.1.7601-SP1
Ren'Py 6.13.8.1675
Madeline's Misplaced Miscellany 1.0


This is my Hidden Object screen: (line 361)
Code:
screen hidden_object:
    tag hidden
   
    imagemap:
        auto hidden_files
        cache False
       
        imagebutton auto "empty_%s.png" action registerClick()
        hotspot (896,676,126,90) action getHint()   
           
        for index, item in enumerate(hidden_items):
            hotspot (item.x,item.y,item.w,item.h) action If(hidden_items[index].found==False, SetItem(hidden_items[index],"found",True), None)
        if is_all_found():
            textbutton "All Objects Found!" xalign 0.5 yalign 0.5 action Return("Completed")


This is what's in my script:
Code:
label parlor_game:   
    hide Miss01
    scene black
   
    $ showitems = False
   
    play music "02 - the dragonfly.mp3" fadeout 1.0
   
    $ game = renpy.time.time()
    $ resetItems(parlor_items)
    $ hidden_files = "parlor_%s.png"
    $ hidden_items = renpy.random.sample(parlor_items,10)
   
    $ num_hints = 3
    $ num_clicks = 0
   
    scene bg parlor
    "Are you ready?"
   
    $ showitems = True
    call screen hidden_object
   
    scene bg parlor
    $ elapsed = (renpy.time.time() - game)
    "Result: [_return] in [elapsed] seconds with [num_clicks] miss-clicks!"
    $ showitems = False
   
    show Miss01 at right with dissolve
    "Oh dear, what I'm looking for wasn't in the parlor."
    "I suppose you're wondering why the place has so many old fashioned things in it. Well, it's because I've been here for a {i}very{/i} long time."
    "Shall we look in another room?"
   
    jump room_choice


Just so you know, I DO have these pngs:
empty_empty.png
empty_ground.png
empty_hover.png
empty_selected.png
empty_insensitive.png

And I haven't even added the penalty jump for over 5 miss-clicks, yet!

_________________
Ookami Kasumi ~ Purveyor of fine Smut.
Erotic Visions ~ Visual Novels

"No amount of great animation will save a bad story." -- John Lasseter of Pixar


Last edited by OokamiKasumi on Wed Feb 08, 2012 8:33 pm, edited 1 time in total.

Top
 Profile Send private message  
 
PostPosted: Wed Feb 08, 2012 9:09 am 
Veteran
User avatar

Joined: Sun Oct 09, 2011 11:15 pm
Posts: 390
Projects: Dream's Dénouement
Organization: Team ANARKY
Thanks Suzan! I'm sure many will put this to good use. :)

@OokamiKasumi: I don't think you need empty_empty.png and empty_selected.png, but you are missing empty_idle.png...

_________________
Image Free hosting or website for your VN


Top
 Profile Send private message  
 
PostPosted: Wed Feb 08, 2012 8:24 pm 
Eileen-Class Veteran
User avatar

Joined: Thu Oct 14, 2010 3:53 am
Posts: 1063
Location: NC, USA
Completed: Torrey & the Vampire, Faery Tale, Madaline's Missing Miscellany, Alchemical Ink, Yaoi Story, The Visitor, Erotic Story Generator, What Kind of Fiction Should YOU Write? (Quiz Game), Falling
Organization: Erotic Visions - VNs
leon wrote:
@OokamiKasumi: I don't think you need empty_empty.png and empty_selected.png, but you are missing empty_idle.png...


Thanks Leon!
-- I changed the empty_empty.png to empty_idle.png and it worked!
I knew I'd missed something simple.

_________________
Ookami Kasumi ~ Purveyor of fine Smut.
Erotic Visions ~ Visual Novels

"No amount of great animation will save a bad story." -- John Lasseter of Pixar


Top
 Profile Send private message  
 
PostPosted: Mon Feb 27, 2012 7:08 pm 
Newbie
User avatar

Joined: Tue Jun 28, 2011 10:27 pm
Posts: 9
First off, this is fantastic, and just what I've been looking for. This is a real blessing.

Now, I'm still new to Ren'py (and python in general) programming, so I'm having a little trouble with this, so you know where I'm coming from. 8)

In a lot of hidden object games, clicking on an object often results in a sound playing and a special effect. Now, I don't want to be as elaborate as having the object fly off the screen or anything, but I'd like to be able to play a sound and a dissolve or another transition.

How might I do that?


Top
 Profile Send private message  
 
PostPosted: Mon Feb 27, 2012 10:32 pm 
Eileen-Class Veteran
User avatar

Joined: Thu Oct 14, 2010 3:53 am
Posts: 1063
Location: NC, USA
Completed: Torrey & the Vampire, Faery Tale, Madaline's Missing Miscellany, Alchemical Ink, Yaoi Story, The Visitor, Erotic Story Generator, What Kind of Fiction Should YOU Write? (Quiz Game), Falling
Organization: Erotic Visions - VNs
MikeConway wrote:
...I'd like to be able to play a sound and a dissolve or another transition.
How might I do that?

I was able to achieve a sound and a disappearance --> Madeline's Misplaced Miscellany.

The disappearance was caused by the differences between the ground.png and the empty.png.
Attachment:
File comment: parlor_ground.png
parlor_ground.png
parlor_ground.png [ 1.58 MiB | Viewed 2850 times ]

Attachment:
File comment: parlor_empty.png
parlor_empty.png
parlor_empty.png [ 1.54 MiB | Viewed 2850 times ]


The sound was triggered by adding this to the options.rpy: style.imagemap_button.activate_sound = "Sonar.wav" like so:
Code:
    ## Sounds that are used when button and imagemaps are clicked.

    style.button.activate_sound = "click.wav"
    style.imagemap.activate_sound = "click.wav"
    style.imagemap_button.activate_sound = "Sonar.wav"

_________________
Ookami Kasumi ~ Purveyor of fine Smut.
Erotic Visions ~ Visual Novels

"No amount of great animation will save a bad story." -- John Lasseter of Pixar


Top
 Profile Send private message  
 
PostPosted: Sat Oct 27, 2012 9:59 am 
Newbie

Joined: Sat Oct 27, 2012 9:08 am
Posts: 3
Location: Guimaraes - Portugal
Projects: Dark Deeds - Awakening (will take some time)
Hey,
Ive been following this tutorial and building up my game over this knowledge and also from Ookami's Madeleine's (which is brutal, in a good sense!).

So far I have a tiny 2 HO maps game. I am ages away from having this finished - I'm learning as I go.
I have to many questions, but most are getting answered by themselves when I check some forum posts or mess with the code. Others, well, are being a pain...

At this point, I'm curious on 2 things I can't manage to code by my own:

-> How can I change the Item-List and Hint spots and appearance? I was thinking on putting them down the screen (where usually the text shows), and having a custom shape for the hint (a magic lamp in this case, that would change its image when hint time is full or empty).

-> About their locations in GUI, I think it's a matter of finding the right x/y coordinates? I've tried everywhere in screens and hidden object code files, I can break the game but not changing the spot with success :p

-> About the Hint becoming a image map fixed over the HO room, I don't even know if it is possible with Ren'py;

Some enlightment over this would be very very welcome :o)
Excuse the broken english, I try ;o) Thanks for reading!

PS - maybe I could share in a private message all the features Im trying to implement in this game? Most are just the common stuff to the HO/VN genres (room actions, inventory, etc).


Top
 Profile Send private message  
 
PostPosted: Wed Apr 24, 2013 9:25 pm 
Miko-Class Veteran
User avatar

Joined: Mon Dec 13, 2010 9:30 am
Posts: 842
Location: New Brunswick, Canada
Projects: Camp Renard
Version 2!

This takes a completely different approach:
- Each item is in it's own image file
- these images are cropped and turned into image buttons

Attachment:
background_together.png
background_together.png [ 1.06 MiB | Viewed 237 times ]


And
* drumroll please *
It works on Android!

To check the code out, download the zip file and unzip into your Renpy Files directory.

If anyone is interested, I write out my workflow.

Susan


Attachments:
File comment: The Android Version!
HiddenObject2-1.1-release.apk [28.78 MiB]
Downloaded 4 times
File comment: Sorry about the size -- lots of images!
H2O.zip [24.46 MiB]
Downloaded 21 times

_________________
In order to understand recursion, one must first understand recursion. (Anonymous)
Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group