Create a brick breaker game with the corona SDK: Application setup

Source: Internet
Author: User

Original article, reprinted Please note:Reprinted from All-iPad.netLink:Create a brick breaker game with the corona SDK: Application setup

This is the first part of the series of tutorials. For the complete content, click the link on the next page:

  • Create a brick breaker game with the corona SDK: Application setup
  • Create a brick breaker game with the corona SDK: game controls
  • Create a brick breaker game with the corona SDK: Collision Detection

 

In this series of tutorials, we will use corona SDK to create a brick breaker game. The goal of this game is very simple. You need to control a board, like playing table tennis, you can control the ball to destroy all the bricks on the opposite side.

Okay, let's get started.

 

Step 1: Application Overview

Introduce the rules of the game again. You need to destroy all the bricks without dropping the ball. If you reach the goal, the game will enter the next level, otherwise the game will end.

 

Step 2: Target Device

First, we need to determine the platform on which the game is finally released, so that we can make appropriate images based on the target platform.

There are three formats for iOS: iPad, iPhone 3, itouch2, and iPhone 4, which correspond to resolutions of 1024*768,320*480,640*960, respectively.

Android is more complicated, because the standards of various mobile phone manufacturers are not uniform. For large screens, there are two sizes: 480*800 and 480*854, other small screens are also not uniform, and the pad size is even more uncertain.

In this tutorial, we will only focus on the iPhone/itouch platform, but the corona SDK itself is cross-platform. The created app can be easily transplanted to the Android platform and other IOs resolutions.

 

Step 3: Interface

As shown above, the interface contains multiple different shapes, buttons, background images, and other resources. You can download them here.

 

Step 4: Export graphics

Scale the image to a proper size based on the platform you want to publish and save it.

 

Step 5: Main. Lua

Now, you have to start writing code.

Use your favorite text editor. Of course, it is better to support Lua syntax highlighting. Note: The project must have a main. Lua file. Start with this file.

 

Step 6: code structure

We will organize our code structure as described below:

Necesary Classes
Variables and Constants
Declare Functions
contructor (Main function)
class methods (other functions)
call Main function

 

 

Step 7: Hide Status Bar
display.setStatusBar(display.HiddenStatusBar)

Use this code to hide the status bar at the top of the screen.

 

Step 8: Load physics engine

Corona SDK integrates the box2d physical engine. You can use the following code to integrate the physical engine into the project.

--Physics Enginelocal physics = require 'physics'physics.start()physics.setGravity(0, 0) -- Set gravity to 0 as we won't be needing it
Step 9: Game variables & Constants

Some basic variables and constants are defined below, and their functions can be understood through code annotations.

891011121314151617181920 local BRICK_W = 41 --brick widthlocal BRICK_H = 21 --brick heightlocal OFFSET = 23 --an offset used to center the brickslocal W_LEN = 8 --the length of the levels, only 8 horizontal bricks should be created on stagelocal SCORE_CONST = 100 --the amount to add to the score when a brick is hitlocal score = 0 --stores the current scorelocal bricks = display.newGroup() --holds all the level brickslocal xSpeed = 5local ySpeed = -5local xDir = 1 -- x directionlocal yDir = 1local gameEvent = '' --stores game events (win, lose, finished)local currentLevel = 1
Step 10: menu screen

 

This is the main interface of the game and the first interface in the game. The variables defined below are used to save the background image and menu interface components.

2223242526 local background =  display.newImage('bg.png')local menuScreenlocal mScreenlocal startBlocal aboutB

 

Step 11: About Screen

This interface is used to display the author and copyright information. The following variable is used to save the view information.

28 local aboutScreen

 

Step 12: game screen

This is the game interface, which is created when a player presses the start button.

303132 local paddlelocal bricklocal ball

 

Step 13: score & level text

The following variables are used to save the current level and score.

34353637 local scoreTextlocal scoreNumlocal levelTextlocal levelNum

 

Step 14: alert screen

Used to show the player victory or failure.

3940414243 local alertScreenlocal alertBglocal boxlocal titleTFlocal msgTF

 

Step 15: Levels

We use Lua table to save the level data.

454647484950515253545556575859606162636465666768697071727374757677787980818283 local levels = {}levels[1] =             {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,0,0,0,0,0},}levels[2] =             {{0,0,0,0,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,1,0,0,1,0,0},{0,0,0,0,0,1,0,0},{0,0,0,0,1,0,0,0},{0,0,0,1,0,0,0,0},{0,0,1,0,0,0,0,0},{0,0,1,1,1,1,0,0},}levels[3] =             {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{0,0,0,1,1,0,0,0},{0,1,0,0,0,0,1,0},{0,1,1,1,1,1,1,0},{0,1,0,1,1,0,1,0},{0,0,0,0,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,0,0,0,0,0},}levels[4] =             {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0},{1,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1},}

In the preceding table, 1 indicates that there is a brick at the position, and 0 indicates no. The subsequent program will read the table and generate the corresponding level.

 

Next time...

In the next two sections, we will add code for interaction with the interface and collision detection.

 

 

Address: http://mobile.tutsplus.com/tutorials/corona/corona-sdk_brick-breaker/

Original article, reprinted Please note:Reprinted from All-iPad.net

Link:Create a brick breaker game with the corona SDK: Application setup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.