左の面からランダムに玉を飛ばすようにプログラムを組もうとしたのですが
一点からランダムに出現するだけになってしまいます。
その理由がイマイチ分かりません。
今のコードでは左面のランダムな地点からでなく、ただのランダムに出現するのみになってしまっているのでしょうか。
Ý座標の面からのランダム出現の方法が分かりません。
どなたかわかる人がおりましたらよろしくお願いします。
Java
1Bullet bullet; 2private Boss boss = new Boss(75, 35); 3private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); 4 5float[] z = new float[500]; 6 7void setup() { 8 size(420, 580); 9 10 frameRate(40); 11 12 noCursor(); 13 14 bullet = new Bullet(width/2, height/2, 10, 0, 0 ); 15 16 for (int r = 0; r < z.length; r++) { 17 z[r] = random(-1000,300); 18 } 19} 20 21void ship(int x, int y) { 22 23 noStroke(); 24 25 fill(255, 0, 0); 26 27 ellipse(mouseX, mouseY, 7.5, 7.5); 28} 29 30 31 32class Boss { 33 private int tx, ty; 34 private int dx, dy; 35 private long routine = 0; 36 Boss(int x, int y) { 37 tx = x; 38 ty = y; 39 dx = 1; 40 dy = -5; 41 } 42 void move() { 43 tx += dx; 44 ty += dy; 45 if (tx < 0 || tx > width) { 46 dx*= -1; 47 } 48 if (ty < 0 || ty > height) { 49 dy*= -1; 50 } 51 } 52 void doShinking() { 53 routine++; 54 if (routine % 10 == 0) { 55 move(); 56 } 57 if (routine % 30 == 0) { 58 danmaku.addAll(this.shot()); 59 println("#shot" +routine + ":" + tx + "," + ty); 60 } 61 } 62 ArrayList<Bullet> shot() { 63 ArrayList<Bullet> danmaku = new ArrayList(); 64 for (int i = 0; i < 360; i+= 11.5) { 65 double rad = radians(i); 66 danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); 67 } 68 return danmaku; 69 } 70} 71 72class Bullet { 73 74 private double tx, ty; 75 private final double tr; 76 private double dx, dy; 77 private boolean is_alive = true; 78 Bullet(double x, double y, double r, double temp_dx, double temp_dy ) { 79 tx = x; 80 ty = y; 81 tr = r; 82 dx = temp_dx; 83 dy = temp_dy; 84 } 85 boolean isAlive() { 86 return is_alive; 87 } 88 void update() { 89 tx += dx; 90 ty += dy; 91 if (Math.min(tx, ty) < 0) { 92 is_alive = false; 93 return ; 94 } 95 if (tx > width || ty > height) { 96 is_alive = false; 97 return ; 98 } 99 stroke(255, 0, 255); 100 101 fill(0, 0, 255); 102 103 ellipse((float)tx, (float)ty, (float)tr, (float)tr); 104 } 105} 106 107 108 109void draw() { 110 background(0); 111 for (int r = 0; r < z.length; r++) { 112 z[r] += 2; 113 float y = r * 0.5; 114 ellipse(z[r], width, 10, 10); 115 if(width >420 116 } 117 118 ship(mouseX, mouseY); 119 boss.doShinking(); 120 121 for (int i = danmaku.size() -1; i >= 0; i--) { 122 Bullet b = (Bullet)danmaku.get(i); 123 if (!b.isAlive()) { 124 danmaku.remove(i); 125 continue; 126 } 127 b.update(); 128 } 129 130 for (int r = 0; r < z.length; r++) { 131 z[r] += 2; 132 float y = r * 0.5; 133 ellipse(z[r], width, 10, 10); 134 } 135}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/08 20:55
2020/01/08 20:58
退会済みユーザー
2020/01/08 21:42