“angry bird” game on€¦ · basic concepts in box2d . 19 • box2d uses kms unit system. •...

29
Write Your “Angry Bird” Game on Tizen for Fun and Profit Lu Guanqun Intel Corporation

Upload: others

Post on 21-Aug-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

Write Your

“Angry Bird” Game on

Tizen

for Fun and Profit

Lu Guanqun

Intel Corporation

Page 2: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

Why?

Page 3: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

3

The market is big!

Page 4: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

4

Famous games apps

Page 5: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

5

• Playing games is fun.

• Developing a game is more fun.

Page 6: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

How?

Page 7: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

7

• Tizen now DOES support the native application development.

• Web is the future and it’s cross platform by its nature.

• So a web game app(HTML5) in this talk.

Native app vs Web app

Page 8: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

8

So how to develop a web game app?

Page 9: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

9

• Write it by yourself from scratch

• Javascript (CoffeeScript,

TypeScript etc)

• Canvas(SVG)/WebGL

• WebAudio

If you’re brave enough…

Page 10: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

10

Basic Game Loop

Read Input

Move

Collision Test

Render

Page 11: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

11

Use a Game Engine

• There are many choices, and I choose…

Page 12: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

12

Use a Game Engine

• cocos2d-html5

Page 13: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

13

• Cocos2d

• Cocos2d for iphone

• Cocos2d-x

• Cocos2d-html5

A bit history about cocos2d

Page 14: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

14

Basic Workflow

Intro Menu Level1 Cutscene Level2 Winning scene

Losing scene

Score board

Page 15: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

15

Basic Concepts

Page 16: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

16

var GameLayer = cc.Layer.extend({

init:function() {

this._super();

var sprite = cc.Sprite.create(s_name);

sprite.setPosition(cc.p(100, 100));

this.addChild(sprite);

}

})

var MainScene = cc.Scene.extend({

onEnter:function () {

this._super();

var layer = new GameLayer(); // create a CCLayer

this.addChild(layer);

layer.init();

}

})

Some samples of code

Page 17: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

17

• Developed in C++ at first by

Erin Catto

• Then have lots of language

ports.

• We would use javascript

version.

2D Physics Engine – Box2D

Page 18: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

18

• “World” – manages the whole physics simulation.

• “Body” – primary element in Box2D world.

• “Shape” – all the collision geometry attached to a body.

• “Fixture” – attach a shape to a body, sets density, friction and

restitution.

• “Joint” – connection between two bodies.

Basic Concepts in Box2D

Page 19: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

19

• Box2D uses KMS unit system.

• Kilograms

• Meters (not pixels)

• Seconds

Unit

Page 20: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

20

• Emphasize with blue or green color from “Theme Colors” only

• Initial caps for titles and sentence case for bullets

• Follow the guidance for bulleted lists on the following page

Let’s see some code:

// create the world

world = new b2World(new b2Vec2(0, -10), // gravity vector

true); // allowing sleeping bodies

// create FixtureDef

var fixDef = new b2FixtureDef;

fixDef.density = 1.0;

fixDef.friction = 0.5;

fixDef.restitution = 0.2;

// create a ground body

var bodyDef = new b2BodyDef;

bodyDef.type = b2Body.b2_staticBody;

fixDef.shape = new b2PolygonShape;

fixDef.shape.SetAsBox(20, 2); // size (half width/height as the argument)

bodyDef.position.Set(10, -1.8);

world.CreateBody(bodyDef).CreateFixture(fixDef);

Page 21: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

21

• Emphasize with blue or green color from “Theme Colors” only

• Initial caps for titles and sentence case for bullets

• Follow the guidance for bulleted lists on the following page

Create a dynamic box

var bodyDef = new b2BodyDef();

bodyDef.type = b2Body.b2_dynamicBody; // specify the dynamic body here!

bodyDef.position.Set(p.x / PTM_RATIO, p.y / PTM_RATIO);

bodyDef.userData = sprite; // link Box2D to our sprite

var body = world.CreateBody(bodyDef);

var dynamicBox = new b2PolygonShape();

dynamicBox.SetAsBox(0.5, 0.5); //1m box

// Define the dynamic body fixture.

var fixtureDef = new b2FixtureDef();

fixtureDef.shape = dynamicBox;

fixtureDef.density = 1.0;

fixtureDef.friction = 0.3;

body.CreateFixture(fixtureDef);

Page 22: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

22

• Emphasize with blue or green color from “Theme Colors” only

• Initial caps for titles and sentence case for bullets

• Follow the guidance for bulleted lists on the following page

Draw the objects from Box2D

update:function (dt) {

var velocityIterations = 8;

var positionIterations = 1;

// Instruct the world to perform a single step of simulation. It is

// generally best to keep the time step and iterations fixed.

this.world.Step(dt, velocityIterations, positionIterations);

//Iterate over the bodies in the physics world

for (var b = this.world.GetBodyList(); b; b = b.GetNext()) {

if (b.GetUserData() != null) {

var myActor = b.GetUserData();

myActor.setPosition(cc.p(b.GetPosition().x * PTM_RATIO, b.GetPosition().y * PTM_RATIO));

myActor.setRotation(-1 * cc.RADIANS_TO_DEGREES(b.GetAngle()));

}

}

}

Page 23: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

23

Classic Box2D Demo

Page 24: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

24

• A place to shoot the bird

• Some blocks, wood, house

• The monsters

To make it more like Angry Bird, we need:

Page 25: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

25

My “Angry Bird” Demo

Page 26: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

26

• Sound effects

• Shiny graphics ( I need an artist! )

More…

Page 27: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

27

• Sell it on Tizen app store

• Add some ads

• In App Purpose

Profits Part

Page 28: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or

28

• https://github.com/cocos2d/cocos2d-html5

• http://box2d-js.sourceforge.net/

• http://blog.flurry.com/bid/95723/Flurry-Five-Year-Report-It-s-an-

App-World-The-Just-Web-Lives-in-It

• http://xkcd.com/724/

• http://www.cocos2d-

iphone.org/wiki/doku.php/prog_guide:basic_concepts

References:

Page 29: “Angry Bird” Game on€¦ · Basic Concepts in Box2D . 19 • Box2D uses KMS unit system. • Kilograms • Meters (not pixels) • Seconds Unit . 20 • Emphasize with blue or