Mobile Maze Application for on Android devices

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 3:02 am

Hi, I really appreciate the help. I really hope this is closer, how does this look?

on accelerationChanged pXAccel, pYAccel, pZAccel
set location of image "marble" to (pXAccel)
set location of image "marble" to (pYAccel)
set location of image "marble" to (pZAccel)
   put round(pXAccel,2) into fld 1
   put round(pYAccel,2) into fld 2
   put round(pZAccel,2) into fld 3
end accelerationChanged

Laura

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Mon Mar 31, 2014 3:13 am

Sorry, location is made up of 2 numbers as shown by:

Code: Select all

set location of image "marble" to 675,167
the first number is x the second y or actually left and top.

Now you've seen the numbers and using them directly would put the marble in a funny place at the top left and off screen. So, you will have to do something with them.
Perhaps add or subtract from the current location, maybe something else?

Again, I can see that I might just be frustrating you and I don't want to. So if you want I can give you much more help, just ask. :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 3:28 am

Hi, I am trying, and I appreciate the help, so I am gonna if it a go again, and if I am wrong, then yes please will you give me much more help :)

here it goes, so the end of my maze is 675,167. I know that is probably wrong, but I thought maybe those are the numbers I am supposed to put in. Yep, I think I need much more help.


on accelerationChanged pXAccel, pYAccel, pZAccel
set location of image "marble" to (pXAccel,675,167)
set location of image "marble" to (pYAccel,675,167)
set location of image "marble" to (pZAccel,675,167)
   put round(pXAccel,2) into fld 1
   put round(pYAccel,2) into fld 2
   put round(pZAccel,2) into fld 3
end accelerationChanged

Laura

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 3:38 am

This might be closer. This is the Left, top, and right locations of where the marble is.

on accelerationChanged pXAccel, pYAccel, pZAccel
set location of image "marble" to (pXAccel,656)
set location of image "marble" to (pYAccel,148)
set location of image "marble" to (pZAccel,695)
   put round(pXAccel,2) into fld 1
   put round(pYAccel,2) into fld 2
   put round(pZAccel,2) into fld 3
end accelerationChanged

Laura

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Mon Mar 31, 2014 3:49 am

Hi Laura,
OK.

Code: Select all

on accelerationChanged pXAccel, pYAccel, pZAccel
   put round(pXAccel,2) into fld 1
   put round(pYAccel,2) into fld 2
   put round(pZAccel,2) into fld 3
   put the loc of image "marble"  into tLoc
   add pXAccel to item 1 of tLoc
   add pYAccel to item 2 of tLoc
   if item 1 of tLoc <= 0 then put 0 into item 1 of tLoc
   if item 1 of tLoc >= the width of this stack then put the width of this stack into item 1 of tLoc
   if item 2 of tLoc <= 0 then put 0 into item 2 of tLoc
   if item 2 of tLoc >= the height of this stack then put the hieght of this stack into item 2 of tLoc
   set the loc of image "marble" to tLoc
end accelerationChanged
There is still some correction to be made there as the location is the center of the image so you need to add 1/2 the width of the image to all 4 if statements.
It's a little rough on my Android device but that can be smoothed out.
Note that z is not needed (unless you have some kind of 3D screen which would be really cool!)

Simon
Edit: Oh I see from your last posting I was really confusing you. I'm very sorry.
Edit 2: typo but it still worked???

Code: Select all

 if item 2 of tLoc >= the height of this stack then put the height of this stack into item 2 of tLoc
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 4:32 am

Oh my gosh, thank you so much. my marble floats all over now :) and LOL, I was very confused.

my next question is, what do I do to make it so that it doesn't go through the maze walls?

this is the scripting that I have for on a desktop maze app. would it be similar to this?

on arrowKey theKey
if intersect (image "maze", image"marble", "opaque pixels") then
if direction is "up" then
set the top of image"marble" to the top of image"marble" + 6
end if
if direction is "down" then
set the top of image"marble" to the top of image"marble" - 6
end if
if direction is "left" then
set the left of image"marble" to the left of image"marble" + 6
end if
if direction is "right" then
set the left of image"marble" to the left of image"marble" - 6
end if
end if
If intersect (image "swirl3", image"marble", "opaque pixels") then
go to the next card
end if
end arrowKey

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Mon Mar 31, 2014 4:49 am

Hi Laura,
I'm glad it's working for you.
I have updated the code:

Code: Select all

constant kMulti = 2

on openCard
   if the environment <> "mobile" then exit openCard
   get mobileSensorAvailable("acceleration")
   if it is false then
      answer "Sensor unavailable"
      exit openCard
   end if
   mobileEnableAccelerometer 1000
end openCard

on accelerationChanged pXAccel, pYAccel, pZAccel
   put round(pXAccel,2) into fld 1
   put round(pYAccel,2) into fld 2
   put round(pZAccel,2) into fld 3
   put the loc of image "marble"  into tLoc
   add (pXAccel*kMulti) to item 1 of tLoc
   add (pYAccel*kMulti) to item 2 of tLoc
   if item 1 of tLoc <= 30 then put 30 into item 1 of tLoc
   if item 1 of tLoc >= (the width of this stack-30) then put (the width of this stack - 30) into item 1 of tLoc
   if item 2 of tLoc <= 30 then put 30 into item 2 of tLoc
   if item 2 of tLoc >= (the height of this stack-30) then put (the height of this stack - 30) into item 2 of tLoc
   set the loc of image "marble" to tLoc
end accelerationChanged

on closeCard
   if the environment = "mobile" then
      mobileDisableAccelerometer
   end if
end closeCard
That 30 is half the width of my image, update for yours.
The constant gives faster motion for a more challenging game
Set the layer mode of your marble image to dynamic to smooth out the motion.

Now intersect huh?
I'll have a think.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 5:00 am

Hi,
Thanks for letting me know the updated code :)

and for helping me with this so much.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Mon Mar 31, 2014 7:36 am

Found another error in my code. it should be:

Code: Select all

  subtract (pXAccel*kMulti) from item 1 of tLoc
   add (pYAccel*kMulti) to item 2 of tLoc
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 3:59 pm

Hi,
Thanks, I made that change already. I tried a few things for intersection with the walls, but haven't had any luck yet.

Laura

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Mon Mar 31, 2014 5:13 pm

Well, I made that change because you told me to, not because I spotted it. So thanks for letting me know to fix that.

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Wed Apr 09, 2014 12:21 am

hi, would someone please help me figure out how to script for an object on a mobile device to not go through the walls of a maze?
my object is called image "marble" and my walls are called image "maze"

I can get it to do something on intersection. Like set the marble back to the original location, or go slightly to the left, but it was very glitchy.

Laura

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Wed Apr 09, 2014 12:34 am

Hi Laura,
I'm in a bit of a quandary.
This is a college project which I'm sure you have to solve.
Me posting solutions really isn't helping you.

But here:
I have something working but would not consider it a "product' at all.
You know from the desktop that there are conditions that indicate which way to move the marble away from the wall, these are up/down/left/right as presented by the arrow keys.
And that is the problem with "intersect" it does not tell you where it hit just that it did hit.

I built 4 "sensors" which were grouped with the image this told me which direction to move to get away from the wall.
Make a 4 slice pizza out of your marble and group them back together.
Now can you tell which slice hit and which direction to move the marble?

Simon
Edit;
Tip: When you slice your pizza make sure you slice it like "X" not "+"
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurabar55
Posts: 26
Joined: Tue Mar 18, 2014 11:10 pm

Re: Mobile Maze Application for on Android devices

Post by laurabar55 » Wed Apr 09, 2014 5:14 am

Hi, I appreciate your little bit of help, and I understand why you don't want to just tell me everything.
My teacher and I have been working on trying to get the walls to work, and we haven't had much success yet.

This is what I tried so far, It works a bit, but its really glitchy. I just scripted it for the one piece of the pie so far. Am I on the right track or should I scrap the intersect idea all together.

if intersect(image "maze", image "p2", "opaque pixels") then
set the left of group "pie" to the left of group "pie" - 10
end if

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Mobile Maze Application for on Android devices

Post by Simon » Wed Apr 09, 2014 5:39 am

YES!

It's that -10 you use that makes it jumpy, and no I was unable to remove all of the jitters.

Because of your understanding you get this:
repeat until not intersect(image "maze", image "p2", "opaque pixels")
add 1 to tMove
I wonder...I wonder... what goes in here? One thing I know is that this can get locked up and repeat forever....
end repeat

Yeah intersect is not all that great for this. I couldn't figure out a better way that was simple. There seems to be a key in that there is no problem when hitting the top/bottom or sides of the screen (no that one is not a hint).

Simon
Edit: and help me by naming your images something I can use Top/Bottom/Right/Left :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply