-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
190 lines (141 loc) · 5.12 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World Application</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/appmobi.js"></script>
<script type="text/javascript" charset="utf-8" src="lib/caat/caat.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
* {
-webkit-user-select: none; /* prevent copy paste for all elements */
}
body { }
</style>
<script type="text/javascript" language="javascript">
Array.prototype.randomElement = function () {
return this[Math.floor(Math.random() * this.length)]
}
//global variables
//Initialization function
function init() {}
//*** Prevent Default Scrolling ******
preventDefaultScroll = function(event) {
// Prevent scrolling on this element
event.preventDefault();
window.scroll(0,0);
return false;
};
window.document.addEventListener('touchmove', preventDefaultScroll, false);
var Game = {}
Game.Character = function(director){
var meta = {
height_choices: ["s","t"],
weight_choices: ["s","f"],
color_choices: ["blue","purple","red"],
item_choices: ["glasses","hat","scarf"], // TODO: null option
mood_choices: ["angry","happy","sad"],
dimensions: {
ss: [231,239],
sf: [231,239],
ts: [300,462],
tf: [300,462]
}
}
var c = {
height: meta.height_choices.randomElement(),
weight: meta.weight_choices.randomElement(),
color: meta.color_choices.randomElement(),
item: meta.item_choices.randomElement(),
mood: meta.mood_choices.randomElement(),
images: {
face: new Image(),
body: new Image(),
item: new Image()
}
}
var path = "assets/persons/";
var ext = ".png";
c.images.face.src = path + c.height + c.weight + "-" + c.color + "-" + c.mood + ext;
c.images.body.src = path + c.height + c.weight + "-" + c.color + ext;
c.images.item.src = path + c.height + c.weight + "-" + c.item + ext;
var cActor = new CAAT.ActorContainer().
setBounds(0,0,300,462);
setTimeout(function(){ // HACK: timeout so that images have a chance to load
var x = 300, y = 462;
var face = new CAAT.Actor().
setBackgroundImage(c.images.face, true).
setLocation((x-c.images.body.width)/2, (y-c.images.body.height));
var body = new CAAT.Actor().
setBackgroundImage(c.images.body, true).
setLocation((x-c.images.body.width)/2, (y-c.images.body.height));
var item = new CAAT.Actor().
setBackgroundImage(c.images.item, true).
setLocation((x-c.images.body.width)/2, (y-c.images.body.height));
cActor.addChild(body);
cActor.addChild(face);
cActor.addChild(item);
}, 50);
cActor.data = c;
return cActor;
}
function setupCAAT() {
function __scene(director) {
var scene = director.createScene();
var bg= new CAAT.ActorContainer().
setBounds(0,0,director.width,director.height).
setFillStyle('#000000');
scene.addChild(bg);
var character = new Game.Character();
bg.addChild(character);
}
function __init() {
director = new CAAT.Director().
initialize(320, 480, document.getElementById("thecanvas"));
/*new CAAT.ImagePreloader().loadImages(
[
{id:'char2', url:'assets/persons/sf-blue.png'}
],
function( counter, images ) {
director.setImagesCache(images);
__scene(director);
}
);*/
__scene(director);
CAAT.loop(60);
}
__init();
}
//*** Device Ready Code **********
//This event handler is fired once the AppMobi libraries are ready
//AppMobi is ready to roll
function testingStuffCallback(res) {
document.getElementById('contentstuff').innerHTML = 'gamma(5) = ' + res;
}
function onDeviceReady() {
//use AppMobi viewport
AppMobi.display.useViewport(320,480);
//lock orientation
AppMobi.device.setRotateOrientation("landscape");
AppMobi.device.setAutoRotate(false);
//manage power
AppMobi.device.managePower(true,false);
AppMobi.device.hideSplashScreen();
// Test function
//document.getElementById('debugging').textContent = AppMobi.testingStuff;
//document.getElementById('contentstuff').innerHTML = 'Running test function...';
//AppMobi.testingStuff(5, 'testingStuffCallback');
setupCAAT();
}
</script>
</head>
<body onload="init();">
<canvas id="thecanvas"></canvas>
<script>
if (typeof(AppMobi) === "undefined") {
setupCAAT();
} else {
document.addEventListener("appMobi.device.ready",onDeviceReady,false);
}
</script>
</html>