Lua is designed to be lightweight, fast, yet powerful. It is used in major titles such as Civilization, Warcraft, and countless indie games. Everything from graphics to animations, simulated physics to beautiful particle effects, the Corona Simulator streamlines your workflow and lets you see changes instantly. Then, just like the instant-update Corona Simulator, any device on your local network running a Live Build of the app will update instantly, saving you the time of frequent builds and re-installs.
From bleeding-fast OpenGL graphics to the lightweight scripting power of Lua, Corona is optimized for performance at every core level. With Corona, your apps are automatically compiled at build time, streamlined for performance and stability.
Everything from in-app advertising, analytics, media, hardware features, and more are within your reach through a selection of almost plugins, and that number continues to grow.
Using Corona Native, you can even create and distribute powerful plugins for other Corona developers in the Corona Marketplace, exposing native platform features, support for third-party tools, and more.
Corona is elegant and inclusive: simply download and install Corona, start a new project, and start editing Lua code in your favorite IDE or text editor.
With Corona, the fun begins immediately and your changes will be instantly reflected through the built-in Corona Simulator — no need to maintain internal toolsets or configure external SDKs.
No hidden fees, charges, or royalties. Some features that were described aren't implemented yet, but they're all fairly cosmetic in nature. That means the game is functionally finished, and now is a good time to test it out. Play it repeatedly and look for anything that seems broken. Or, just keep playing it for a while; you've earned it! Although the game is functionally working at this point, it's not really ready for the prime time.
The way the bats just fade out and keep flying could easily confuse players. The high scores table could use a little more excitement. Finally, since we're reusing Creative Commons art assets, some credit information is in order. Copy the explosion. This file provides the sprite sheet info and a simple function to create and animate a small explosion at a given point. First, we're going to make the bat's death a little more dramatic, adding a little explosion and causing the bat to fall off the bottom of the screen instead of continuing to fly.
Open up the bat. We'll use the new explosion module to create an animated explosion in the bat's world environment at its current point. The explosion is responsible for animating itself and deleting itself when the animation is done. We'll start the bat sliding sideways off the right-hand side. Because we're looking for a natural bouncing motion under the effects of gravity, the horizontal aspect of the motion will be tweened linearly, while the vertical component will be tweened quadratically; this means we need two separate transitions:.
We calculate the total distance the bat will travel vertically to rise up 50 pixels and then fall off the bottom of the screen. We add because it will also fall the extra 50 pixels that it bounced up:. Because the bat will first bounce up a little, then fall, its vertical motion will be determined by a custom tweening function, arc , which we will write in a moment.
This transition is made slightly longer than the first one, because it will clean up the object and post a remove event when it's done, and we want to make sure the other transition has finished first:.
This is our custom tweening function. It isn't terribly fancy; it transitions the object back, against the direction of the tween, for the first milliseconds, then tweens it forward from that point for the rest. It relies on Corona's existing quadratic tweens a decelerating tween for the upward motion, and an accelerating one for the fall to calculate the intervening values. Now the bat dies a little more dramatically and we can move on to animating the credits and high scores.
Close bat. This credits object will trade places periodically with the high-scores display, so whenever it fades out, it needs to cue the high-score object to slide into the empty space:. We don't want the credits to appear until the high scores have faded out, so make them completely transparent whenever the scene starts:.
This means that in order for it to ever appear, it needs to be cued in whenever the high scores fade out, which we'll set up in the revealScores function:. In order for the object to ever receive a Faded event, we'll have to start the same transition on it:. This moves the collected scores down off the screen, and schedules them to slide back in after a second and a half.
Returning the resulting cancellation function means that the Cycle function will store it in the scene. StopEffects field. This is important, because if we start a game, we need to be able to cancel that transition. We can do that from the scene:exitScene function. Finally, we need to update the number of bats per scene; right now, it is set to a test value of 5.
The document specifies 30 per game. To leave ourselves room for flexibility in the future, we'll have the menu pass in the desired number when it calls the game scene, much the same way the game passes the final score out. Go to the top of menu. We'll reuse this table as we relaunch the game scene. Now, we just need to supply it when we launch the game, which is in the function right under that:.
Adding a reference to the options table tells storyboard to pass the parameters in to the scene being opened. Finally, we can save and close menu. Instead of setting the game's starting creature count to a fixed 5, we'll set it to whatever is passed in by the menu. Now, we added additional animations to the dying bats by modifying only one function and adding another one for it to call. We also added a little animation to create visual interest and made control of the game scene more flexible.
We have engineered a game from concept description up through final polish and improvements. We have designed and implemented a flexible system for bridging communications between disparate elements of the program and adapted the components within that system to accommodate new elements as they are included.
We also now have a playable game! How many bats can you swat? There are several generalizations that have been left in the code to make it easier to add new components and variations later with a minimum of fuss. Can you give the player a choice between the existing level and one that mixes the brown bats with black ones that move slower, but take three taps to kill? For the cleanest results, try and do it without creating any new scene files!
Nevin Flanagan has had an extremely varied career covering several fields, but the threads of computers, teaching, and games have trailed through it all for years.
He has programmed on different levels ranging from assembly language to high-level scripting in game engines, and is credited as a contributor to the World of Warcraft user interface. He is currently fascinated by the interface possibilities offered by mobile touchscreen devices and is completing a Master's degree in Interactive Media and Game Development at Worcester Polytechnic Institute in Massachusetts. He lives with his wife Jenna in Leominster, Massachusetts, in the U. About this book If you've used the Corona Software Development Kit to build your very first new mobile app, you already know how easy it makes developing across all the pieces of this fragmented market.
Publication date: May Publisher Packt. Pages ISBN Chapter 1. What do we build? What does it do? How is it excellent? How are we going to do it? Describing the game Defining the event flow Creating the game scene, and the bat and world objects Creating the interface layer Adding the shell Tracking high scores Adding some polish.
What do I need to get started? Describing the game. Getting on with it. A design should start with an overview description that summarizes what the player will experience and why it will be fun: Bat Swat is a game that tests your reflexes, challenging you to quickly tap sinister bats as they escape across the screen from the bottom left to the top right. Each bat knocked out of the sky is worth ten points, and the ten highest scores are displayed on the menu screen with the initials of their achievers.
The bats' flight is displayed across the staggered ramparts of a gothic castle, which move down and left across the screen to show upward progress. A distant landscape is slowly moved down in the background to reinforce the impression of upward travel. A numerical display of the player's score so far is shown in the upper left.
A game lasts until 30 bats have appeared on the screen and either escaped off the other side or been knocked down. Between games, and when the app first launches, a splash screen is displayed with the name of the game and a reminder to tap the screen in order to begin play. If the game remains on this screen for more than a few seconds, it cycles between a display of the high score record and the game credits. When the menu is displayed after completing a game, if that game's final score is within the ten highest scores recorded, a pop-up screen is shown displaying the new high score and soliciting the player's initials.
This disappears and returns to the normal menu screen once the initials entry is confirmed. What did we do? What else do I need to know? Defining the event flow. Note For example, in a game of baseball, the outcome of the game is expressed in scores for the teams, determining a winner and a loser, but these are abstract concepts; the scores are determined by how the rules of the game are applied to things that happen on the field; for example, which hits are caught and which lead to runners on base.
Creating the objects. Getting ready. Click on the icon for New Project ; the pop-up screen that you take next changes slightly depending whether you are running the simulator on Windows or Mac OS X: On a Mac, enter the project name and select Scene from the template list.
Loading art assets and libraries. Loading the world. World Copy. Note Depending on how much Lua programming you've done, the syntax of the require call may or may not be familiar to you; when a name or expression is followed directly by a string literal or table constructor, Lua attempts to call the value of the name or expression assuming it is a function with the string or table as its only argument.
Linking the game with the world. World self. World:addEventListener 'Death', self self. World end Copy. Loading a new game into the display.
We'll go down to the next event responder, and replace the contents of that function with code that actually starts the game: function scene:enterScene event self. StartingCount Copy.
Note Notice that the event's name starts with a capital letter. Preparing the game challenges. Responding to world changes. Count or self. Note When a table which includes scene and display objects is registered as a listener on some event target, it should have a field name matching the event name including matching case; Lua is case-sensitive , containing a function that will process those events. Monitoring game progress. Concluding the game. Count - 1 end end Copy. Understanding your libraries.
Note Notice that the bat object registers for its own Death event, as well as the world registering for it. Creating the interface. Adding visible information. ScoreDisplay:setReferencePoint display. CenterRightDisplayPoint Copy. Updating an information display. CenterRightDisplayPoint function self. ScoreDisplay:Score event Copy. CenterRightDisplayPoint self. ScoreDisplay return self end Copy. Linking the interface to the game.
Interface self. World:addEventListener 'Death', self Copy. Triggering a game event from a world event. Tip Lua is a language that's light on semi-colons, making their use between statements optional in almost all cases. Adding the Shell. Creating a staging zone for high scores. ScoresWindow scene.
Linking the shell into the play cycle. What else do we need to know? Note In scripting languages, truthy values are ones that are considered on or positive for if statements.
Tracking high scores. Retrieving a top score Determining if a score belongs in the top 10 Adding a new score to the database. Linking to the database file.
Initializing the database. Note Notice the use here of the Lua long string literal, enclosed in double brackets. Cleaning up old scores. Note While programming styles vary, it's frequently a good habit to build your code inwardly; for instance, when you type the beginning of an if … then statement in Lua, you can immediately type end on the next line and then back up and fill the contents in between the two.
Considering possible new high scores. Tip It's worth noting that all three functions don't actually return any records; they return iterator functions that produce the contents of a new row each time they're called.
Saving new high scores. MobCount, statistics. Initials Copy. Recovering old high scores. Communicating scores between modules. Score then if history:find event. Reviewing new scores. Displaying the score history. PulseInOut self. Banner self. ScoresSlide scene. ScoresWindow:insert scene. ScoresSlide end function scene:Cycle Copy. Initials and score. Score then break; end Copy. Score then break; end display.
ScoresSlide, score. CenterRightReferencePoint score. Adding finishing touches. Flight Copy. Flight explosion self. Changing the creatures' motion. Animating on a custom curve. Adding visual interest to the high scores. ScoresWindow, creditsText, , 0, , , native.
Credits:addEventListener 'Faded', function self. SlideInFadeOut self. ScoresSlide end end Copy. Score then Copy. ScoresSlide:addEventListener 'Faded', function SlideInFadeOut scene. Credits end end Copy.
Credits end return visuals. Are you ready? The 2D Game Engine. No limits Unlimited. Lua-based Lua is an open source scripting language designed to be lightweight, fast, yet also powerful. Plugins for all needs Select from numerous plugins which extend the Corona core for features like in-app advertising, analytics, media, and much more. Cross-platform Develop for mobile, desktop, and connected TV devices with just one code base. Completely free No hidden fees, charges, or royalties.
See your dream come to life. Speed and performance From bleeding-fast OpenGL graphics to the lightweight scripting power of Lua, Corona is optimized for performance at every core level. Not only an engine But an entire ecosystem. Community More than , developers and an active, helpful forum are not just facts. Visit forum Marketplace Our marketplace is where you can easily find or distribute whatever you need to build the next blockbuster game or app.
Open source Corona's source code is now open for developers to add features to that they need and even contribute back to the core product. Read more Priority support Get priority support provided by our engineering team via our community Slack channel and email. Learn more. Made with Corona. Get started with Corona Join over k developers worldwide using Corona to create hit mobile apps. Blog posts.
0コメント