⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bomberplayer.java

📁 Clan Bomber Java game using Swings v1.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                canMove = false;
                if (currentDirKeyDown > 0) {
                    if ((currentDirKeyDown & BLEFT) > 0) {
                        state = LEFT;
                        canMove = (x % size != 0 || 
			(y % size == 0 && (map.grid[(x >> shiftCount) - 1][y >> shiftCount] <= BomberMap.NOTHING)) ||
			((map.grid[(x >> shiftCount) - 1][y >> shiftCount] <= BomberMap.NOTHING) && 
			 (map.grid[(x >> shiftCount) - 1][(y >> shiftCount) +1] <= BomberMap.NOTHING)));

                        if (!canMove) {
                            int oy = 0;
                            for (oy = -offset; oy < 0; oy += (size / 4)) {
                                if ((y + oy) % size == 0 &&
                                map.grid[(x >> shiftCount) - 1]
                                [(y + oy) >> shiftCount] <= BomberMap.NOTHING) {
                                    canMove = true; break;
                                }
                            }
                            if (!canMove) {
                                for (oy = (size / 4); oy <= offset;
                                oy += (size / 4)) {
                                    if ((y + oy) % size == 0 &&
                                    map.grid[(x >> shiftCount) - 1]
                                    [(y + oy) >> shiftCount]
                                    <= BomberMap.NOTHING) {
                                        canMove = true; break;
                                    }
                                }
                            }
                            if (canMove) {
                                clear = true; game.paintImmediately(x,
                                y - halfSize, width, height);
                                y += oy;
                                clear = false; game.paintImmediately(x,
                                y - halfSize, width, height);
                            }
                        }
                        if (canMove) {
                            clear = true; game.paintImmediately(x,
                            y - halfSize, width, height);
                            x -= (size / 4);
                            clear = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                        else {
                            moving = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                    }
                    else if ((currentDirKeyDown & BRIGHT) > 0) {
                        state = RIGHT;
                        canMove = false;
                        canMove = (x % size != 0 || 
			(y % size == 0 && (map.grid[(x >> shiftCount) + 1][y >> shiftCount] <= BomberMap.NOTHING)) ||
			((map.grid[(x >> shiftCount) + 1][y >> shiftCount] <= BomberMap.NOTHING) &&
			 (map.grid[(x >> shiftCount) + 1][(y >> shiftCount)+1] <= BomberMap.NOTHING)));
                        if (!canMove) {
                            int oy = 0;
                            for (oy = -offset; oy < 0; oy += (size / 4)) {
                                if ((y + oy) % size == 0 &&
                                map.grid[(x >> shiftCount) + 1]
                                [(y + oy) >> shiftCount] <= BomberMap.NOTHING) {
                                    canMove = true; break;
                                }
                            }
                            if (!canMove) {
                                for (oy = (size / 4); oy <= offset;
                                oy += (size / 4)) {
                                    if ((y + oy) % size == 0 &&
                                    map.grid[(x >> shiftCount) + 1]
                                    [(y + oy) >> shiftCount]
                                    <= BomberMap.NOTHING) {
                                        canMove = true; break;
                                    }
                                }
                            }
                            if (canMove) {
                                clear = true; game.paintImmediately(x,
                                y - halfSize, width, height);
                                y += oy;
                                clear = false; game.paintImmediately(x,
                                y - halfSize, width, height);
                            }
                        }
                        if (canMove) {
                            clear = true; game.paintImmediately(x,
                            y - halfSize, width, height);
                            x += (size / 4);
                            clear = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                        else {
                            moving = false;
                            game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                    }
                    else if ((currentDirKeyDown & BUP) > 0) {
                        state = UP;
                        canMove = false;
                        canMove = (y % size != 0 || 
			(x % size == 0 && (map.grid[x >> shiftCount][(y >> shiftCount) - 1] <= BomberMap.NOTHING)) ||
			((map.grid[x >> shiftCount][(y >> shiftCount) - 1] <= BomberMap.NOTHING) &&
			 (map.grid[(x >> shiftCount)+1][(y >> shiftCount) - 1] <= BomberMap.NOTHING)));

                        if (!canMove) {
                            int ox = 0;
                            for (ox = -offset; ox < 0; ox += (size / 4)) {
                                if ((x + ox) % size == 0 &&
                                map.grid[(x + ox) >> shiftCount]
                                [(y >> shiftCount) - 1] <= BomberMap.NOTHING) {
                                    canMove = true; break;
                                }
                            }
                            if (!canMove) {
                                for (ox = (size / 4); ox <= offset; ox += (size / 4)) {
                                    if ((x + ox) % size == 0 &&
                                    map.grid[(x + ox) >> shiftCount]
                                    [(y >> shiftCount) - 1]
                                    <= BomberMap.NOTHING) {
                                        canMove = true; break;
                                    }
                                }
                            }
                            if (canMove) {
                                clear = true; game.paintImmediately(x,
                                y - halfSize, width, height);
                                x += ox;
                                clear = false; game.paintImmediately(x,
                                y - halfSize, width, height);
                            }
                        }
                        if (canMove) {
                            clear = true; game.paintImmediately(x,
                            y - halfSize, width, height);
                            y -= (size / 4);
                            clear = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                        else {
                            moving = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                    }
                    else if ((currentDirKeyDown & BDOWN) > 0)
                    {
                        state = DOWN;
                        canMove = false;
                        canMove = (y % size != 0 || 
			(x % size == 0 && (map.grid[x >> shiftCount][(y >> shiftCount) + 1]<= BomberMap.NOTHING)) ||
			((map.grid[x >> shiftCount][(y >> shiftCount) + 1]<= BomberMap.NOTHING) &&
			 (map.grid[(x >> shiftCount)+1][(y >> shiftCount) + 1]<= BomberMap.NOTHING)));

                        if (!canMove) {
                            int ox = 0;
                            for (ox = -offset; ox < 0; ox += (size / 4)) {
                                if ((x + ox) % size == 0 &&
                                map.grid[(x + ox) >> shiftCount]
                                [(y >> shiftCount) + 1] <= BomberMap.NOTHING) {
                                    canMove = true; break;
                                }
                            }
                            if (!canMove) {
                                for (ox = (size / 4); ox <= offset;
                                ox += (size / 4)) {
                                    if ((x + ox) % size == 0 &&
                                    map.grid[(x + ox) >> shiftCount]
                                    [(y >> shiftCount) + 1]
                                    <= BomberMap.NOTHING) {
                                        canMove = true; break;
                                    }
                                }
                            }
                            if (canMove) {
                                clear = true; game.paintImmediately(x,
                                y - halfSize, width, height);
                                x += ox;
                                clear = false; game.paintImmediately(x,
                                y - halfSize, width, height);
                            }
                        }
                        if (canMove) {
                            clear = true; game.paintImmediately(x,
                            y - halfSize, width, height);
                            y += (size / 4);
                            clear = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                        else {
                            moving = false; game.paintImmediately(x,
                            y - halfSize, width, height);
                        }
                    }
                }
            }
            else if (!isExploding && !isDead && lastState != currentDirKeyDown)
            {
                frame = 0;
                moving = false;
                game.paintImmediately(x, y - halfSize, width, height);
                lastState = currentDirKeyDown;
            }
            else if (!isDead && isExploding)
            {
                if (frame >= 2) isDead = true;
                game.paintImmediately(x, y - halfSize, width, height);
                frame = (frame + 1) % 3;
            }
            else if (isDead)
            {
                clear = true;
                game.paintImmediately(x, y - halfSize, width, height);
                break;
            }
            if (map.bonusGrid[x >> shiftCount][y >> shiftCount] != null)
               { bx = x; by = y; }
            else if (map.bonusGrid[x >> shiftCount][(y + halfSize)
                 >> shiftCount] != null) { bx = x; by = y + halfSize; }
            else if (map.bonusGrid[(x + halfSize) >> shiftCount][y
                 >> shiftCount] != null) { bx = x + halfSize; by = y; }
            if (bx != 0 && by != 0) {
                map.bonusGrid[bx >> shiftCount][by >>
                shiftCount].giveToPlayer(playerNo);
                bx = by = 0;
            }
            if (isDead) break;
            try { sleep(65); } catch (Exception e) { }
        }
        interrupt();
    }

    public void paint(Graphics graphics)
    {
        Graphics g = graphics;
        paint2D(graphics); 
    }

    public void paint2D(Graphics graphics) {
        Graphics2D g2 = (Graphics2D)graphics;
        g2.setRenderingHints((RenderingHints)hints);
        if (!isDead && !clear)
        {
            if (moving)
               g2.drawImage(sprites[playerNo - 1][state][frame],
               x, y - (BomberMain.size / 2), width, height, null);
            else
                g2.drawImage(sprites[playerNo - 1][state][0],
                x, y - (BomberMain.size / 2), width, height, null);
        }
    }
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -