-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
727 lines (603 loc) · 32.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Playtomic: open source leaderboards, achievements, user created content and dynamic content for games</title>
<meta name="description" content="Free, open source, self-hosted achievements, leaderboards and more for html5, ios, android, c#, unity3d and flash games.">
<link href='css/bootstrap/bootstrap.min.css' rel='stylesheet' type='text/css'>
<link href='css/custom.css' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800' rel='stylesheet' type='text/css'>
<link rel="icon" href="assets/favicon.ico" type="image/icon" />
</head>
<body>
<div id="sponsor">
<div class="container">
Need support you can't find on Stackoverflow or programming communities you use? I'm busy but you can <a href="mailto:benlowry@outlook.com">contact me</a>!
</div>
</div>
<header>
<div class="container">
<a href="http://playtomic.org/" class="logo"><img src="assets/playtomic.png" alt="Playtomic" title="Playtomic" /></a>
<ul>
<li><a href="/server.html">Server setup</a></li>
<li><a href="/games.html">Game setup</a></li>
<li><a href="/apis.html">API documentation</a></li>
<li class="follow">
<a href="https://github.com/playtomic" target="_blank" class="github-follow-button">
<img src="/assets/github.png" alt=""/>
Github
</a>
</li>
<li class="follow">
<a href="https://twitter.com/playtomic" target="_blank" class="github-follow-button">
<img src="/assets/twitter.png" alt=""/>
Twitter
</a>
</li>
</ul>
</div>
</header>
<div id="splash">
<div class="container">
<h1>Leaderboards, achievements, user levels,<br />dynamic content, in-game newsletter subscriptions</h1>
<h2>Open source. Scalable. Cross-platform. Free.</h2>
</div>
</div>
<div id="content">
<div class="container">
<div class="row">
<div class="span6">
<div class="section">
<h2>Developers, take control of your backend</h2>
<p>Playtomic.org is the new home of the tools
once provided by Playtomic - achievements, leaderboards, player levels, gamevars, geoip and in-game newsletter subscription - as a simple to host, open source platform for your game
compatible with most gaming platforms.</p>
<p>Setting up your server is very easy and for small games will probably stay under the free limits of the selected hosting providers.</p>
<p>It's your game, now it's your backend too.</p>
</div>
</div>
<div class="span6">
<div class="section">
<h2>Game APIs</h2>
<p>Playtomic has extensive documentation, compatibility and tests/examples for all major gaming platforms.</p>
<ul>
<li><a href="/api/as3.html">ActionScript 3</a></li>
<li><a href="/api/android.html">Android / Java</a></li>
<li><a href="/api/openfl.html">Haxe / OpenFL</a></li>
<li><a href="/api/html5.html">HTML5 / JavaScript</a></li>
<li><a href="/api/ios.html">iOS / Objective C</a></li>
<li><a href="/api/csharp.html">Mono and .NET</a></li>
<li><a href="/api/unity3d.html">Unity3d</a></li>
</ul>
</div>
</div>
<div class="span12">
<div class="section">
<h2>Examples</h2>
<p>To demonstrate the flexibility here are some examples of what you can do with the different APIs.</p>
<div class="btn-group">
<a class="btn btn-small" href="#leaderboards">Leaderboards</a>
<a class="btn btn-small" href="#achievements">Achievements</a>
<a class="btn btn-small" href="#playerlevels">User content</a>
<a class="btn btn-small" href="#gamevars">Dynamic content</a>
<a class="btn btn-small" href="#newsletters">Newsletters</a>
</div>
</div>
</div>
</div>
</div>
<div class="row1 firstrow">
<div class="container">
<div class="row">
<div class="span3">
<div class="section">
<h2>Achievements</h2>
<p>Cross-platform, versatile and flexible achievements system.</p>
</div>
</div>
<div class="span9">
<div class="section">
<h3>Features</h3>
<ul>
<li>Award once, overwrite, or allowduplicates</li>
<li>Filter by device or website</li>
<li>Filter by custom fields like difficulty to differentiate between different levels of achievement</li>
<li>Include own and friends' status when retrieving lists</li>
<li>Filter by own and friends' ids to make everything social</li>
<li>View awarded achievements as a stream of updates</li>
<li>Group the achievement stream to show only the most recent for each player</li>
</ul>
<h4>Achievements example</h4>
<button class="btn btn-small" onclick="this.style.display='none'; document.getElementById('achievement_example').style.display='block'; ">Show the example code</button>
<pre id="achievement_example" style="display: none;"><span class="green">// let's start with listing</span>
<span class="blue3">var</span> options = {
playerid: <span class="blue">"my_id"</span> <span class="green">// optional from facebook or google or twitter or apple or whatever</span>
}
Playtomic.Achievements.list(options, function(achievements, response){
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
<span class="green">/*
* now we have our achievement list, it will be something like this:
* [
* {
* achievement: "did something awesome"
* },
* {
* achievement: "killed the boss",
* player: { // when the specified player has the achievement we have a 'player' object
* // with the data, when we include our friends we get an
* // array called 'friends' of objects the same as this
* playerid: "my_id",
* playername: "fred",
* date: new Date(),
* rdate: "3 days ago",
* fields: {
* difficulty: "easy"
* }
* }
* }
* ]
*/</span>
<span class="green">// now let's make it more interesting by including our friends</span>
options.friendslist = [ <span class="blue">"an"</span>, <span class="blue">"array"</span>, <span class="blue">"of"</span>, <span class="blue">"friends"</span>, <span class="blue">"ids"</span>];
Playtomic.Achievements.list(options, <span class="blue3">function</span>(achievements, response){
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<achievements.length; i++) {
<span class="blue3">var</span> message = achievements[i].achievement;
<span class="blue3">if</span>(achievements[i].player) {
message += <span class="blue">", awarded to player on "</span> + achievements[i].player.date;
}
<span class="blue3">if</span>(achievements[i].friends) {
<span class="blue3">var</span> friends = <span class="blue">""</span>;
<span class="blue3">if</span>(achievements[i].friends.length > 3) {
friends = achievements[i].friends[<span class="red">0</span>].playername + <span class="blue">", "</span> +
achievements[i].friends[<span class="red">1</span>].playername + <span class="blue">", "</span> +
achievements[i].friends[<span class="red">2</span>].playername + <span class="blue">" and "</span> +
(achievements[i].friends.length - <span class="red">3</span>) + <span class="blue">" more"</span>;
} else {
<span class="blue3">for</span>(<span class="blue3">var</span> j=<span class="red">0</span>; j<achievements[i].friends.length; j++) {
friends += (j > <span class="red">0</span> ? <span class="blue">","</span> : <span class="blue">""</span>) + achievements[i].friends[j].playername;
}
}
message += <span class="blue">", awarded to "</span> + achievements[i].friends.length + <span class="blue">" friends: "</span> + friends;
}
console.log(message);
<span class="green">// output: killed the boss, awarded to player on May 10 2013,
// awarded to 7 friends: tom, dick, harry and 4 more</span>
}
<span class="green">// let's view the achievements chronologically by me</span>
options = {
playerid: <span class="blue">"my_id"</span>,
}
Playtomic.Achievements.stream(options, <span class="blue3">function</span>(achievements, numachievements, response) {
<span class="blue3"><span class="blue3">if</span></span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"I have "</span> + numachievements + <span class="blue">" achievements,
here are the latest"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<achievements.length; i++) {
console.log(achievements[i].awarded.achievement + <span class="blue">" on "</span> + achievements[i].date +
<span class="blue">" ("</span> + achievements[i].fields.difficulty + <span class="blue">")"</span>);
}
<span class="green">// and now let's view me and my friends with one-update-per-person</span>
options.friendslist = [<span class="blue">"2"</span>, <span class="blue">"3"</span>, <span class="blue">"4"</span>, <span class="blue">"5"</span>];
options.group = <span class="blue2">true</span>; <span class="green">// this triggers making it the most recent for each person</span>
Playtomic.Achievements.stream(options, <span class="blue3">function</span>(achievements, numachievements, response) {
<span class="blue3"><span class="blue3">if</span></span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"My friends and I have "</span> + numachievements + <span class="blue">" achievements, here are the latest"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<achievements.length; i++) {
console.log(achievements[i].awarded.achievement + <span class="blue">" to "</span> + achievements[i].playername +
<span class="blue">" on "</span> + achievements[i].date + <span class="blue">" ("</span> + achievements[i].fields.difficulty + <span class="blue">")"</span>;
<span class="green">// output: killed the boss, awarded to ben on May 14 2013 (easy)</span>
<span class="green">// output: killed the boss, awarded to tom on May 10 2013 (hard)</span>
}
<span class="green">// and now let's make it just the hard achievements</span>
options.filter = {
difficulty: <span class="blue">"hard"</span>
}
Playtomic.Achievements.stream(options, <span class="blue3">function</span>(achievements, numachievements, response) {
<span class="blue3"><span class="blue3">if</span></span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"My friends and I have "</span> + numachievements + <span class="blue">" hard achievements, here are the latest"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<achievements.length; i++) {
console.log(achievements[i].awarded.achievement + <span class="blue">" to "</span> + achievements[i].playername +
<span class="blue">" on "</span> + achievements[i].date +
<span class="blue">" ("</span> + achievements[i].fields.difficulty + <span class="blue">")"</span>);
<span class="green">// output: killed the boss, awarded to tom on May 10 2013 (hard)</span>
}
});
});
});
});
});</pre>
</div>
</div>
</div>
</div>
</div>
<div class="row2">
<div class="container">
<div class="row">
<div class="span3">
<div class="section">
<h2>Newsletters</h2>
<p>Build your mailing list in-game</p>
</div>
</div>
<div class="span9">
<div class="section">
<h3>Features</h3>
<ul>
<li>Built on top of the very powerful <a href="http://mailchimp.com/">MailChimp</a> API</li>
<li>Players don't have to leave your game</li>
<li>Free for up to 2,000 players with 12,000 emails per month</li>
<li>Pay as you go and subscription options available</li>
</ul>
<p>On the server side you can turn double opt-in off and disable updating a player's records
if they re-submit their information.</p>
<h4>Subscription example</h4>
<button class="btn btn-small" onclick="this.style.display='none'; document.getElementById('newsletter_example').style.display='block'; ">Show the example code</button>
<pre id="newsletter_example" style="display: none;"><span class="blue3">var</span> subscription = {
email: <span class="blue">"test@exampleuri.com"</span>, <span class="green">// the only mandatory field</span>
firstname: <span class="blue">"fred"</span>,
lastname: <span class="blue">"bloggs"</span>,
fields: {
FIRSTPLAYED: <span class="blue">"2013-05-20"</span>,
PLATFORM: <span class="blue">"as3-web"</span>,
GAMEVERSION: <span class="red">1.08</span>,
RESOLUTION: <span class="blue">"800x400"</span>
}
};
<span class="green">// note that these example MERGE fields must be created in your MailChimp</span>
<span class="green">// dashboard, they do not exist by default.</span>
Playtomic.Newsletters.subscribe(subscription, <span class="blue3">function</span>(response) {
<span class="blue3">if</span>(response.success) {
}
<span class="blue3">else</span> {
<span class="green">// response failed because of response.errormessage</span>
}
});</pre>
</div>
</div>
</div>
</div>
</div>
<div class="row1">
<div class="container">
<div class="row">
<div class="span3">
<div class="section">
<h2>Leaderboards</h2>
<p>Incredibly rich capabilities available to build on.</p>
</div>
</div>
<div class="span9">
<div class="section">
<h3>Features</h3>
<ul>
<li>Highest or lowest</li>
<li>Custom fields for additional data like characters, kills, or anything else you want</li>
<li>Filtering by custom fields to automatically create sub-leaderboards on that data</li>
<li>Five simple modes: TODAY, LAST7DAYS, LAST30DAYS, ALLTIME, NEWEST (a score stream)</li>
<li>Filter by friends' ids to make your leaderboards social</li>
<li>Filter by player's id to make your leaderboards personal</li>
<li>Combine all of the above to make the most powerful leaderboards around!</li>
</ul>
<h4>Leaderboard example</h4>
<p>Imagine a racing game that you and your friends play. Let's walk through some of the awesome capabilities
waiting for you in these leaderboards using the HTML5 API.</p>
<button class="btn btn-small" onclick="this.style.display='none'; document.getElementById('leaderboard_example').style.display='block'; ">Show the example code</button>
<pre id="leaderboard_example" style="display: none;"><span class="green">// we just tore up race #10 in our lambo</span>
<span class="blue3">var</span> score = {
playername: <span class="blue">"fred"</span>,
playerid: <span class="blue">"my_id"</span>, <span class="green">// optional facebook, apple, google, device, whatever you want</span>
points: <span class="red">243</span>, <span class="green">// seconds</span>
allowduplicates: <span class="blue2">false</span>, <span class="green">// only save the player's best score</span>
lowest: <span class="blue2">true</span>, <span class="green">// low score is best</span>
fields: { <span class="green">// save this additional data with the score</span>
car: <span class="blue">"Lamborghini Gallardo"</span>,
race: <span class="red">10</span>
},
filters: { <span class="green">// return scores with these fields</span>
race: <span class="red">10</span>
}
}
<span class="green">// by using saveAndList we submit a score and return the 'page' of scores the</span>
<span class="green">// ranked score sits on, eg 17th score on 10 per page will give us scores #11 - 20</span>
Playtomic.Leaderboards.saveAndList(score, <span class="blue3">function</span>(scores, numscores, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"Best times for race #10 ("</span> + numscores + <span class="blue">" total scores)"</span>);
<span class="blue3">var</span> i;
<span class="blue3">for</span>(i=<span class="red">0</span>; i<scores.length; i++) {
console.log(scores[i].rank + <span class="blue">" "</span> + scores[i].points + <span class="blue">" "</span> +
scores[i].playername + <span class="blue">" driving "</span> + scores[i].fields.car);
}
<span class="green">// let's drill down further and just look at that car</span>
<span class="blue3">var</span> list = {
lowest: <span class="blue2">true</span>,
perpage: <span class="red">10</span>,
filters: {
car: <span class="blue">"Lamborghini Gallardo"</span>,
race: <span class="red">10</span>
}
}
Playtomic.Leaderboards.list(list, <span class="blue3">function</span>(scores, numscores, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"Best times for Lamborghini Gallardos on race #10"</span>);
<span class="blue3">for</span>(i=<span class="red">0</span>; i<scores.length; i++) {
console.log(scores[i].rank + <span class="blue">" "</span> + scores[i].points + <span class="blue">" "</span> + scores[i].playername);
}
<span class="green">// let's drill down further and make this about my personal bests</span>
<span class="blue3">var</span> myleaderboard = {
lowest: <span class="blue2">true</span>,
perpage: <span class="red">10</span>,
playerid: <span class="blue">"my_id"</span>,
filters: {
car: <span class="blue">"Lamborghini Gallardo"</span>,
race: <span class="red">10</span>
}
}
Playtomic.Leaderboards.list(myleaderboard, <span class="blue3">function</span>(scores, numscores, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"My best times for Lamborghini Gallardos on race #10"</span>);
<span class="blue3">for</span>(i=<span class="red">0</span>; i<scores.length; i++) {
console.log(scores[i].rank + <span class="blue">" "</span> + scores[i].points + <span class="blue">" "</span> + scores[i].rdate);
<span class="green">// 'rdate' is a friendly date format relative to utc, like 7 minutes ago</span>
}
<span class="green">// let's see what my friends are submitting as a stream</span>
<span class="blue3">var</span> friendsactivity = {
perpage: <span class="red">20</span>,
friendslist: [<span class="blue">"array of friends' playerids"</span>],
mode: <span class="blue">"newest"</span> <span class="green">// in 'newest' we get the scores as an unranked stream</span>
}
Playtomic.Leaderboards.list(friendsactivity, <span class="blue3">function</span>(scores, numscores, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"Latest scores from my friends"</span>);
<span class="blue3">for</span>(i=<span class="red">0</span>; i<scores.length; i++) {
console.log(scores[i].points + <span class="blue">" "</span> + scores[i].playername +
<span class="blue">" driving "</span> + scores[i].fields.car + <span class="blue">" on race "</span> + scores[i].fields.race);
}
});
});
});
});</pre>
</div>
</div>
</div>
</div>
</div>
<div class="row2">
<div class="container">
<div class="row">
<div class="span3">
<div class="section">
<h2>PlayerLevels</h2>
<p>Cross-platform user created content.</p>
</div>
</div>
<div class="span9">
<div class="section">
<h3>Features</h3>
<ul>
<li>Rate creations</li>
<li>Custom fields for any meta data you want to include </li>
<li>Filtering by custom fields </li>
<li>Two simple modes: POPULAR and NEWEST</li>
<li>Fetch lists of levels with heavy data payloads excluded to reduce bandwidth</li>
<li>Filter by friends' ids to share content within a player's personal network</li>
<li>Filter by player's id to maintain a catalog of the player's creations</li>
<li>Create content on tablets or web to share with smaller form factors</li>
</ul>
<h4>PlayerLevel example</h4>
<p>You've created a game where players can design their own levels for other people
to play. This is how you'd do it with the HTML5 API.</p>
<button class="btn btn-small" onclick="this.style.display='none'; document.getElementById('playerlevel_example').style.display='block'; ">Show the example code</button>
<pre id="playerlevel_example" style="display: none;"><span class="green">// let's save our creation</span>
<span class="blue3">var</span> level = {
name: <span class="blue">"my level"</span>,
playername: <span class="blue">"ben"</span>,
playerid: <span class="blue">"my_id"</span>, <span class="green">// optional facebook, apple, google, device, whatever you want</span>
data: <span class="blue">"this is the level data"</span>,
fields: {
shots: <span class="red">9</span>,
enemies: <span class="red">8</span>
}
}
Playtomic.PlayerLevels.save(level, <span class="blue3">function</span>(l, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"my level has been saved with level id "</span> + l.levelid);
<span class="green">// someone wants to play the levels other people have made</span>
<span class="blue3">var</span> options = {
mode: <span class="blue">"popular"</span>,
perpage: <span class="red">10</span>,
data: <span class="blue2">false</span> <span class="green">// if your level data is big and you are retrieving lots of</span>
<span class="green">// levels at once you can exclude the data and just load it</span>
<span class="green">// individually </span>
}
Playtomic.PlayerLevels.list(options, <span class="blue3">function</span>(levels, numlevels, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"loaded "</span> + levels.length + <span class="blue">" levels out of "</span> + numlevels + <span class="blue">" total"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<levels.length; i++) {
console.log(levels[i].name + <span class="blue">" by "</span> + levels[i].ben + <span class="blue">": "</span> + levels[i].rating);
}
<span class="green">// now let's pretend we clicked on one of those levels to play it, because</span>
<span class="green">// we excluded the data when we fetched the list we now need to load it in</span>
<span class="green">// a seperate request</span>
Playtomic.PlayerLevels.load(selected.levelid, <span class="blue3">function</span>(level, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"ready to play "</span> + level.name);
<span class="green">// so we beat this level and now we want to rate it out of 10</span>
Playtomic.PlayerLevels.rate(level.levelid, <span class="red">8</span>, <span class="blue3">function</span>(response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"rated "</span> + level.levelid + <span class="blue">" successfully, which increases "</span> +
<span class="blue">"the votes by 1 and the score by 8, from which the rating is calculated."</span>);
<span class="green">// now we want to play our friends' levels</span>
<span class="blue3">var</span> friendslevels = {
mode: <span class="blue">"popular"</span>,
perpage: <span class="red">10</span>,
data: <span class="blue2">true</span>,
friendslist: [<span class="blue">"my"</span>, <span class="blue">"friends"</span>, <span class="blue">"playerids"</span>]
}
Playtomic.PlayerLevels.list(friendslists, <span class="blue3">function</span>(levels, numlevels, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"loaded "</span> + levels.length + <span class="blue">" levels out of "</span> + numlevels + <span class="blue">" total"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<levels.length; i++) {
console.log(levels[i].name + <span class="blue">" by "</span> + levels[i].ben + <span class="blue">": "</span> + levels[i].rating);
}
<span class="green">// now i want to show off my own creations</span>
<span class="blue3">var</span> mylevels = {
mode: <span class="blue">"popular"</span>,
playerid: <span class="blue">""my_id"</span>
}
Playtomic.PlayerLevels.list(mylevels, <span class="blue3">function</span>(levels, numlevels, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
console.log(<span class="blue">"loaded "</span> + levels.length + <span class="blue">" levels out of "</span> + numlevels + <span class="blue">" total"</span>);
<span class="blue3">for</span>(<span class="blue3">var</span> i=<span class="red">0</span>; i<levels.length; i++) {
console.log(levels[i].name + <span class="blue">" by "</span> + levels[i].ben + <span class="blue">": "</span> + levels[i].rating);
}
});
});
});
});
});
});
});</pre>
</div>
</div>
</div>
</div>
</div>
<div class="row1">
<div class="container">
<div class="row">
<div class="span3">
<div class="section">
<h2>GameVars</h2>
<p>Update your game without republishing</p>
</div>
</div>
<div class="span9">
<div class="section">
<h3>Features</h3>
<ul>
<li>Update at any time in your database</li>
<li>Tweak difficulty balancing</li>
<li>Store game configuration</li>
<li>Manage cross-promotions</li>
<li>Rotate between advertising partners</li>
</ul>
<h4>GameVars example</h4>
<p>In our game we are going to store the entire configuration for our enemies. This data weighs in at
47 kilobytes so we are also going to store a 'version' we can cache to skip reloading the same
data.</p>
<button class="btn btn-small" onclick="this.style.display='none'; document.getElementById('gamevars_example').style.display='block'; ">Show the example code</button>
<pre id="gamevars_example" style="display: none;"><span class="green">// first let's set up our default configuration for when the player is disconnected</span>
<span class="blue3">var</span> config = {
version: <span class="red">1</span>,
enemies: { <span class="green">// the enemy configuration</span>
badguy1: {
hitpoints: <span class="red">100</span>,
gun: <span class="red">3</span>,
speed: <span class="red">8</span>,
damage: <span class="red">3</span>
},
....
badguy9000: {
hitpoints: <span class="red">10000000</span>,
gun: <span class="red">12</span>,
speed: <span class="red">47</span>,
damage: <span class="red">120</span>
}
},
player: { <span class="green">// the player's configuration</span>
hitpoints: <span class="red">1000</span>,
xplevels: [ <span class="green">// when to upgrade the player's level</span>
<span class="red">1000</span>,
....
<span class="red">1024000</span>
]
},
powerups: { <span class="green">// probability of dropping cool stuff</span>
powerup1: <span class="red">0.3</span>
....
powerup10: <span class="red">0.0005</span>
},
crosspromotion: { <span class="green">// will we promote our other game</span>
enabled: <span class="blue2">true</span>,
url: <span class="blue">"https://itunes.apple.com/...."</span>,
image: <span class="blue">"https://the_url_to_my_image.png"</span>
}
}
<span class="green">// so now when the player opens up your game we load the 'version'</span>
Playtomic.GameVars.loadSingle(<span class="blue">"version"</span>, <span class="blue3">function</span>(gamevars, response)) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
<span class="green">// check if we need to make the bigger request for all of the data</span>
<span class="blue3">if</span>(gamevars.version > config.version) {
Playtomic.GameVars.load(<span class="blue3">function</span>(gamevars, response) {
<span class="blue3">if</span>(!response.success) {
<span class="blue3">return</span> console.log(<span class="blue">"something went wrong: "</span> + response.errormessage);
}
<span class="green">// and update our local config, you could do this in a variety of ways depending on</span>
<span class="green">// if you are storing one giant GameVar with the entire config:</span>
config = gamevars;
<span class="green">// or doing each section as a separate GameVar</span>
config.version = gamevars.version;
config.enemies = gamevars.enemies;
config.player = gamevars.player;
config.powerups = gamevars.powerups;
config.crosspromotion = gamevars.crosspromotion;
<span class="green">// or going even more granular</span>
config.enemies.badguy1 = gamevars.enemies_badguy1;
});
});
});
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
© 2013 Ben Lowry. Server and client software are released under the <a href="http://opensource.org/licenses/MIT">MIT license</a>.
</div>
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40077834-4', 'playtomic.org');
ga('send', 'pageview');
</script>
</body>
</html>