質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

Q&A

解決済

2回答

2071閲覧

proseccing ゲームタイトルの付け方

miiso_soup

総合スコア7

Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

1グッド

0クリップ

投稿2020/01/08 22:28

このゲームの始まりに”press button to start”みたいなテキストを入れてゲームの進行をしたいのですが

int title(){ text("Game Title", width * 0.5, height * 0.3); text("Press button to start", width * 0.5, height * 0.7); if(keyPressed)

このような感じのコードを挿入したいです。しかしコードも不十分です。また入れる場所も分かりません。
いれるとしたらほかに必要な要素は何なのでしょうか。
教えてください。

Bullet bullet; private Boss boss = new Boss(75, 35); private ArrayList<Bullet> danmaku = new ArrayList<Bullet>(); float[] z = new float[500]; float[] y = new float[500]; void setup() { size(450, 600); frameRate(40); noCursor(); bullet = new Bullet(width/2, height/2, 10, 0, 0 ); for (int r = 0; r < z.length; r++) { z[r] = random(-1000,300); y[r] = random(height); } } void ship(int x, int y) {こ noStroke(); fill(255, 0, 0); ellipse(mouseX, mouseY, 7.5, 7.5); } class Boss { private int tx, ty; private int dx, dy; private long routine = 0; Boss(int x, int y) { tx = x; ty = y; dx = 1; dy = -5; } void move() { tx += dx; ty += dy; if (tx < 0 || tx > width) { dx*= -1; } if (ty < 0 || ty > height) { dy*= -1; } } void doShinking() { routine++; if (routine % 10 == 0) { move(); } if (routine % 30 == 0) { danmaku.addAll(this.shot()); println("#shot" +routine + ":" + tx + "," + ty); } } ArrayList<Bullet> shot() { ArrayList<Bullet> danmaku = new ArrayList(); for (int i = 0; i < 360; i+= 11.5) { double rad = radians(i); danmaku.add(new Bullet(this.tx, this.ty, 10, Math.cos(rad), Math.sin(rad))); } return danmaku; } } class Bullet { private double tx, ty; private final double tr; private double dx, dy; private boolean is_alive = true; Bullet(double x, double y, double r, double temp_dx, double temp_dy ) { tx = x; ty = y; tr = r; dx = temp_dx; dy = temp_dy; } boolean isAlive() { return is_alive; } void update() { tx += dx; ty += dy; if (Math.min(tx, ty) < 0) { is_alive = false; return ; } if (tx > width || ty > height) { is_alive = false; return ; } stroke(255, 0, 255); fill(0, 0, 255); ellipse((float)tx, (float)ty, (float)tr, (float)tr); } } void draw() { background(0); ship(mouseX, mouseY); boss.doShinking(); for (int i = danmaku.size() -1; i >= 0; i--) { Bullet b = (Bullet)danmaku.get(i); if (!b.isAlive()) { danmaku.remove(i); continue; } b.update(); } for (int r = 0; r < z.length; r++) { z[r] += 2; if(z[r] > width + 7.5){ z[r] = random(-1000,-10); y[r] = random(height); } stroke(255, 0, 255); fill(0,0,255); ellipse(z[r], y[r], 10, 10); } } ```ここに言語名を入力 ソースコード

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

int title() { }??
と思ったら Processing で状態遷移のあるゲーム・アプリを作る こちらのサイトですね?

引用にもなっていませんし、参考にするにしても参考サイトがあるのであれば明示してください。

確かにちょっと凝ったことをしているので、わかりにくくなっているかもしれませんね。
わかりやすいようにもっとシンプルに書き直してみました。

Processing

1Bullet bullet; 2Boss boss; 3ArrayList<Bullet> danmaku; 4float[] z; 5float[] y; 6 7int state; // 今の画面状態 8final int TITLE = 0; // タイトル画面 9final int GAME = 1; // ゲーム画面 10final int ENDING = 2; // ゲームオーバー画面 11 12void setup() { 13 size(450, 600); 14 frameRate(40); 15 noCursor(); 16 17 init(); // 各変数の初期化 18} 19 20// 各変数の初期化 21void init() { 22 boss = new Boss(75, 35); 23 danmaku = new ArrayList<Bullet>(); 24 bullet = new Bullet(width / 2, height / 2, 10, 0, 0 ); 25 z = new float[500]; 26 y = new float[500]; 27 28 for (int r = 0; r < z.length; r++) { 29 z[r] = random(-1000, 300); 30 y[r] = random(height); 31 } 32} 33 34void draw() { 35 if (state == TITLE) { // 今の画面状態がタイトル画面だったら。。。 36 title(); // タイトル画面の描画 37 } else if (state == GAME) { // 今の画面状態がゲーム画面だったら。。。 38 game(); // ゲーム画面の描画 39 } else if (state == ENDING) { // 今の画面状態がゲームオーバー画面だったら。。。 40 ending(); // ゲームオーバー画面の描画 41 } 42} 43 44// タイトル画面の描画 45void title() { 46 background(0); 47 fill(255); 48 textSize(24); 49 textAlign(CENTER); 50 text("Game Title", width * 0.5, height * 0.3); 51 text("Press any key to start", width * 0.5, height * 0.7); 52 if (keyPressed) { // 何かのキーが押されていれば。。。 53 state = GAME; // ゲーム画面に遷移 54 } 55} 56 57// ゲーム画面の描画 58void game() { 59 background(0); 60 ship(mouseX, mouseY); 61 boss.doShinking(); 62 63 for (int i = danmaku.size() -1; i >= 0; i--) { 64 Bullet b = (Bullet)danmaku.get(i); 65 if (!b.isAlive()) { 66 danmaku.remove(i); 67 continue; 68 } 69 b.update(); 70 } 71 72 for (int r = 0; r < z.length; r++) { 73 z[r] += 2; 74 if (z[r] > width + 7.5) { 75 z[r] = random(-1000, -10); 76 y[r] = random(height); 77 } 78 stroke(255, 0, 255); 79 fill(0, 0, 255); 80 ellipse(z[r], y[r], 10, 10); 81 } 82} 83 84// ゲームオーバー画面の描画 85void ending() { 86 fill(255); 87 textSize(24); 88 textAlign(CENTER); 89 text("try again?", width * 0.5, height * 0.3); 90 text("Press any key to restart", width * 0.5, height * 0.7); 91 if (keyPressed) { // 何かのキーが押されていれば。。。 92 state = GAME; // ゲーム画面に遷移 93 init(); // 各変数の初期化 94 } 95} 96 97void ship(int x, int y) { 98 noStroke(); 99 fill(255, 0, 0); 100 ellipse(mouseX, mouseY, 7.5, 7.5); 101} 102 103// 以下各classは変更無いので省略

投稿2020/01/09 15:03

TN8001

総合スコア9326

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

miiso_soup

2020/01/10 06:06

ご指摘ありがとうございます。 しかもとても親切に書き直していただけるなんて。 これを見て少し勉強します。 ありがとうございました。 引用の件は気を付けます。
guest

0

見りゃだいたいわかると思うけど。

Processing

1boolean isTitle=true;//タイトル表示中かどうか? 2 3final int R=50; 4final int DX=2; 5final int DY=1; 6int x,y; 7int dx=2; 8int dy=1; 9 10void setup() { 11 size(640, 480); 12 x=width/2; 13 y=height/2; 14 textAlign(CENTER,TOP); 15} 16 17void title() { 18 text("Game Title", width * 0.5, height * 0.3); 19 text("Press button to start", width * 0.5, height * 0.7); 20} 21 22void draw() { 23 if(isTitle){ //タイトル表示状態だったら 24 background(32,32,64); 25 title();//タイトル表示して 26 if(keyPressed){//キー検査して 27 isTitle=false;//押されてたら次回以降はここに来ない 28 } 29 return;//さっさと抜けちゃう 30 } 31 //本番処理 32 background(204); 33 circle(x,y,R); 34 x+=dx; 35 y+=dy; 36 if(x<R/2){ 37 x=10; 38 dx=DX; 39 }else if(x>width-R/2){ 40 x=width-R/2; 41 dx=-DX; 42 } 43 if(y<R/2){ 44 y=R/2; 45 dy=DY; 46 }else if(y>height-R/2){ 47 y=height-R/2; 48 dy=-DY; 49 } 50}

投稿2020/01/09 13:39

thkana

総合スコア7652

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問