游戏开发论坛

 找回密码
 立即注册
搜索
查看: 7499|回复: 0

请高手指点 俄罗斯方块java代码中碰撞检测为什么左右有

[复制链接]

1

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2012-7-25 19:52:00 | 显示全部楼层 |阅读模式
                   方向操作函数:  
                      private void down() {
                        // TODO Auto-generated method stub
                        if (!isClied(x, y + 1)) {
                                y++;
                        } else {
                                add();
                                delete();
                                newBlock();
                        }
                        repaint();
                }

                private void right() {
                        // TODO Auto-generated method stub
                        if (!isClied(x + 1, y)) {
                                x++;
                        }               
                        repaint();
                }

                private void left() {
                        // TODO Auto-generated method stub
                        if (!isClied(x - 1, y)) {
                                x--;
                        }
                        repaint();
                }
               向下检测到碰撞后的添加函数:
                      public void add() {
                        int i = 0;
                        for (int a = 0; a < 4; a++) {
                                for (int b = 0; b < 4; b++) {
                                        if (map[x + 1 + b][y + a] == 0) {
                                                map[x + 1 + b][y + a] = shapes[blockType][turnState];
                                        }
                                        i++;
                                }
                        }
                }
               检测函数:  
                      public Boolean isClied( int x,  int y) {
                        for (int a = 0; a < 4; a++) {
                                for (int b = 0; b < 4; b++) {
                                        if ((shapes[blockType][turnState][a * 4 + b] == 1)
                                                        && (map[x + 1 + b][y * a]) == 1) {
                                                return true;
                                        } else if ((shapes[blockType][turnState][a * 4 + b] == 1)
                                                        && (map[x + 1 + b][y * a] == 2)) {
                                                return true;
                                        }
                                }
                        }
                        return false;

                }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-2-27 23:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表