-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
126 lines (119 loc) · 3.92 KB
/
main.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
phina.globalize();
const SCREEN_WIDTH = 640;
const SCREEN_HEIGHT = 960;
let ASSETS = {
image: {
'titlebg':'title.png',
'enemy': 'typhoon.png',
'player': 'ninja.png',
'bg': 'background.png',
},
}
phina.define('TitleScene', {
superClass: 'DisplayScene',
// コンストラクタ
init: function() {
this.superInit();
// グループ
var bgGroup = DisplayElement().addChildTo(this);
// 背景追加
(2).times(function(i) {
Sprite('titlebg').addChildTo(bgGroup)
.setPosition(this.gridX.center() + i * SCREEN_WIDTH, this.gridY.center())
.setSize(SCREEN_WIDTH, SCREEN_HEIGHT)
}, this);
// タイトル
Label({
text: '飛翔忍者',
fontSize: 64,
}).addChildTo(this).setPosition(this.gridX.center(), this.gridY.span(4));
Label({
text: "TOUCH START",
fontSize: 32,
}).addChildTo(this)
.setPosition(this.gridX.center(), this.gridY.span(12))
.tweener.fadeOut(1000).fadeIn(500).setLoop(true).play();
// 画面タッチ時
this.on('pointend', function() {
// 次のシーンへ
this.exit();
});
},
});
phina.define("MainScene", {
superClass: 'DisplayScene',
init() {
this.superInit();
Sprite('bg').addChildTo(this).setPosition(this.gridX.center(), this.gridY.center());
this.player = Sprite('player').setPosition(SCREEN_WIDTH / 2, 100).addChildTo(this);
this.player.width = 70;
this.player.height = 70;
this.enemyGroup = DisplayElement().addChildTo(this);
this.time = 0;
this.enemyspeed = 5;
this.point = 0;
this.coment = "";
},
update() {
if (this.time % 150 === 0) {
let position = Math.randint(-3, 3);
Enemy().setPosition(SCREEN_WIDTH / 2 + position * 70, SCREEN_HEIGHT).addChildTo(this.enemyGroup);
position = Math.randint(-3, 3);
Enemy().setPosition(SCREEN_WIDTH / 2 + position * 70, SCREEN_HEIGHT).addChildTo(this.enemyGroup);
position = Math.randint(-3, 3);
Enemy().setPosition(SCREEN_WIDTH / 2 + position * 70, SCREEN_HEIGHT).addChildTo(this.enemyGroup);
position = Math.randint(-3, 3);
Enemy().setPosition(SCREEN_WIDTH / 2 + position * 70, SCREEN_HEIGHT).addChildTo(this.enemyGroup);
}
this.enemyGroup.children.each((enemy) => {
enemy.y = enemy.y - this.enemyspeed;
if (enemy.hitTestElement(this.player)) {
this.exit({
backgroundColor: "#9400d3",
score: this.point,
message: this.coment
});
}
if (enemy.y < 0) {
enemy.remove();
this.enemyspeed = this.enemyspeed + 0.05;
this.point = this.point + 5;
if(this.point<100){
this.coment = "まだまだ飛べるはず"
}else if(this.point<200){
this.coment = "忍法鼫の術"
}else if(this.point<300){
this.coment = "I can fly!!"
}else{
this.coment = "ニンジャナンデ!!"
}
}
})
this.time++;
},
onpointstart(e) {
if (e.pointer.x > SCREEN_WIDTH / 2 && this.player.x < SCREEN_WIDTH / 2 + 200) {
this.player.x += 70;
} else if (e.pointer.x < SCREEN_WIDTH / 2 && this.player.x > SCREEN_WIDTH / 2 - 200) {
this.player.x -= 70;
}
}
});
phina.define('Enemy', {
superClass: 'Sprite',
init() {
this.superInit('enemy');
this.width = 70;
this.height = 70;
},
update() {}
});
phina.main(function() {
const app = GameApp({
fps: 60,
title: '飛翔忍者',
startLabel: 'title',
assets: ASSETS,
})
app.run();
});