revUp - Updates and news for the LiveCode community
Issue 125 | December 22nd 2011 Contact the Editor | How to Contribute

Pimp My Rocket
What's going on in the Game Academy forum? I dropped by to find out.

By Heather Nagey

We're well under way now with the Game Academy, and the buzz that's going on around it is just fantastic. I'm really enjoying reading all the forum posts, and seeing students pick up the materials we're giving out and running with them. Its great to see so much enthusiasm and creativity.

With the permission of the posters, I'd like to pick out a few forum gems here, showing what they are already doing after week 2. The way this community is coming together and helping each other out is just inspiring. It's also very interesting to see the kinds of questions being asked, things that we wouldn't necessarily think about after being familiar with LiveCode for so long.

Getting down and dirty with Gravity
This all started with a query from a beginner, asking for help on the "gravity" exercise from week 1. Students were challenged to make the game rocket move as though under the influence of gravity, rather than in a linear fashion.

I was wondering if anyone could explain the ins and outs of getting this to function properly for beginners. I have absolutely no coding skills. As a matter of fact this is my first real attempt at learning any type of coding. I thought others might be able to benefit from a "dummy" explanation, but might feel awkward asking. I'd love some feed back.
~ robantonelli29GAgYtd

Can I just say here, that this is the smartest thing any newbie can do. Put your hand up, say "I don't understand, please help me". There are no stupid questions. His cry for help resulted in no fewer than 23 replies, of which I will pick out a few highlights.

Sturgis provided a fantastic explanation of exactly how he created his gravity script, broken down into stages, and culminating in this script, reproduced here in its entirety with his kind permission:

on updateScreen
      ## Check if the game loop should be run
      if sMoving is true then -- run the loop or not?
      
                -- I didn't want to initialize my millisecond tracker
      -- until the loop actually begins.
                -- so I checked here to see if its empty, and if it
      -- is Go ahead and init
                -- to the current time in milliseconds
            if tSeconds is empty then put the milliseconds into \
             tSeconds -- tseconds is used for accel timing control
      
            ## Update the game state[b]
            -- You will notice I decided to move the statement that
      -- actually "sets" the rocket position
            -- Individual set statements could have been used for up
      -- and down smaller walls of text is a good thing!
            -- Also moved the "top of card" and "bottom of card"
      -- checks, again so that I can have a slightly smaller amount of text[/b]
      
             switch the mouse is down -- I find switch easier to read 
               --since I changed to switch/case "case true" using an if
         -- would work out the same as "if the mouse is down"
                  case true -- moves up 
            
                  -- the mouse was down so its time to determine whether or
            -- not to adjust the movement amount
                  -- has enough time lapsed (based on the current time
            -- compared to the value in tSeconds) AND
                  -- make sure I'm not going to pass my minimum or maximum
            -- values for velocity (sMvMin)
                        if (sMvAmt > sMvMin) and (the milliseconds - \
                   tSeconds > sAccelUp) then  -- determine if its time to 
adjust velocity
              -- its time to adjust the movement value (IE -- velocity), and we're not passing our max/min value               -- since this is the "up" movement section, -- sutbract a value from sMvAmt               -- positive values move the ship down, negative -- values will move the ship up.                subtract 1 from sMvamt -- if it is, adjust how \ far a move is                          -- reset timer for next check so that the value is -- not incremented on every cycle               put the milliseconds into tSeconds             end if             break          case false -- moves down                  -- the same thing here as above but for the -- downward position.             if sMvAmt < sMvMax and the milliseconds - tSeconds \ > sAccelDown then -- same as above but for downward                addto sMvamt                put the milliseconds into tSeconds             end if             break       end switch             -- since I deal in positive and negative numbers I can -- use the same "set" statement to move my rocket.       -- First check both bottom and top, and if both are -- within range, the set is done. Otherwise we're       -- at a border, and no movement is performed       if the bottom of image "rocket" + sMvAmt < the bottom of \ this card and the top of image "rocket" + sMvAmt > 0 then        -- added this after the fact to rotate the rocket based -- on direction and speed.        --since sMvMent amount defines velocity, I used it along -- with a factor to set the angle of rotation.        -- more velocity means more rotation          set the angle of image "rocket" to (sMvAmt * -2)         -- and here is the set. Since sMvAmt will either be -- positive or negative,         -- adding a positive (down) will increase the value and -- move rocket down,         -- adding a negative will lower the value and move the -- rocket up.          set the top of image "rocket" to the top of image \ rocket + sMvAmt       else          -- if we're at the top or bottom border, zero out -- acceleration.          put 0 into sMvAmt       end if end updateScreen

Awesome!

Now, Mobymom starts to riff on this theme:

Could we use the random function on the gravity calculation? Perhaps applied to the tSeconds or mymovementvalue in the example provided by Sturgis? I know gravity fall velocity should be constant in real life, but adding a random element to the mix might be fun

Sturgis agrees... with frills...

Would be interesting. Could add some "wobble" to the rocket motion. Could also do a non-linear rate that slows down as it nears the end of the acceleration curve. IE increasing wind resistance causing the rate to eventually stop increasing.

Bryan has a different take and thinks outside the box:

I got an OK result for the first task by just copying the "drop" code of the card script of "rocket.livecode" and reversing it e.g. bottom of card to top of card to give up movement. I then looked at accelerating the drop (gravity) by adding 1 to the drop (+5) each screen update. I used a global variable that would hold it's value until it hit the bottom. Looks fine to me.

Way to go Bryan, why reinvent the wheel when you could just turn it inside out?
I'll let Al have the last word on this one (although the thread still continues!):

Some interesting thoughts coming out of this which is very encouraging, perhaps there is hope for me after all!

2 things which strike me since trying to digest this since Tuesday, firstly how 'verbose' Livecode is, almost like English for many instructions which helps when trying to understand it all; secondly I am impressed with how helpful the community is here, people seem very generous with their time (and their code) so really looking forward to the next webinar.

I couldn't agree more. One of the most outstanding things about LiveCode is the user community. I've always said it's one of the most helpful, welcoming and friendly communities you'll find, and together we can achieve results you'd never think of alone.

Pimp up your Rocket
Pabs kicks this one off, with his Rocketman post. The Game Academy comes with some standard materials provided, including a fairly stylish but basic rocket:

RocketPabs decided to have a play about with it.

The code was giving me a headache so I took time off to play with the rocket image... as you do. Set the rocket to fly vertically and found the fins were asymmetrical so did a little doodling ... as you do. Then I just had to have some burn/exhaust when the rocket gets a mousedown. So after more fiddling I had 2 images; one with exhaust and one without. Grouped them one on top of the other and used show and hide to cycle them as and when there is or isn't a mousedown.

Question: is there a better/easier way to effect the transition?

ps the gizmo at the top is the gun (gotta have a gun)

Dave picks up the thread:


I achieved a similar effect with the original rocket image (horizontally) by doing a second image with the jet exhaust only in it. Then grouping them both together and changing all the move commands to affect the group instead of the image. Using the visible property of the image I got the flame to show or hide, but didn't need to hide the rocket itself.

This works well, but it could be improved with a couple of frames of transparency being applied instead of just the on off of the visible property.

The other way would be to create a couple of jet images - one with very little flame and one with full flame. Then with each activation or deactivation of thrust the smaller jet would show for a couple of frames before the full one is made visible/invisible.

I'm also playing with how to use the outsideGlow image effect with some larger numbers to create a "force-field" type effect that can be toggled on/off.

There are so many ideas of what can be applied to even something as simple as this rocket game

mobymom isn't going to let it lie there!

What if we let it crash on the bottom? We could add a little parachute guy triggered a certain height from the bottom and let him float down while the rocket crashes.

Sturgis leaps into action with a fully fledged flame...

I remember in the old days that color cycling could be used to create the illusion of flowing water, lave etc so decided to give it a try with flames. I made several graphic "squiggles" in different colors that overlay one another in the shape of a flame cone. Grouped them, placed them behind the rocket at the right location, grouped the result, put the color list of each graphic squiggle into a property then, while the mouse is down, set the visible of the flame group to true and randomly set the color of each squiggle to one of the colors in the property list. Looks like some interesting things might be done this way by someone who had talent (not me that's for sure)

Just thought i'd throw this out there as a further possibility.

Stack can be seen here if anyone is interested.

Way to go guys. This is so much fun, and I can't wait to see what you're getting up to by week 4 or 5!

If you haven't already joined the Game Academy, its not too late. You can easily catch up with the downloadable webinars and materials, so come on in and join us! How would you mod your rocket?

Elanor

About the Author

Heather Nagey is Customer Services Manager for RunRev Ltd. She does not own a rocket, but is starting to think about building one in the back yard.

 

Main Menu

What's New

A Festive Gift from LiveCode