質問するログイン新規登録

質問編集履歴

1

いろいろ

2021/01/15 07:09

投稿

mothi5656
mothi5656

スコア27

title CHANGED
File without changes
body CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  ```ここに言語名を入力
16
16
  ソースコード
17
+
17
18
  float X=0.0;
18
19
  int count=0;
19
20
 
@@ -21,6 +22,8 @@
21
22
  int[]meteo_y=new int[50];
22
23
  int[]meteo_speed=new int[50];
23
24
 
25
+ int time=0;
26
+
24
27
  void setup() {
25
28
  size(500, 750);
26
29
  rectMode(CENTER);
@@ -34,6 +37,10 @@
34
37
 
35
38
  void draw() {
36
39
  background(0);
40
+ textSize(40);
41
+ time=millis()/1000;
42
+ text(time, 40, 50);
43
+
37
44
  meteo();
38
45
  stroke(255);
39
46
  rect(250+X, 700, 20, 20);//自機
@@ -41,8 +48,8 @@
41
48
 
42
49
  void meteo() {
43
50
  int i;
44
- stroke(255);
45
51
  for (i=0; i<50; i++) {
52
+ stroke(255);
46
53
  ellipse(meteo_x[i], meteo_y[i], 15, 15);//隕石は円で表現
47
54
  meteo_y[i]=meteo_y[i]+ meteo_speed[i];//隕石は上から下に移動
48
55
 
@@ -50,23 +57,34 @@
50
57
  meteo_x[i]=int(random(width));
51
58
  meteo_y[i]=0;
52
59
  meteo_speed[i]=int(random(2, 7));
60
+ } else if (240+X<meteo_x[i] && meteo_x[i]<260+X && 690<meteo_y[i]&&meteo_y[i]<710) {//隕石の中心座標が自機の中に入ったらゲームオーバー
61
+ background(255);
62
+ textSize(70);
63
+ fill(0);
64
+ text("Game Over", 70, 350);
65
+ textSize(50);
66
+ text("Score :",100,440);
67
+ text(time,300,440);
68
+ text("s",340,440);
69
+ textSize(30);
70
+ text("Please press 'ENTER'", 100, 500);
71
+ noLoop();
53
72
  }
54
73
  }
55
-
56
- if (240+X<meteo_x[i] && meteo_x[i]<260+X && 690<meteo_y[i]&&meteo_y[i]<710) {//隕石の中心座標が正方形の中に入った時にゲームオーバーとしたい
57
- text("Game Over", 200, 350);
58
- }
59
74
  }
60
75
 
61
76
 
62
77
  void keyPressed() {
63
- if (keyCode==RIGHT) {
78
+ if (keyCode==RIGHT) {//自機を右に移動
64
79
  X=X+10;
65
- } else if (keyCode==LEFT) {
80
+ } else if (keyCode==LEFT) {//自機を左に移動
66
81
  X=X-10;
82
+ } else if (keyCode==ENTER) {//ENTERキーを押してゲーム終了
83
+ exit();
67
84
  }
68
85
  }
69
86
 
87
+
70
88
  ```
71
89
 
72
90
  ### 試したこと