-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·99 lines (80 loc) · 2.06 KB
/
Copy pathmain.js
File metadata and controls
executable file
·99 lines (80 loc) · 2.06 KB
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
enchant();
window.onload=function(){
var game = new Core(320, 320),
GAME_WIDTH = 320,
GAME_GROUND = 150,
STAR_NUM = 100;
game.fps = 15;
game.preload('avatarBg1.png', 'avatarBg2.png', 'avatarBg3.png', "space3.png", "icon0.png");
game.onload = function(){
// 背景
game.rootScene.backgroundColor="#000000";
bg =new AvatarBG(1);
bg.y=50;
game.rootScene.addChild(bg);
// くま
var bear = new Sprite(32, 32);
bear.image = game.assets["space3.png"];
bear.x = 40;
bear.y = GAME_GROUND;
bear.frame = 5;
game.rootScene.addChild(bear);
// 星
var star = [];
for ( var i = -1; ++i < STAR_NUM; ) {
star[i] = new Sprite(16, 16);
star[i].image = game.assets["icon0.png"];
star[i].x = GAME_WIDTH + GAME_WIDTH * Math.random();
star[i].y = GAME_GROUND * Math.random();
star[i].frame = 30;
game.rootScene.addChild(star[i]);
}
bear.addEventListener("enterframe", function(){
// 背景スクロール
bg.scroll(game.frame*2);
// 星
for ( var i = -1; ++i < STAR_NUM; ) {
star[i].x -= 3;
if(this.intersect(star[i]) || star[i].x < 0){
star[i].x = GAME_WIDTH + i;
star[i].y = GAME_GROUND * Math.random();
}
}
// コマンド受け付け
if (game.input.left) {
this.x -=5;
}
if (game.input.right) {
this.x +=5;
}
if (game.input.up) {
if (this.a < 5) {
this.y -=30;
}
}
if ( this.x > GAME_WIDTH-33 ) {
this.x = GAME_WIDTH-33;
} else if ( this.x < -8 ) {
this.x = -8;
}
// 飛んでいる時の処理
if (this.y < GAME_GROUND) {
// くまの見た目
this.frame = 6;
// 落下速度
this.a += 1;
this.y += this.a;
// 地面にめり込んだら戻す
if(this.y > GAME_GROUND){
this.y = GAME_GROUND;
}
} else {
// くまの見た目(走る)
this.frame = this.age % 2 + 6;
// 落下速度リセット
this.a = 0;
}
});
};
game.start();
}