/* * constant */ var SCREEN_WIDTH = 640; var SCREEN_HEIGHT = 480; var SCREEN_CENTER_X = SCREEN_WIDTH/2; var SCREEN_CENTER_Y = SCREEN_HEIGHT/2; // アセット var ASSETS = { "CAT": "neko.png" }; /** * リソースの読み込み */ tm.preload(function() { // 音 tm.sound.SoundManager.add("hit_se", "hit_se.wav"); }); //画像読み込み tm.asset.AssetManager.load("TitleImage" , "title.png"); // ユーザーのデータの定義 tm.util.DataManager.set("userData", { score: 10, time: 100 , speed: 1 }); /* * メイン処理(ページ読み込み後に実行される) */ tm.main(function() { // ユーザーデータの生成 userData = tm.util.DataManager.get("userData"); // アプリケーション作成 var app = tm.app.CanvasApp("#world"); app.resize(SCREEN_WIDTH, SCREEN_HEIGHT); // リサイズ app.fitWindow(); // 自動フィット app.replaceScene(TitleScene()); // 実行 app.run(); }); /** * TitleScene */ tm.define("TitleScene", { superClass : "tm.app.TitleScene", init : function() { this.superInit({ title : "タイトル画面", width : SCREEN_WIDTH, height : SCREEN_HEIGHT, backgroundImage : "TitleImage" }); }, update: function(app) { var key = app.keyboard; if (key.getKey("z")) { // シーンの遷移 var loadingScene = tm.app.LoadingScene({ assets: ASSETS, nextScene: MainScene, width: SCREEN_WIDTH, height: SCREEN_HEIGHT }); this.app.replaceScene(loadingScene); } } }); tm.define("MainScene", { superClass: "tm.app.Scene", init: function() { // 親の初期化 this.superInit(); this.rect = tm.app.RectangleShape(64,64); this.addChild(this.rect); // シーンに追加 this.star = tm.app.Sprite("CAT"); this.star.scaleSetSize = function() {this.setSize(this.width * this.scaleX , this.height * this.scaleY);} this.addChild(this.star); // シーンに追加 // ユーザーデータの生成 userData = tm.util.DataManager.get("userData"); // スコアのラベル this.scoreLabel = tm.app.Label(); l_obj = { x : SCREEN_WIDTH, y : 40, text : "score : " + userData.score, width : tm.app.width, align : "end", fontSize : 32 } setLabel(this.scoreLabel ,l_obj); this.addChild(this.scoreLabel); // タイムのラベル this.timeLabel = tm.app.Label(); l_obj.x = 240; l_obj.text = "time : " + userData.time; setLabel(this.timeLabel ,l_obj); this.addChild(this.timeLabel); // スピードのラベル this.speedLabel = tm.app.Label(); l_obj.y = 80; l_obj.text = "speed : " + userData.speed; setLabel(this.speedLabel ,l_obj); this.addChild(this.speedLabel); }, update: function(app) { var p = app.pointing; // this.rect.x = 300; this.rect.y = 300; // マウス位置 or タッチ位置に移動 this.star.x = p.x; this.star.y = p.y; // if(this.star.isHitElement(this.rect) && this.rect.visible == true){ tm.sound.SoundManager.get("hit_se").play(); this.rect.visible = false; // スコアを更新 userData.score += 100; this.scoreLabel.text = "score : " + userData.score; } // クリック or タッチ中は回転させる if (app.pointing.getPointing() == true) { this.star.rotation += 15; } //キーボタン受付 var key = app.keyboard; if (key.getKey("z")) { this.star.scaleX += 0.1; this.star.scaleY += 0.1; this.star.scaleSetSize(); } }, }); function setLabel(that , l_obj){ that.position.set(l_obj.x , l_obj.y); that.text = l_obj.text; that.align = l_obj.align; that.width = l_obj.width; that.fontSize = l_obj.fontSize; }