2012-02-24 3 views
0

私はブロック/壁の検出に問題がある:私のキャラクターはブロックの近くにどのように残っていますか?

enter image description here

赤=文字

緑=ブロック/壁

試み:私のキャラクターは、例えば触れます左側にはブロック/壁があり、左側にあるべきです。

int len = blocks.size(); 

for (int b = 0; b < len; b++) { 

    Block block = block.get(i); 

    Rectangle r1 = red.bounds; 
    Rectangle r2 = block.bounds; 

    if((r1.lowerLeft.y + r1.height/2) > (r2.lowerLeft.y - r2.height/2)) { 
    ... 
    } 

    if((r1.lowerLeft.y - r1.height/2) < (r2.lowerLeft.y + r2.height/2)) { 
    ... 
    } 

    if((r1.lowerLeft.x + r1.width/2) > (r2.lowerLeft.x - r2.width/2)) { 
    ... 
    } 

    if((r1.lowerLeft.x - r1.width/2) < (r2.lowerLeft.x + r2.width/2)) { 
    ... 
    } 
} 

答えて

0

あなただけのコードを付き合うために持っていたかのように思えます。 あなたがトップにいるかどうかを調べる条件は、それが底にあった場合に何が行われなければならなかったかを計算します。条件の中でコードを交換するだけで、あなたは行こうとしていますね。

関連する問題