Is it possible to make this 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

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Is it possible to make this game

Post by dave_probertGA6e24 » Thu Nov 01, 2012 6:12 pm

Hi Salman,

Sorry to say, but that won't work.

You are putting the x value into a variable, then immediately replacing it with the y value. Therefore you don't have the x value any more!!

Hint: Try looking up the 'loc' variable in the dictionary - it is something that contains both the x and y values.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Fri Nov 02, 2012 1:16 am

ok so i changed it again

Code: Select all

local pX,pY,pX2,pY2

on touchStart flyBall
    ## When the user touches the image
    put empty into sCoordinateArray["start"]
    put empty into sCoordinateArray["end"]
end touchStart

on touchMove flyBall,pX,pY,pX2,pY2
   if sCoordinateArray["start"] is empty then
       put pX into sCoordinateArray["xStart"]
       put pY into sCoordinateArryay["yStart"]
       put pX and pY into sCoordinateArray["start"]
     else if sCoordinateArray["end"] then
       put pX2 into sCoordinateArray["xEnd"]
       put pY2 into sCoordinateArray["yEnd"]
       put pX2 and pY2 into sCoordinateArray["end"]
end if
    end touchMove

on touchEnd
    put sCoordinateArray["start"] into tStart
    put sCoordinateArray["end"] into tEnd
end touchEnd
comes up as no errors...surely i have hit the jackpot! :twisted:

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Fri Nov 02, 2012 5:36 pm

ok so i cahnged it even more line 8,9
line 13,18 setting the loc of target

Code: Select all

local pX,pY,pX2,pY2

on touchStart pObjectID
    ## When the user touches the image
    put empty into sCoordinateArray["start"]
    put empty into sCoordinateArray["end"]
end touchStart

on touchMove pObjectID,pX,pY,pX2,pY2
   
   If the short name of the target contains "bla.png" then ##bla is the name of the image ball
      if the icon of the target is 1003 then ##1003 is the id of the image bla which is represented by a button
         end if 
   end if
   if sCoordinateArray["start"] is empty then
      set the location of the target to px,py
       put pX into sCoordinateArray["xStart"]
       put pY into sCoordinateArryay["yStart"]
       put pX and pY into sCoordinateArray["start"]
    else if sCoordinateArray["end"] then
       set the location of the target to px2,py2
       put pX2 into sCoordinateArray["xEnd"]
       put pY2 into sCoordinateArray["yEnd"]
       put pX2 and pY2 into sCoordinateArray["end"]
end if
    end touchMove

on touchEnd
    put sCoordinateArray["start"] into tStart
    put sCoordinateArray["end"] into tEnd
end touchEnd

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Sat Nov 03, 2012 7:02 pm

ok this has to be my final hoorah on this issue, i dont see how it can be changed more

Code: Select all

local pX,pY

on touchStart flyBall
    ## When the user touches the image
    put empty into sCoordinateArray["start"]
    put empty into sCoordinateArray["end"]
end touchStart

on touchMove flyBall,pX,pY
   if sCoordinateArray["start"] is empty then
put pX && pY into sCoordinateArray["start"]
else
put pX && pY into sCoordinateArray["end"]
end if
end touchMove

on touchEnd
     If the short name of the target contains "bla.png" then ##bla is the name of the image ball
      if the icon of the target is 1003 then ##1003 is the id of the image bla which is represented by a button
         end if 
   end if
    put sCoordinateArray["start"] into tStart
    put sCoordinateArray["end"] into tEnd
end touchEnd
if only i can test this code in terms of tracking the co-ords etc but problem is i cant

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sat Nov 03, 2012 8:25 pm

I can currently only test things on desktop, but I put together a quicky stack (that you can use on desktop, it uses mouseup, mousedown, mousemove) so that you can "toss" a button and have it bounce around the screen.

The stack can be seen here. https://dl.dropbox.com/u/11957935/tossit.livecode All of the code is in the "throwMe" button.

Here is the code that is in that button. The code is ugly and not yet well thought out, but might give you some ideas.

Code: Select all

local sStartLoc,sEndLoc,sTouched,sVX,sVY,sDirX,sDirY, sRunning, sMoveTimer
on mouseDown 
   set the acceleratedrendering of this stack to true
   -- clear and initialize variables
   put empty into sVY
   put empty into sVX
   put false into sRunning -- toggle animation off
   put the milliseconds into sMoveTimer
   
   -- set both start loc and end loc to match
   -- since on initial mousedown you haven't moved the object yet
   put the loc of me into sEndLoc
   put sEndLoc into sStartLoc
   
   -- grab the button
   grab me
   -- make sure screenupdate is not already running.
   -- if it is NOT running then start it
   if lineoffset("screenUpdate",the pendingmessages) is 0 then screenUpdate
end mouseDown

on screenUpdate
   lock screen
   moveButton -- move handler
   checkBounds -- check screen edges
   
   -- same as above. Only send screenupdate if its not already pending
   if lineoffset("screenUpdate",the pendingmessages) is 0 then send "screenUpdate" to me in 50 milliseconds
   unlock screen
end screenUpdate

on mouseMove
   -- update positions aprox every 20ms
   -- this way if you grab the button and hold it, or move it fast then slow down
   -- it should take its velocity and positions from the most recent 20ms.. sorta
   -- clunky and there must be a better way, but for example purposes this works I guess. 
   if the milliseconds - sMoveTimer > 20 then
      put sEndLoc into sStartLoc
      put the loc of me into sEndLoc
      put the milliseconds into sMoveTimer
   end if
end mouseMove

on mouseUp
   put the loc of me into sEndLoc
   put item 1 of sEndLoc - item 1 of sStartLoc into sVX
   put item 2 of sEndLoc - item 2 of sStartLoc into sVY
   
   -- these ifs are needed for direction changes
   -- turns vector into abs() vector with sDir as direction factor 1, or -1
   if sVX < 0 then 
      put -1 into sDirX
      put abs(sVX) into sVX
   else 
      put 1 into sDirX
   end if
   if sVY < 0 then 
      put -1 into sDirY
      put abs(sVY) into sVY
   else
      put 1 into sDirY
   end if

-- toggle animation on
   put true into sRunning
   
end mouseUp

command checkBounds
   -- set direction factor to keep button within bounds
   if sRunning then
      if the top of me < 0 then put 1 into sDirY
      if the bottom of me > the bottom of this card then put -1 into sDirY
      if the left of me < 0 then put 1 into sDirx
      if the right of me > the right of this card then put -1 into sDirx
   end if
end checkBounds

command moveButton
   if sRunning then
      if sVX is a number and sVY is a number then
         -- move button by the amount in vector sVx or svy multiplied by 1 or -1 (sDirX sDirY) for direction control
         -- sDirX = -1 goes left.  sDirY -1 goes up.  1 and 1 go right and down respectively
         set the left of me to the left of me + (sVX * sDirX) 
         set the top of me to the top of me + (sVY * sDirY)
      end if
   end if
end moveButton

command stopRunning
   put false into sRunning -- a command to turn off animation. Can be called from another control with: send "stopRunning" to button "ThrowMe" in 0
end stopRunning

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sun Nov 04, 2012 12:31 am

Adjusted the stack to account for pseudo gravity. Same link as above, here is the adjusted code.

Code: Select all

local sStartLoc,sEndLoc,sTouched,sVX,sVY,sDirX,sDirY, sRunning, sMoveTimer, sLocX,sLocY,sGravity


command gravityAdjust
   -- friction too sorta
   put trunc((100*(.98 * (sVX))))/100 into sVX
   if sRunning then
      if sGravity + (sVY * sDirY) >= 0 then 
      put 1 into sDirY
      put trunc(100* abs(sGravity + (sVY * sDirY))/ 100) into sVY
      end if
      if sGravity + (sVY * sDirY) < 0 then put -1 into sDirY 
      put (trunc( (.98 * (abs(sGravity + (sVY * sDirY)))))) into sVY
   end if
   put sVX,sVY
end gravityAdjust

on mouseDown 
   set the acceleratedrendering of this stack to true
   -- clear and initialize variables
   put 1 into sGravity
   put empty into sVY
   put empty into sVX
   put false into sRunning -- toggle animation off
   put the milliseconds into sMoveTimer
   
   -- set both start loc and end loc to match
   -- since on initial mousedown you haven't moved the object yet
   put the loc of me into sEndLoc
   put sEndLoc into sStartLoc
   
   -- grab the button
   grab me
   -- make sure screenupdate is not already running.
   -- if it is NOT running then start it
   if lineoffset("screenUpdate",the pendingmessages) is 0 then screenUpdate
end mouseDown

on screenUpdate
   lock screen
   moveButton -- move handler
   checkBounds -- check screen edges
   gravityAdjust
   -- same as above. Only send screenupdate if its not already pending
   if lineoffset("screenUpdate",the pendingmessages) is 0 then send "screenUpdate" to me in 50 milliseconds
   unlock screen
end screenUpdate

on mouseMove
   -- update positions aprox every 20ms
   -- this way if you grab the button and hold it, or move it fast then slow down
   -- it should take its velocity and positions from the most recent 20ms.. sorta
   -- clunky and there must be a better way, but for example purposes this works I guess. 
   if the milliseconds - sMoveTimer > 20 then
      put sEndLoc into sStartLoc
      put the loc of me into sEndLoc
      put the milliseconds into sMoveTimer
   end if
end mouseMove

on mouseUp
   put the loc of me into sEndLoc
   put item 1 of sEndLoc - item 1 of sStartLoc into sVX
   put item 2 of sEndLoc - item 2 of sStartLoc into sVY
   
   -- these ifs are needed for direction changes
   -- turns vector into abs() vector with sDir as direction factor 1, or -1
   if sVX < 0 then 
      put -1 into sDirX
      put abs(sVX) into sVX
   else 
      put 1 into sDirX
   end if
   if sVY < 0 then 
      put -1 into sDirY
      put abs(sVY) into sVY
   else
      put 1 into sDirY
   end if
   
   -- toggle animation on
   put true into sRunning
   
end mouseUp

command checkBounds
   -- set direction factor to keep button within bounds
   if sRunning then
      if the top of me < 0 then 
         set the top of me to 0
         put 1 into sDirY
      end if
      if the bottom of me > the bottom of this card then 
         put -1 into sDirY      
         set the bottom of me to the bottom of this card
         if (abs(sVY)) < sGravity + .1 then 
            put 0 into sVY
            put 0 into sGravity
         end if
      end if
      if the left of me < 0 then put 1 into sDirx
      
      if the right of me > the right of this card then put -1 into sDirx
   end if
end checkBounds

command moveButton
   if sRunning then
      if sVX is a number and sVY is a number then
         -- move button by the amount in vector sVx or svy multiplied by 1 or -1 (sDirX sDirY) for direction control
         -- sDirX = -1 goes left.  sDirY -1 goes up.  1 and 1 go right and down respectively
         set the left of me to the left of me + (sVX * sDirX) 
         if sVY > sGravity - .001 then set the top of me to the top of me + (sVY * sDirY)
      end if
   end if
end moveButton

command stopRunning
   put false into sRunning -- a command to turn off animation. Can be called from another control with: send "stopRunning" to button "ThrowMe" in 0
end stopRunning

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Sun Nov 04, 2012 2:45 am

wow thank you very much for that sturgis :) such a massive help for my project! once again thanks!! :D :D

Post Reply