2ch勢いランキング 全部 1- 最新50

プログラミング詳しい人至急来てー


名無しさん@お腹いっぱい。 [] 2020/12/13(日) 16:11:23.66:xqL/25cc0
制作でパズルゲーム作れって言われたからパズドラしか思い浮かばなくて、マウス操作で配列に入れた画像を動かして3つ揃ったら消えるみたいなパズドラ超簡易版を作ってたんだけど、マウス操作で詰んだので助けて欲しい。

教師に聞いたら、ただの配列で作ってんのにArrayListで書かれたマウス操作のサンプルを持ってこられて書き換えようとしたけどよくわからなくなった。
名無しさん@お腹いっぱい。 [] 2020/12/13(日) 16:13:50.09:xqL/25cc0
以下コード

PImage[] img;
Card[][] c;
boolean f;
int t, dt, n;

void setup() {
size( 500, 600 );

img = new PImage[] { loadImage( "heart.jpg" ),
loadImage( "triangle.jpg" ),
loadImage( "clober.jpg" ),
loadImage( "diamond.jpg" ),
loadImage( "spead.jpg" ),
loadImage( "moon.jpg" ) };

c = new Card[ 5 ][ 6 ];
for( int row = 0; row < c.length; row++ ) {
for( int col = 0; col < c[ row ].length; col++ ) {

c[ row ][ col ] = new Card( img[ int( random( 0, 5 ) ) ], col * 60 + 100, row * 60 + height / 2, 60, 60 );


while( col >= 1 && ( c[ row ][ col ].getImage() == c[ row ][ col - 1 ].getImage() ) )
c[ row ][ col ].setImage( img[ int( random( 0, 5 ) ) ] );


while( row >= 1 && c[ row ][ col ].getImage() == c[ row - 1 ][ col ].getImage() )
c[ row ][ col ].setImage( img[ int( random( 0, 5 ) ) ] );

}
}
}

void draw() {
background( 0 );


for( Card[] row : c )
for( Card col : row )
col.show();
名無しさん@お腹いっぱい。 [] 2020/12/13(日) 16:14:23.62:xqL/25cc0
//Card Class

class Card {
PImage img;
int x, y, w, h;

Card( PImage img, int x, int y, int w, int h ) {
this.img = img; this.x = x; this.y = y; this.w = w; this.h = h;
}

void setImage( PImage img ) { this.img = img; }

PImage getImage() { return this.img; }
int getX() { return this.x; }
int getY() { return this.y; }

void show() { image( this.img, this.x - w / 2, this.y - h / 2, w, h ); }
}
名無しさん@お腹いっぱい。 [] 2020/12/13(日) 16:16:28.94:xqL/25cc0
先生がサンプルに持ってきたArrayListになってるマウス操作コード↓

for( Card cc : c )
if( dist( mouseX, mouseY, cc.getP().x, cc.getP().y ) < 50 )
n = cc.getID();

if( mousePressed ) c.get( n ).setP( new PVector( mouseX, mouseY ) );
for( Card cc : c ) cc.show();

for( int j = 0; j < c.size() - 1; j++ )
for( int i = j + 1; i < c.size(); i++ )
if( ! f && dist( c.get( j ).getP().x, c.get( j ).getP().y, c.get( i ).getP().x, c.get( i ).getP().y ) < 50 ) {
PImage tmp = c.get( j ).getImage();
c.get( j ).setImage( c.get( i ).getImage() );
c.get( i ).setImage( tmp );
dt = 1; f = true;
}

t += dt;
if( t >= frameRate * 2 ) { t = dt = 0; f = false; }
}

void mousePressed() {}
void mouseReleased() { t = dt = 0; f = false; }

これどうしたらよいのかな、サンプルコードガン無視するべきなのかな?

勢い5万以上のスレをメールでお知らせするサービス、実施中!!
憧れボディをGETしたい!その夢、ボニックで!

2ch勢いランキング 全部 1- 最新50 情報学板ランキング

凡例:

レス番

100 (赤) → 2つ以上レスが付いている
100 (紫) → 1つ以上レスが付いている

名前

名無しさん (青) → sage のレス
名無しさん (緑) → age のレス

ID

ID:xxxxxxx (赤) → 発言が3つ以上のID
ID:xxxxxxx (青) → 発言が2つ以上のID

このページは2ch勢いランキングが作成したキャッシュです。元のページはこちら。削除についてはこちら