/** * 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)); } }
/** thread run method that is called when the thread start method is called */ @Override public void run() { for (; k < vecSequence.size(); k++) { // set it to say its not in this thread so the user cannot click on the // progress bar at the perfect time and freeze the program in the waiting // cursor stage if (k == (vecSequence.size() - 1)) { theApp.setThreadStatus(false); theApp.setPlayPauseOff(); } if (((Component) theApp).getCursor().getType() == Cursor.WAIT_CURSOR) { int jpbIncrement = Math.round(1.0f * theApp.getBarMax() / vecSequence.size()); k = Math.round(theApp.getBarValue() / jpbIncrement); ((Component) theApp).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } AePlayWave thread = new AePlayWave(vecSequence.get(k)); theApp.incrementProgressBarValue(); thread.start(); // play the selected audio clip try { thread.join(); // wait for the thread playing to clip to die } catch (InterruptedException ie) { ((Component) theApp).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } if (theApp.playPausePressed()) { k = vecSequence.size(); } } if (!theApp.playPausePressed()) { theApp.setButtonsOutOfThread(); theApp.fillBarValue(); } }
// 构造函数 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)); }