/** * makes this jump * * @param pressed true if jump button is down * @param sound true if should play sound */ public void jump(boolean pressed, boolean sound) { if (dead) return; if (pressed) jumpDown = true; else jumpDown = false; if (cape) { if (pressed) { movingUp = true; acc.y = Wuigi.GRAVITY; jumping = true; } else { movingUp = false; jumping = false; acc.y = 0; } return; } if (pressed) { if (vel.y == 0) { vel.y = JUMP_VEL + Wuigi.GRAVITY; jumping = true; jumpAdd = Wuigi.COMPLETE_JUMP_TIME; if (sound) JUMP.start(); } } else { jumpAdd = -Wuigi.COMPLETE_JUMP_TIME; } }
/** shoots the AWP */ public void shootAWP(int x, int y) { if (numBullets > 0) { numBullets--; AWP.start(); shotTime = System.currentTimeMillis(); ammo.setText("" + numBullets); double awpx = pos.x + width / 2; double awpy = pos.y + height / 2; double mousex = x + this.pos.x - (Wuigi.screenWidth / 2.0 + xOffset()); double mousey = Wuigi.screenHeight + pos.y + 32 - (ScreenManager.mouse.y + yOffset()); addSpawn(new AWPBullet(awpx, awpy, mousex, mousey)); } }
// 构造函数 public MyPanel(String flag) { apw.start(); // 恢复记录 Recorder.getRecord(); // bombs.add(new Bomb(0,0)); // 括号里的是初始位置 myTank = new MyTank(100, 100); if (flag.equals("newGame")) { // 初始化敌方坦克 for (int i = 0; i < enemySize; i++) { // 创建一辆敌人的坦克 EnemyTank et = new EnemyTank((i + 1) * 50, 0); et.setColor(1); et.setDirect(2); // 將MyPanel的敵人坦克向量交給該敵人坦克 et.setEts(enemyTanks); // 启动敌人的坦克 Thread t = new Thread(et); t.start(); // 给敌人坦克添加一颗子弹 Bullet b = new Bullet(et.x + 10, et.y + 30, 2); // 加入敌人坦克 et.bb.add(b); Thread t2 = new Thread(b); t2.start(); // 加入 enemyTanks.add(et); } } else { nodes = new Recorder().getNodesAndEnNums(); // 初始化敌方坦克 for (int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); // 创建一辆敌人的坦克 EnemyTank et = new EnemyTank(node.x, node.y); et.setColor(1); et.setDirect(node.direct); // 將MyPanel的敵人坦克向量交給該敵人坦克 et.setEts(enemyTanks); // 启动敌人的坦克 Thread t = new Thread(et); t.start(); // 给敌人坦克添加一颗子弹 Bullet b = new Bullet(et.x + 10, et.y + 30, 2); // 加入敌人坦克 et.bb.add(b); Thread t2 = new Thread(b); t2.start(); // 加入 enemyTanks.add(et); } } // 初始化爆炸图片 // try { // image1= ImageIO.read(new File("/3.png")); // image2= ImageIO.read(new File("/2.png")); // image3= ImageIO.read(new File("/1.png")); // } catch (IOException e) { // e.printStackTrace(); // } image1 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/3.png")); image2 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/2.png")); image3 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/1.png")); bombs.add(new Bomb(0, 0)); }