/* * 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, }); /* * メイン処理(ページ読み込み後に実行される) */ tm.main(function() { // アプリケーション作成 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.enemy = tm.app.StarShape(64,64); this.addChild(this.enemy); // シーンに追加 this.star = tm.app.Sprite("CAT"); this.addChild(this.star); // シーンに追加 // ユーザーデータの生成 userData = tm.util.DataManager.get("userData"); // スコアのラベル this.scoreLabel = tm.app.Label(); this.scoreLabel.position.set(SCREEN_WIDTH, 40); this.scoreLabel.text = "score : " + userData.score; this.scoreLabel.width = tm.app.width; this.scoreLabel.align = "end"; this.scoreLabel.fontSize = 32; this.addChild(this.scoreLabel); }, update: function(app) { var p = app.pointing; // this.enemy.x = 300; this.enemy.y = 300; // マウス位置 or タッチ位置に移動 this.star.x = p.x; this.star.y = p.y; // if(this.star.isHitElement(this.enemy) && this.enemy.visible == true){ tm.sound.SoundManager.get("hit_se").play(); this.enemy.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.setSize(this.star.width * this.star.scaleX , this.star.height * this.star.scaleY); } }, });