detecting gaps inbetween - creating game

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

detecting gaps inbetween - creating game

Post by star0629 » Wed Dec 18, 2013 10:27 pm

So i have the background scrolling along the card with gaps in between, and the character is to jump over the gaps. My problem is that at the moment, nothing happens if the character goes over the gaps, I am wanting to code so that it will fall off/disappear the card. I have a rough idea where i am going with this but it isnt working. something along the line of this?
what i have on my card scrolling across.
"bg1" "bg2" "bg3"

if image "character" is left of image"bg2" then move image"character" to the bottom of card id "1003"
end if
if image "character" is left of image"bg3" then move image"character" to the bottom of card id "1003"

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: detecting gaps inbetween - creating game

Post by dunbarx » Wed Dec 18, 2013 11:00 pm

Hi.

Firstly, you cannot use the "left" property that way, though, oddly, no error is thrown. Rather, unless I misunderstand, why not just:

if the left of image "character" < the left of image"bg2" then hide image"character" --see the dictionary under the property "left"

Just so you know, you can also set the loc of an object to a value offscreen, like "50000,50000". which might be in the next room.

Craig Newman

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: detecting gaps inbetween - creating game

Post by star0629 » Wed Dec 18, 2013 11:23 pm

ahh okay.. i think there needs to be something in between.. because that line of code if i take out the hide character and replace it with stopGame(already coded for) then the entire thing just stops..

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: detecting gaps inbetween - creating game

Post by dunbarx » Thu Dec 19, 2013 2:43 am

Do you mean this locks up:

if the left of image "character" < the left of image"bg2" then stopGame

StopGame is a handler somewhere, I assume. Does it do so as well from the message box?

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: detecting gaps inbetween - creating game

Post by star0629 » Thu Dec 19, 2013 3:37 am

yes, that is the code i tried and it didn't work out as expected. i could replace the "stopGame" with anything later on.. my main focus is getting the "character" to disappear once it detects the gaps somehow...I see no where round this, it seems impossible :( the character is self is not moving at all except for when it is clicked on by the mouse it jumps (for it not to fall between the gaps, atm there is no effect when it goes over the gap). The process of the game is similar to "baby horse run"

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: detecting gaps inbetween - creating game

Post by dunbarx » Thu Dec 19, 2013 3:58 am

Hi.

I don't understand what you are saying. So the handler does not lock up, it just stops without performing? And the "character" is not moving as you wish. How do you make it move? Not with the "move" command, I hope, since that is blocking and has to complete before anything else can happen. There are ways around this, sort of, but could that be your problem?

More information is needed...

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: detecting gaps inbetween - creating game

Post by star0629 » Thu Dec 19, 2013 3:04 pm

For my background the images are positioned and locked in place as i want them, leaving small gaps in between (for the character to fall into) i have the code working for the images to move across the card continuously. I don't want the character to move forward or anything, just up and back down when it is click on only by the mouse(which i have managed to code for).

I am wanting the character to detect the gaps somehow, currently i have the moving background, and the character is in a still position not detecting the gaps. I am wanting to code for the character to disappear/fall into the gaps.

If i open up my card the character is always going to be in the bottom left corner of the card, at first it is on the grass(the scrolling background) it needs to detect the gap in-between the two images as it scrolls across to the character

"image1" "image2"

I hope i made better sense, and someone can help me out please

thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: detecting gaps inbetween - creating game

Post by dunbarx » Thu Dec 19, 2013 3:22 pm

Hi.

So if you have managed all this, you should be able to detect when item 1 of the loc of the character, which is its "X" position on the card, is at or near the middle of the space bounded by the right of one image and the left of the adjacent one. This has to be managed, since you only want to check adjacent images, not more distant ones, which might give a false positive. Write back if this is still not clear.

Craig

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: detecting gaps inbetween - creating game

Post by star0629 » Thu Dec 19, 2013 4:23 pm

yes, that is exactly it but im unsure how to code it, I have tried different methods but my coding is not right and i keep getting different error messages...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: detecting gaps inbetween - creating game

Post by dunbarx » Thu Dec 19, 2013 4:42 pm

So make three buttons. Place two of them sort of close together, but with a gap between. In the third button script do something cute like:

Code: Select all

on mouseMove
   if the optionKey is down then set the loc of me to the mouseLoc
   put the loc of me
end mouseMove
Hold down the option key and move the mouse over this button.

Now can you change this to give an alert when the button is between the other two?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: detecting gaps inbetween - creating game

Post by jacque » Thu Dec 19, 2013 6:52 pm

This sounds like a side-scroller game, where the character does not move but the background does. I think the easiest way is to use the "within" function to determine whether the character overlaps either of the images. You'll need to decide whether you want to count only the center of the character button or the edges. To just compare the center (the loc) then you can do this:

Code: Select all

put the loc of btn "character" into tLoc
if tLoc is not within the rect of img 1 and tLoc is not within the rect of img 2 then -- in the gap
  jump
end if
If you want to use only the edges of the button (so the entire character must be in the gap) then:

Code: Select all

put the left of btn "character" into tLeft
put the right of btn "character" into tRight
put item 2 of the loc of btn "character" into tV
if tLeft,tV is not within the rect of img 1 and tRight,tV  is not within the rect of img 2 then -- in the gap
  jump
end if
Both of these use the entire rectangle of the button as the test. If you only want to test the actual pixels of the character then there's a different way to use "within", but let us know.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: detecting gaps inbetween - creating game

Post by star0629 » Mon Dec 23, 2013 8:57 pm

jacque wrote:This sounds like a side-scroller game, where the character does not move but the background does. I think the easiest way is to use the "within" function to determine whether the character overlaps either of the images. You'll need to decide whether you want to count only the center of the character button or the edges. To just compare the center (the loc) then you can do this:

Code: Select all

put the loc of btn "character" into tLoc
if tLoc is not within the rect of img 1 and tLoc is not within the rect of img 2 then -- in the gap
  jump
end if
If you want to use only the edges of the button (so the entire character must be in the gap) then:

Code: Select all

put the left of btn "character" into tLeft
put the right of btn "character" into tRight
put item 2 of the loc of btn "character" into tV
if tLeft,tV is not within the rect of img 1 and tRight,tV  is not within the rect of img 2 then -- in the gap
  jump
end if
Both of these use the entire rectangle of the button as the test. If you only want to test the actual pixels of the character then there's a different way to use "within", but let us know.

Yes, this is exactly what i am looking for and it almost works perfectly..but because the scrolling background images is grass the actual image is quite high but you cant see how high exactly since it is grass if you can see what i am trying to say here... and so i think the pixel "within" code which you mentioned would be much better and come in more handy. Atm the character stops just at the edge of the image and not exactly in the gap. The user should be able to click on the character to whilst it is at the edge?

also the reason it stops is because i have added the code for everything to stop just to see what is happening..once everything is sorted the character will die off the screen somehow ...

Could you please tell me what the pixel is about and how i would come to coding it

thanks

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: detecting gaps inbetween - creating game

Post by jacque » Mon Dec 23, 2013 11:52 pm

The difference is just a variation on the syntax style. Use the parentheses version instead, like this:

Code: Select all

if not within(img 1,tLoc) and not within(img 2,tLoc) then
But this may not be what you want. This form only checks to see if the location (tLoc) is over a painted part of the image. It will be false if tLoc is over a transparent area. If your grass image has lots of transparent areas, then this form could trigger anywhere on the card, not just in the gap. I think this would be less reliable than checking the boundaries of the image itself.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: detecting gaps inbetween - creating game

Post by Newbie4 » Tue Dec 24, 2013 1:51 am

Here may be another approach.
Put an object ( like a button ) between the 2 images and make it not visible. Then just check for the intersection between your character and the object.
See if that works
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: detecting gaps inbetween - creating game

Post by jacque » Tue Dec 24, 2013 4:24 pm

By the way, if the character is stopping at the edge it probably means you're using the first example I wrote. Try the second one, which will trigger only in the center of the gap.

The extra button idea could work too but it wouldn't act any differently than just calculating where the gap is, and would require scripting another moveable object.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply