-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgame.js
133 lines (108 loc) · 3.93 KB
/
game.js
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
enchant();
//円の色指定
var CIRCLE_COLOR = "rgb(100,100,100)";
//円の半径指定
var CIRCLE_RADIUS = 30;
//円の個数指定
var CIRCLE_NUM = 10;
// htmlを読み込み終わったらロードされる
window.onload = function() {
//ゲームオブジェクトの生成
var game = new Game(320, 320);
game.fps = 16;
game.score = 0;
//画像読み込み
game.preload('http://enchantjs.com/assets/images/chara1.gif',
'http://enchantjs.com/assets/images/map0.gif',
'http://enchantjs.com/assets/images/icon0.gif');
//サーフェイスに色指定メソッドの追加
Surface.prototype.setColor = function(strokeColor, fillColor) {
this.context.strokeStyle = strokeColor;
this.context.fillStyle = fillColor;
};
//サーフェイスに円塗りつぶしのメソッドの追加
Surface.prototype.fillCircle = function(x, y, r) {
this.context.beginPath();
this.context.arc(x, y, r, 0, Math.PI * 2, true);
this.context.fill();
};
//円の描画
//これを呼び出すと、個数分の円の登録が完了する
game.addCircle = function() {
//サーフェイスオブジェクトの生成
var surface = new Surface(50,50);
//サーフェイスの色を指定
surface.setColor("rgb(0,0,0)",CIRCLE_COLOR);
//座標記憶用配列の準備
var tmp = Array(CIRCLE_NUM);
for (var i = 0; i < CIRCLE_NUM; i++) {
tmp[i] = Array(2);
}
//for文の開始(円の個数分)
for (var i = 0; i < CIRCLE_NUM; i++) {
var isFull = false;
var s = 0;
while (!isFull) {
//ランダムな座標を生成
x = rand(280) + 10;
y = rand(280) + 10;
var isDuplication = false;
for (var j = 0; j < tmp.length; j++) {
if (tmp[j][0] - 10 < x && x < tmp[j][0] + 10) {
isDuplication = true;
}
if (tmp[j][1] - 10 < y && y < tmp[j][1] + 10) {
isDuplication = true;
}
}
if (isDuplication) {
continue;
}
tmp[i][0] = x;
tmp[i][1] = y;
s++;
if (s >= 10) {
isFull = true;
}
}
console.log("END");
for (var j = 0; j < tmp.length; j++) {
console.log(tmp[j][0]);
}
//ランダムな座標は配列に記憶、重ならないように処理する
//for (var j = 0; j < tmp.length; j++) {
// if (tmp[j])
//ランダムな座標が決定
//Sprite[i]の生成
//imageにsurfaceを指定
//ランダム座標を元に、sprite[i]のx,yを決定する
//ルートシーンにsprite[i]を追加する
//タッチされたときのsprite[i]の処理を書く(エフェクト)
//for文終わり
}
//これで個数分のspriteの登録が終わった
};
//ロード完了時に呼ばれる
//ここは画像の指定とか一番最初に処理するところ
game.onload = function () {
//背景の生成
//背景スプライトの生成
var bg = new Sprite(320, 320);
//背景色の指定
bg.backgroundColor = "rgb(100, 100, 100)";
//ルートシーンに追加
game.rootScene.addChild(bg);
//円の追加
game.addCircle();
};
//ルートシーンの定期処理
game.tick = 16 * 10;
game.rootScene.addEventListener(Event.ENTER_FRAME, function() {
});
//ゲームスタート
game.start();
};
//乱数の生成
function rand(num) {
return Math.floor(Math.random() * num);
}