Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Pages: 1 2 [All]

Author Topic: Sliding a letter onto a spot  (Read 5045 times)

0 Members and 1 Guest are viewing this topic.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Sliding a letter onto a spot
« on: August 03, 2009, 04:23:30 AM »

I've figured out how to code a scene so you can slide a scene object, for example, a letter around.

It's a word game.  I've done it where you have letters in a scene, take the letters into your inventory and slide them onto a specific slot for each letter to spell a word but I want to be able to not take the letters into inventory but just use them them in the scene and slide them onto slots in the scene to spell the word.  If they're wrongly in the slot, that's ok, you just have to do it over. 

I can slide the letters around but am having trouble getting them to stick on the slot that is meant for each one. 

I can post some code tomorrow if that would help. 

Just for my information, is it possible to use "on object"  for example "on LetterA" in the scene if Letter A is in the scene and not in your inventory---or does "on" only work with inventory items?  Thanks for any enlightenment.

I haven't exhausted every possibility but hoping someone has already done this. Thanks.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

maze

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 59
  • Good news
    • View Profile
Re: Sliding a letter onto a spot
« Reply #1 on: August 03, 2009, 09:31:08 AM »

Hi Cat,

I think what you need is a second inventory which is always open. I never done something like this, but there is stuff about this here at the forum.
Hope that brings you back on your way.
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #2 on: August 03, 2009, 04:01:00 PM »

Thanks, maze, but I'm hoping to do it without a second inventory. 

I’m using modified code from old posts from the Derman and Warmblood to make the sliding effect which works fine—my problem is getting the entity under the game selected item to change its graphic when the selected item hovers over it at the same x and y and delete the game selected item. 

http://forum.dead-code.org/index.php?topic=2269.0

http://forum.dead-code.org/index.php?topic=2985.0

I will keep trying for a bit and if nothing works, will try a second hidden inventory. 

Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Sliding a letter onto a spot
« Reply #3 on: August 03, 2009, 10:03:43 PM »

I don't understand the relation to inventory items. The threads you linked use scene entities. You just move the entities around with mouse.

EDIT: If I were you, I wouldn't tie the pieces to inventory items at all. Perhaps have a scene with predefined entities for each letter. Upon entering the puzzle scene, display or hide some letters depending on what the player has in their inventory. Then just use the entity shuffling code to move the letters around. Does that sound feasible?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #4 on: August 03, 2009, 10:11:39 PM »

Hi, Mnemonic--I'm not using inventory items -- just entities in the scene---I can move the entities around.  I have about 9 letters in the overlay.  You can slide 7 of the letters correctly onto an area where there is a blank slot to hold each letter  (sprite entity) to spell the word ---the extra 2 are just red herrings---but they don't stick (snap) to the spot each is supposed to snap to.

F.E. MYSTERY

I can slide the M to the M spot but it doesn't snap in--nothing happens.  Thanks for your help.

I'm not clear what you mean by display or hide some letters depending on what the player has in their inventory?  Or what entity shuffling code is.  Although I will search it in the forum. Thanks again.
« Last Edit: August 03, 2009, 10:15:52 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Sliding a letter onto a spot
« Reply #5 on: August 03, 2009, 10:16:23 PM »

In other words, you mean the entity doesn't get the mouse release event? How do the entities look like? Are those just rectangles, or some irregular shapes?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #6 on: August 03, 2009, 10:18:13 PM »

The entity does get mouse release event using warmblood's code.  The  entities are pngs for letters (the entities you can move around).  They should each snap into a separate slot to hold each letter to display word, f.e. mystery.  I can post my code later tonight.

The entities that hold the letters are blank colored circles -- like old fashioned typewrite keys.  so

  ()   ()    ()   ()  ()   ()  ()

M   S  R  F  G  T  Y  E L
« Last Edit: August 03, 2009, 10:20:21 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Sliding a letter onto a spot
« Reply #7 on: August 03, 2009, 10:22:03 PM »

Yes... but do the pngs have transparent areas? If there are holes in them, and you release the mouse button while the mouse pointer is above the hole, the entity will not receive the release event and it will not "snap". Is that the case?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #8 on: August 03, 2009, 10:28:14 PM »

OH, oh!  I will try jpgs.  Thanks!
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Sliding a letter onto a spot
« Reply #9 on: August 03, 2009, 11:00:53 PM »

Yes... but do the pngs have transparent areas? If there are holes in them, and you release the mouse button while the mouse pointer is above the hole, the entity will not receive the release event and it will not "snap". Is that the case?


Is there anyway to avoid that behavior? I have that problem for example with an inventory item, which is a thin wooden pole, so the user has to do "pixelhunting"....WHats a neat way to avoid that?
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #10 on: August 04, 2009, 04:17:11 AM »

Mnemonic, could you help me here---  Right now I have the sliding effect working perfectly but trying to figure out how to test when every letter is on its right slot.  Am trying to match up the X's and Y's but it doesn't seem to work.

What exactly happens when you slide a scene entity onto another scene entity (in a layer)?  How can they interact? And how can you test whether they match up?  MY x,y test doesn't seem to be working.

F.e.
{if (EntSlot1.X==EntLetterM.X)
{do something because everything is fine
}
}

Both EntSlot1 and EntLetterM now take up the same space because I slid M onto Slot1 and their X values should match up---maybe I have to be more precise--

so everything is not fine but getting there -- will work on it somemore tomorrow in a different way  : )

@Spellbreaker:  To avoid that for example with a wand, I put a special effect behind or over the wand (like a flameball or puff of smoke) to graphically make it thick enough in the middle so that there's no pixel hunting--it is a pain for sure otherwise.  :  )  My crowbar f.e. now is a bar with a crow head curving into the bar to give it that thickness--it does get challenging!

« Last Edit: August 04, 2009, 05:39:45 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Sliding a letter onto a spot
« Reply #11 on: August 04, 2009, 03:24:42 PM »

Quote
if (EntSlot1.X==EntLetterM.X)
{do something because everything is fine
}
}
You will want to be more tolerant with the player:) This way they'd have to hit the exact spot. IMO a good and natural way is to:

1) Define the slot rectangle somehow. I don't know how your slots are done; if you are using entities for slots, then use the entity's X and Y position to define the top-left point, and add the width/height of the entity to get the lower-left point (you'll need to hardcode the width/height, because you can't read entity size in wme script).
2) When the player drops the letter, check if the center point of the letter entity is within the slot rectangle.


Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. function OnDropEntity(var DroppedEntity)
  3. {
  4.   var NumSlots = 5;
  5.  
  6.   var SlotWidth = 100;
  7.   var SlotHeight = 100;
  8.  
  9.   var LetterWidth = 100;
  10.   var LetterHeight = 100;
  11.  
  12.  
  13.   // get the center point of the dropped letter entity
  14.   var DropPointX = DroppedEntity.X + LetterWidth / 2;
  15.   var DropPointY = DroppedEntity.Y + LetterHeight / 2;
  16.  
  17.   // let's assume that the slot entities are named "slot1", "slot2" etc.
  18.   // so walk through all the slots...
  19.   for(var i = 1; i <= NumSlots; i = i + 1)
  20.   {
  21.     // query the slot entity from scene
  22.     var Slot = Scene.GetNode("slot" + i);
  23.      
  24.     // is the dropped entity over this particular slot?
  25.     if (DropPointX >= Slot.X && DropPointX <= Slot.X + SlotWidth && DropPointY >= Slot.Y && DropPointY <= Slot.Y + SlotHeight)
  26.     {
  27.       // yes it is; position the letter to the exact position and leave
  28.       DroppedEntity.X = Slot.X;
  29.       DroppedEntity.Y = Slot.Y;
  30.        
  31.       // here you may check if the letter is in the correct slot or something
  32.        
  33.       break;
  34.     }     
  35.   }
  36. }
  37.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5679
    • View Profile
    • Dead:Code Site
Re: Sliding a letter onto a spot
« Reply #12 on: August 04, 2009, 03:25:57 PM »

Is there anyway to avoid that behavior? I have that problem for example with an inventory item, which is a thin wooden pole, so the user has to do "pixelhunting"....WHats a neat way to avoid that?
Create a sprite for the inventory item, and in SpriteEdit uncheck the "Pixel precise" check-box.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #13 on: August 04, 2009, 04:30:34 PM »

Thanks, Mnemonic, that was very kind of you to post the code snippet---I will try it tonight but am pretty sure it will solve the problem.  I use sprites for both Slots and Letters.  I think with your code snippet and the link to the Derman's code for sliding, people should be able to replicate this puzzle pretty easily.  Thanks for your help.
Have tried the sprite/pixel precise method for inventory items and it does work.  Just had to change the width of the inventory box as sprite goes up a little.

Thanks very much!   ::rock

Code: WME Script
  1. You're wonderful.
  2.  

« Last Edit: August 04, 2009, 04:37:59 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #14 on: August 05, 2009, 01:41:07 AM »

Note my new signature!  It worked perfectly.  Sometime by the end of this week, I'll put up a little demo in some appropriate place here of the code so anyone who doesn't know how to do this type of puzzle can do it.  There must be someone other than me who didn't know how.  ;  )

Thanks again, Mnemonic!   :D
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Sliding a letter onto a spot
« Reply #15 on: August 06, 2009, 02:44:54 AM »

I made a little demo of source code for making a sliding letter puzzle for newbies to Wintermute and coding.  It includes using a particle maker and an overlay.  Overlays are cool and they are really easy to use.  You just have to remember to check the box that makes an object "interactive" or your overlay will be dead.  : )  How many times I have forgotten this.  In fact, I wish it were the default that the object is interactive.

It can be tweaked to do other things as well, f.e., a picture puzzle, putting together a torn letter puzzle, and many things you could imagine.   :D

http://forum.dead-code.org/index.php?topic=3761.0

Thanks to The Derman for the sliding part, thanks for everything else to Mnemonic.  :  )  Thanks to Maze for reminding me of X's and Y's from an old post of his and for reminding me that it's nice to put everything back as it was if player doesn't get it right.   :  )   :D
« Last Edit: August 07, 2009, 02:02:33 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  
Pages: 1 2 [All]
 

Page created in 0.219 seconds with 23 queries.