Top Banner
Simple Game Development in Cascades JAM42 Eric Harty Brian Scheirer May 14-16, 2013
31

Simple Game Development in Cascades

Feb 23, 2016

Download

Documents

Simple Game Development in Cascades. JAM42 Eric Harty Brian Scheirer May 14-16, 2013. Who are we?. Brian Scheirer @BrianScheirer. Eric Harty @Ebscer. So We Made a Game. In Cascades…. Full Source Code. Download the full source code from Github at - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simple Game Development in Cascades

Simple Game Development in CascadesJAM42Eric HartyBrian ScheirerMay 14-16, 2013

Page 2: Simple Game Development in Cascades

Eric Harty

@Ebscer

Brian Scheirer

@BrianScheirer2

Who are we?

Page 3: Simple Game Development in Cascades

So We Made a Game

In Cascades…

3

Page 4: Simple Game Development in Cascades

Download the full source codefrom Github at

https://github.com/Ebscer/BlackBerryLive-JAM42

4

Full Source Code

Page 5: Simple Game Development in Cascades

Entry point for our game Allows users to jump ahead,

replay levels or continue where they last left off

Same basic code as Starbeams LevelButton.qml objects in a

ScrollView Remember last played level

5

Level Selection Screen

Page 6: Simple Game Development in Cascades

LevelButton.qml

6

import bb.cascades 1.0Container {

property int value: 0background: levelButtonBack.imagePaint //ImagePaintDefinitionpreferredWidth: 144preferredHeight: 144gestureHandlers: [

TapHandler {onTapped: {

levelSelectionPage.newLevel(value)}

}]

}

Page 7: Simple Game Development in Cascades

Level Selection (part 2)

7

attachedObjects: [ComponentDefinition {

id: levelButtonObjectsource: “LevelButton.qml”

}]

Page 8: Simple Game Development in Cascades

Level Selection (part 3)

8

ScrollView {Container {

id: levelsonCreationCompeted: {

for(var i=0;i<max_level; i++){var b = levelButtonObject.createObject()b.value = ilevels.add(b)

}}

}}

Page 9: Simple Game Development in Cascades

Load the level JavaScript function

Setup win/loss conditions and score Variable scoring QTimer

User input Switch Buttons Submit Button

9

Level Creation

Page 10: Simple Game Development in Cascades

Level Creation: Load Level

10

onCurrent_levelChanged: { LevelFunctions.nextLevel(current_level); }…function nextLevel(theLevel) {

switch (theLevel) { case 1:

//level conditions

break; }

Page 11: Simple Game Development in Cascades

Level Creation: Win Conditions

11

ImageButton {defaultImageSource: "asset:///images/Sub1.png"pressedImageSource: "asset:///images/Sub2.png"onClicked: { var box1postion = Number(box1.translationX); var box2postion = Number(box2.translationX); var tube1score = Number(0); var tube2score = Number(0);

// if/else statement for tube2score based off box2postion // if/else statement for tube2score based off box2postion gameTimer.stop(); round_score = tube1score + tube2score; subDialog.open(); }}

Page 12: Simple Game Development in Cascades

Level Creation: Loss Conditions

12

qmlRegisterType<QTimer>("bb.cascades", 1, 0, "QTimer");

attachedObjects: [ QTimer { id: gameTimer interval: 1000 onTimeout: { timeRemaining.value -= 1; timeLabel.text = timeRemaining.value; if (timeRemaining.value == 0) { //end game loseDialog.open(); } } }]

Page 13: Simple Game Development in Cascades

Level Creation: User Input

13

gestureHandlers: [ TapHandler { onTapped: { if (switch2.text == "on") { if (right2.isPlaying() == true) { right2.stop(); } else if (left2.isPlaying() == true) { left2.stop(); } switch2.text = "off"; mySwitch2.imageSource = "asset:///images/Switch2.png"; } … //else do the opposite } }]

Page 14: Simple Game Development in Cascades

Translation Animations Duration Position Easing Curves

Use onEnded function to alternate animations

14

Animation

Page 15: Simple Game Development in Cascades

Animation (Part 2)

15

Container { id: box2 animations: [ TranslateTransition { id: right2 toX: 500 duration: 2000 onEnded: { left2.play(); } } ]

}

Page 16: Simple Game Development in Cascades

Used in our game to progress past the second level

A better way to offer upgrades than having a separate app Additional features “Power-ups”

16

In-App Purchases

Page 17: Simple Game Development in Cascades

In-App Purchases (c++)

17

// use PaymentServiceControl.cpp from the paymentservice sample

// first line for testing onlyPaymentManager::setConnectionMode(PaymentConnectionMode::Test);

qmlRegisterType<PaymentServiceControl>("com.blackberry.payment", 1, 0, "PaymentServiceControl");

https://github.com/blackberry/Cascades-Samples/tree/master/paymentservice

Page 18: Simple Game Development in Cascades

In-App Purchases (qml part 1)

18

import com.blackberry.payment 1.0attachedObjects: [

PaymentServiceControl {id: paymentControlonPurchaseResponceSuccess: {

// handle successful purchase}onInfoResponseError: {

if(errorText==“alreadyPurchased”) {//handle successful purchase

} else {//purchase failed (if needed)

}}

}]

Page 19: Simple Game Development in Cascades

In-App Purchases (qml part 2)

19

import com.blackberry.payment 1.0

var inAppId = “UnlockLevel3"var inAppSku = “UnlockLevel3“var inAppName = “Unlock the third level”var inAppMetaData = “Allows you to play past level 2”paymentControl.purchase(inAppId,inAppSku,inAppName,inAppMetaData)

Page 20: Simple Game Development in Cascades

Scoreloop is a free service provided by BlackBerry

Scoreloop services are run on a separate thread

Leaderboard GUI is based on a ListView

20

Scoreloop Leaderboards

Page 21: Simple Game Development in Cascades

Scoreloop

21

BBLiveGame::BBLiveGame(bb::cascades::Application *app) {mScoreLoop = ScoreLoopThread::instance();mAppData = 0;mScoreLoop->start();

}

void BBLiveGame::submitScore(int score, int mode) {if(mAppData!=0) {

ScoreLoopThread::SubmitScore(mAppData,score,mode);}

}

ScoreLoopThread* BBLiveGame::scoreLoop() {return ScoreLoopThread::instance();

}

Page 22: Simple Game Development in Cascades

Scoreloop leaderboard qml

22

ListView {id: leaderboardListdataModel: GroupDataModel {

id: leaderboardModelgrouping: ItemGrouping.NonesortingKeys: [“rank”]

}onCreationCompleted: {App.scoreloop().LoadLeaderboardCompleted.connect(getdata)App.loadLeaderboard(“all-time”,100)}

}

function getdata(leaderboardData) {leaderboardModel.insertList(leaderboardData)

}

Page 23: Simple Game Development in Cascades

Scoreloop leaderboard thread

23

void ScoreLoopThread::LoadLeaderboard(AppData_t *app, SC_ScoresSearchList_t searchList, unsigned int count) { SC_Client_CreateScoresController(app->client, &app-> scoresController, LoadLeaderboardCompletionCallback, app); SC_Range_t range; range.offset = 0; range.length = count; SC_ScoresController_LoadScores(app->scoresController, range);}void ScoreLoopThread::LoadLeaderboardCompletionCallback (void *userData, SC_Error_t completionStatus) { AppData_t *app = (AppData_t *) userData; SC_ScoreList_h scoreList = SC_ScoresController_GetScores(app->scoresController); QVariantList leaderboardData;

continued on next slide

Page 24: Simple Game Development in Cascades

Scoreloop leaderboard thread part 2

24

QVariantList leaderboardData; unsigned int i, numScores = SC_ScoreList_GetCount(scoreList);for (i = 0; i < numScores; ++i){ SC_Score_h score = SC_ScoreList_GetAt(scoreList, i); SC_User_h user = SC_Score_GetUser(score); SC_String_h login = user ? SC_User_GetLogin(user) : NULL; QVariantMap scoreData; scoreData["rank"] = SC_Score_GetRank(score); scoreData["simpleScore"] = SC_Score_GetResult(score); scoreData["username"]=login?SC_String_GetData(login):"<unknown>"; leaderboardData.append(scoreData);}emit(instance()->LoadLeaderboardCompleted(leaderboardData));SC_ScoresController_Release(app->scoresController);

Page 25: Simple Game Development in Cascades

Next Steps…

Cocos2dx

25

Page 26: Simple Game Development in Cascades

Cascades + Native Gaming libraries

What? Using Cascades with native gaming libraries is easy.ForeignWindow control lets you embed a native game window to Cascades UI.

Who?Native BB10 App look-and-feel with Cascades UI Focus on native game development and not UIOverlay cascades controls over their native game

Page 27: Simple Game Development in Cascades

What is Cocos2D

Framework for 2D Games, graphics apps

Simplifies:Flow control between scenesSprites with actions [move, rotate, scale…]Effects [waves, twirl, lens…]Particle Systems [explosions, fireworks …]

Page 28: Simple Game Development in Cascades

Cascades + Native Gaming libraries

How? [https://github.com/rmadhavan/Cocos2dxIntegrated] Use Case: Running Cocos2dx in Cascades

1. Import Cocos2dx libraries.2. Modify Cocos2dx library to use a child window under Cascades’ Window

group.3. Modify Z-order of Cocos2dx window either behind (Z < 0) or in front (Z > 0)4. Build cocos2dx libraries.5. Create a new cascades project.6. Include Cocos2dx headers and libs to the cascades project.7. Create a ForeignWindowControl and bind cocos2dx game window8. Execute cocos2dx game loop in a new thread.9. If Cocos2dx is underlay, use cascades event to modify Scene.10. If Cocos2dx is overlay, use Cocos2dx event handling to modify Scene.

Page 29: Simple Game Development in Cascades

Q & A

Questions & Answers

29

Page 30: Simple Game Development in Cascades

Eric Harty Twitter: @Ebscer Email: [email protected] Site: http://news.ebscer.com/

Brian Scheirer Twitter: @BrianScheirer Site: http://bbcascades.com/

30

Be in touch

Page 31: Simple Game Development in Cascades

THANK YOU

JAM42Eric HartyBrian ScheirerMay 14-16, 2013