Home > Products > SophiaFramework UNIVERSE > Tutorial > Breakout > - 4 / 9 -

BREW Breakout - 4 / 9 -

Initialize application

License code

Write down the license code in Block.cpp.

- Block.cpp -

// Boot loader
SFCApplet::FactorySPP SFCApplet::Boot(AEECLSID id, SFXAnsiStringPtr license)
  *license = "heap://"
  return (id == AEECLSID_BLOCK) ? (&Block::Factory) : (null);

If you forget to input the license code, the application will not be executed on the actual device.

Initializing the Application

Initialization of the application is required in the following chunks of code.

The following operations are carried out in the Block::Initialize function to merge the difference in screen size between emulator and device.

- Block.cpp -...
// Constructor Block::Block(Void) : _status(APP_STATUS_NOTHING),
//_drawInterval(1000 / DRAW_RATE){
// Configure racket color _racket.color.Set(RACKET_COLOR);
// Configure ball color _usingBall.color.Set(BALL_COLOR);
// Handler for starting applicationVoid Block::OnAppStart
//(AEEAppStartPtr environment){
// Avoid warning for unused variable unused(environment);
// Start up process Initialize();return;}...

Initialization 1 : Acquire graphic interface

Initialization of variables is performed in the Block::Initialize function. ( See Block.cpp for details )

The following code obatins an instance of a graphical interface.

_pgraphics = SFXGraphics::GetInstance();

Always remember to get an interface when acting upon the hardware.

Since the graphics interface has been obtained, the background color may now be set.


Do you remember the definition for BGCOLOR ?

#define BGCOLOR SFXRGBColor(0, 0, 0, 0)

The argument of the SFXGraphics::SetBackColor function refers to a SFXRGBColor object.

Initialization 2 : Obtaining Screen Information

This is the screen layout of Breakout.

_gameArea is where the gaming squences take place and _messageArea is for displaying messages. Before drawing this layout, the screen size and font height need to be obtained.

The screen size can be obtained as a rectangle by this code.

SFXRectangle deviceRect = _pgraphics->GetDeviceRectangle();

The font height can be obtained by this code.

SInt16 fontHeight = _pgraphics->GetFontHeight(AEE_FONT_NORMAL);

Now, use these variables to calculate the coordinates for _gameArea and _messageArea.

Initialization 3 : SFXRectangle

_gameArea and _messageArea are both SFXRectangle type objects. Screen layout can be obtained by calculating their heights.

The width of these areas are the same as the screen width, so use this code.

_gameArea = _messageArea = deviceRect;

First, calculate the height for _gameArea. The result is given by: screen height minus font height.

_gameArea.SetHeight(deviceRect.GetHeight() - fontHeight);

Height for _messageArea is equal to the font height.


Move these two rectangles and the screen layout is completed.

But before that, you need to know the difference between the two member functions of SFXRectangle.

The Set* function is for moving the assigned vertices or sides. By using this function, you can change the size of the rectangle.

The Snap* function is for moving the rectangles so that the vertices or sides will be in their assigned places. Using this function will not change the rectangle size.

The SFXRectangle class obtains the height, width and coordinates of the rectangle's top left corner. In this case, the top left coordinates of _gameArea matches with the top left coordinate of the screen; only the SetHeight() function needs to be invoked.

For _messageArea, you will need to move the rectangle to the bottom. So use the SnapBottom function like this.


In the Initialize function, the size and speeds of: blocks, rackets and balls are also calculated.
( For details see Block.cpp. )

Initialization 4 : Generating stages

Breakout has 4 stages.

Properties for each types of block are defined in Void Block::CreateStage(SInt16 n). This function is invoked in the last lines of the Block::Initialize function. ( See Block.cpp for details )

Go back  1   2   3   4   5   6   7   8   Apdx   Next page