示例#1
0
  public boolean saveGame(String map) {
    Player p = m_game.getPlayer();
    GameConfig cfg = new GameConfig();
    cfg.put("tag", "GameSaveFile");
    cfg.put("x", (int) p.getX());
    cfg.put("y", (int) p.getY());
    cfg.put("name", p.getName());
    cfg.put("map", map);
    cfg.put("hp", p.HP);
    cfg.put("face", p.getFace());
    cfg.put("playtime", (int) m_game.getPlayTime());
    cfg.put("cansword", p.items[Player.ITEM_SWORD] != null);
    cfg.put("canshoot", p.items[Player.ITEM_RING] != null);
    cfg.put("canbomb", p.items[Player.ITEM_BOMB] != null);
    if (p.canShoot()) cfg.put("ring.num", p.items[Player.ITEM_RING].getCount());
    if (p.canBomb()) cfg.put("bomb.num", p.items[Player.ITEM_BOMB].getCount());
    if (p.curItem == p.items[Player.ITEM_SWORD]) cfg.put("curitem", "sword");
    else if (p.curItem == p.items[Player.ITEM_RING]) cfg.put("curitem", "ring");
    else if (p.curItem == p.items[Player.ITEM_BOMB]) cfg.put("curitem", "bomb");

    for (int i = 0; i < 256; i++) {
      if (p.hasKey[i]) cfg.put("key" + i, p.hasKey[i]);
      if (p.openedDoor[i]) cfg.put("door" + i, p.openedDoor[i]);
    }
    if (cfg.save(m_name + FILEDIR) == false) return false;
    cfg.reset();
    java.util.Map<String, String> vars = AbstractScript.getVars();
    Object[] keys = (vars.keySet().toArray());
    for (int i = 0; i < keys.length; i++) {
      cfg.put((String) keys[i], vars.get(keys[i]));
    }
    return cfg.save(m_name + FILEVARSDIR);
  }
示例#2
0
  @Override
  public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    screenX = scaleX(screenX);
    screenY = scaleY(screenY);

    if (world.isMenu()) {
      if (playButton.isTouchUp(screenX, screenY)) {
        world.restart();
        world.setRunning();
        return true;
      } else if (sfxButton.isTouchUp(screenX, screenY)) {
        if (AssetLoader.getSfx()) {
          sfxButton.setSwitchOn(false);
          AssetLoader.setSfx(false);
        } else {
          sfxButton.setSwitchOn(true);
          AssetLoader.setSfx(true);
        }

        return true;
      }
    }

    return false;
  }
示例#3
0
  public GameRenderer(GameWorld gameworld) {
    this.planetmap = gameworld.getPlanetmap();
    this.currentCamera = gameworld.getCurrentCamera();

    this.uiItems = gameworld.getUiItems();

    fpsLog = new FPSLogger();
    // GLProfiler.enable();
  }
示例#4
0
文件: Ufarm.java 项目: Monezz/ufarm
  @Override
  public void start(Stage primaryStage) {
    // setup title, scene, stats, controls, and actors.
    gameWorld.initialize(primaryStage);

    // kick off the game loop
    gameWorld.beginGameLoop();

    // display window
    primaryStage.show();
  }
示例#5
0
  public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    gridView.render();

    if (world.isWin()) {
      batch.begin();
      font.draw(batch, world.getWinMessage(), 40, X0Game.HEIGHT / 2);
      batch.end();
    }
  }
示例#6
0
 public void mouseReleased(MouseEvent arg0) {
   if (SwingUtilities.isRightMouseButton(arg0)) {
     if (selecting) {
       gameData.unselectAll();
       gameData.selectAt(
           new Rectangle(
               startPoint.x,
               currentPoint.y,
               currentPoint.x - startPoint.x,
               startPoint.y - currentPoint.y));
       selecting = false;
       repaint();
     }
   }
 }
示例#7
0
  public void updateSpiral() {
    if (mTicks % 2 != 0 || ((mTicks / 80) % 2 == 0)) {
      return;
    }

    mWorld.addBullet(
        new SpiralBullet(
            (int) mEntity.mPosition.X + mEntity.getWidth() / 2, (int) mEntity.mPosition.Y, mWorld));
  }
示例#8
0
 public GameRender(GameWorld world) {
   this.game = X0Game.getInstance();
   this.world = world;
   camera = new OrthographicCamera();
   camera.setToOrtho(false, X0Game.WIDTH, X0Game.HEIGHT);
   shapeRenderer = new ShapeRenderer();
   shapeRenderer.setProjectionMatrix(camera.combined);
   gridView = new GridView(world.getGrid(), shapeRenderer);
   batch = new SpriteBatch();
   font = new BitmapFont();
   winDialog = new Dialog("You win!", game.getSkin());
 }
示例#9
0
 public void mouseClicked(MouseEvent arg0) {
   if (SwingUtilities.isLeftMouseButton(arg0)) {
     try {
       Point worldPoint = getWorldPoint(arg0.getPoint());
       gameData.selectAt(worldPoint);
       repaint();
     } catch (NoninvertibleTransformException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
示例#10
0
 /** 开启游戏 */
 public void startGame(MyIO io) {
   if (io.isApplet() == false) {
     try {
       setCursor(
           Toolkit.getDefaultToolkit()
               .createCustomCursor(
                   Toolkit.getDefaultToolkit().getImage(""), new Point(0, 0), "invisible"));
     } catch (Exception e) {
     }
   }
   m_game = new GameWorld(this, io);
   m_game.start();
 }
示例#11
0
  public void updateBeam() {
    if (mTicks % 4 != 0 || ((mTicks / 40) % 2 == 0)) {
      return;
    }

    int xf = (int) mWorld.getPlayer().mPosition.X;
    int yf = (int) mWorld.getPlayer().mPosition.Y;

    float tmp = (yf - mEntity.mPosition.Y) / 5;
    tmp = tmp == 0 ? 1 : tmp;

    int xv = Math.min((int) ((xf - mEntity.mPosition.X) / tmp), 20);

    mWorld.addBullet(
        new Bullet(
            (int) mEntity.mPosition.X + mEntity.getWidth() / 2,
            (int) mEntity.mPosition.Y,
            xv,
            10,
            true,
            mWorld));
  }
示例#12
0
 public void drawSelectIcon(Graphics2D g2d, int x, int y, boolean selected) {
   if (m_sicon == null) {
     g2d.setColor(Color.blue);
     g2d.drawRect(x, y, 32, 32);
     g2d.setColor(Color.yellow);
     if (selected) {
       g2d.fillRect(x + 1, y + 1, 30, 30);
     } else {
       g2d.fillRect(x, y, 32, 32);
     }
   } else {
     if (!selected) {
       Composite oldac = g2d.getComposite();
       AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
       g2d.setComposite(ac);
       g2d.drawImage(m_sicon, x, y, m_game.getPanel());
       g2d.setComposite(oldac);
     } else {
       g2d.drawImage(m_sicon, x, y, m_game.getPanel());
     }
   }
 }
示例#13
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (gameData == null) return;

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform previousTransform = g2d.getTransform();

    g2d.transform(getVTM());

    double visibleWorldY = gameData.getLanderPosition().getY().doubleValue() * 1.33;
    double zoomFactor = (double) getHeight() / visibleWorldY;

    if (zoomFactor < 1) {
      g2d.translate(
          -(gameData.getLanderPosition().getX().intValue() * zoomFactor - (getWidth() / 2)), 0);
      g2d.scale(zoomFactor, zoomFactor);
    } else {
      g2d.translate(-(gameData.getLanderPosition().getX().intValue() - (getWidth() / 2)), 0);
    }

    for (GameObject gameObj : gameData.getGameObjects()) {
      gameObj.draw(g2d);
    }

    currentAT = g2d.getTransform();
    g2d.setTransform(previousTransform);

    if (selecting) {
      Color save = g.getColor();
      g.setColor(Color.yellow);
      g.drawRect(
          startScreenPoint.x,
          startScreenPoint.y,
          currentScreenPoint.x - startScreenPoint.x,
          currentScreenPoint.y - startScreenPoint.y);
      g.setColor(save);
    }
  }
  @Override
  protected void initialize() {
    window.requestFocusInWindow();

    // Replace the default keyboard input with DyehardKeyboard
    window.removeKeyListener(keyboard);
    keyboard = new DyehardKeyboard();
    window.addKeyListener(keyboard);

    window.addMouseListener(mouse);

    resources.setClassInJar(this);

    state = State.BEGIN;
    GameState.TargetDistance = Configuration.worldMapLength;
    world = new GameWorld();

    // preload sound/music, and play bg music
    DyeHardSound.playBgMusic();

    hero = new Hero();

    // move mouse to where center of hero is
    try {
      Robot robot = new Robot();

      robot.mouseMove(
          window.getLocationOnScreen().x
              + (int) (hero.center.getX() * window.getWidth() / BaseCode.world.getWidth()),
          window.getLocationOnScreen().y
              + window.getHeight()
              - (int) (hero.center.getX() * window.getWidth() / BaseCode.world.getWidth()));
    } catch (AWTException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    // hero.registerWeapon(new SpreadFireWeapon(hero));
    // hero.registerWeapon(new OverHeatWeapon(hero));
    // hero.registerWeapon(new LimitedAmmoWeapon(hero));

    world.initialize(hero);

    new DeveloperControls(hero);

    Stargate.addColor(Colors.Yellow);

    timer = new Timer(2000);
  }
示例#15
0
  @Override
  public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    screenX = scaleX(screenX);
    screenY = scaleY(screenY);

    if (world.isMenu()) {
      playButton.isTouchDown(screenX, screenY);
      sfxButton.isTouchDown(screenX, screenY);
    }

    if (world.isRunning()) {
      for (int i = 0; i < world.getBombColumns(); i++) { // do columns
        for (int j = 0; j < world.getBombRows(); j++) { // do rows

          // check if touched a bomb
          if (bombs[i][j].getBomb().contains(screenX, screenY)) {
            bombs[i][j].onClick();
          }
        }
      }
    }

    return true;
  }
示例#16
0
  public void updateRadial() {
    if (mTicks % 4 != 0 || ((mTicks / 120) % 2 == 0)) {
      return;
    }

    int xv = (int) (MathHelper.cos(mTicks * 5) * 10);
    int yv = (int) (MathHelper.sin(mTicks * 5) * 10);

    mWorld.addBullet(
        new Bullet(
            (int) mEntity.mPosition.X + mEntity.getWidth() / 2,
            (int) mEntity.mPosition.Y,
            xv,
            yv,
            true,
            mWorld));
  }
示例#17
0
  public void updateCircle() {
    if (mTicks % 300 != 0) {
      return;
    }
    for (int i = 0; i < 89; ++i) {
      int xv = (int) (MathHelper.cos(i * 4) * 10);
      int yv = (int) (MathHelper.sin(i * 4) * 10);

      mWorld.addBullet(
          new Bullet(
              (int) mEntity.mPosition.X + mEntity.getWidth() / 2,
              (int) mEntity.mPosition.Y,
              xv,
              yv,
              true,
              mWorld));
    }
  }
示例#18
0
  public void updateSpokes() {
    if (mTicks % 3 != 0 || ((mTicks / 60) % 2 == 0)) {
      return;
    }

    for (int i = 1; i <= 3; ++i) {
      int xv = (int) (MathHelper.cos(mTicks * 4 + 120 * i) * 10);
      int yv = (int) (MathHelper.sin(mTicks * 4 + 120 * i) * 10);

      mWorld.addBullet(
          new Bullet(
              (int) mEntity.mPosition.X + mEntity.getWidth() / 2,
              (int) mEntity.mPosition.Y,
              xv,
              yv,
              true,
              mWorld));
    }
  }
示例#19
0
  public InputHandler(GameWorld world, float scaleFactorX, float scaleFactorY) {
    this.world = world;

    bombs = world.getBombs();

    this.scaleFactorX = scaleFactorX;
    this.scaleFactorY = scaleFactorY;

    menuButtons = new ArrayList<SimpleButton>();
    playButton =
        new SimpleButton(50, 50, 200, 200, AssetLoader.bombTexture2, AssetLoader.bombTexture3);
    getMenuButtons().add(playButton);

    sfxButton =
        new SimpleButton(50, 300, 200, 200, AssetLoader.bombTexture1, AssetLoader.bombTexture3);
    if (AssetLoader.getSfx()) {
      sfxButton.setSwitchOn(true);
    } else {
      sfxButton.setSwitchOn(false);
    }
    getMenuButtons().add(sfxButton);
  }
示例#20
0
 @Override
 public void snowPopulate(MyGame game) {
   super.snowPopulate(game);
 }
示例#21
0
 @Override
 public void firePopulate(MyGame game) {
   super.firePopulate(game);
 }
示例#22
0
 /**
  * Populate the world.
  *
  * @param game
  * @param color
  */
 @Override
 public void worldPopulate(MyGame game, Color color) {
   super.worldPopulate(game, color);
 }
示例#23
0
 @Override
 public void actionPerformed(ActionEvent e) {
   gameWorld.setSound(!gameWorld.getSound());
   System.out.println(
       "Sound Command From " + e.getActionCommand() + " " + e.getSource().getClass());
 }
  private void checkControl() {
    keyboard.update();

    if (keyboard.isButtonDown(KeyEvent.VK_ALT) && keyboard.isButtonTapped(KeyEvent.VK_ENTER)) {

      keyboard.releaseButton(KeyEvent.VK_ENTER);
      keyboard.releaseButton(KeyEvent.VK_ALT);
      window.toggleFullscreen();
      window.requestFocusInWindow();
    }

    switch (state) {
      case BEGIN:
        if (world.startScreen.isShown()) {
          if (timer.isDone()) {
            world.startScreen.showScreen(false);
          } else {
            world.startScreen.showScreen(true);
          }
        } else {
          if (keyboard.isButtonTapped(KeyEvent.VK_A) || mouse.isButtonTapped(1)) {
            state = State.PLAYING;
            world.hero.currentWeapon.resetTimer();
            world.start.showScreen(false);
          }
          if (keyboard.isButtonTapped(KeyEvent.VK_ESCAPE)) {
            state = State.MENU;
            world.start.showScreen(false);
          }
        }
        break;
      case PAUSED:
        if (world.menu.getCredit()) {
          if (mouse.isButtonTapped(1) || keyboard.isButtonTapped(KeyEvent.VK_ESCAPE)) {
            world.menu.CreditOff();
            world.deathEdge.drawFront();
            world.ui.drawFront();
            state = State.MENU;
          }
        } else {
          if (keyboard.isButtonTapped(KeyEvent.VK_A)) {
            state = State.PLAYING;
          } else if (keyboard.isButtonTapped(KeyEvent.VK_ESCAPE)) {
            state = State.MENU;
          }
        }
        break;
      case MENU:
        if (keyboard.isButtonTapped(KeyEvent.VK_A)) {
          state = State.PLAYING;
        }
        if (keyboard.isButtonTapped(KeyEvent.VK_ESCAPE)) {
          state = State.PLAYING;
        }
        break;
      case PLAYING:
        if (keyboard.isButtonTapped(KeyEvent.VK_A)) {
          state = State.PAUSED;
        } else if (keyboard.isButtonTapped(KeyEvent.VK_ESCAPE)) {
          state = State.MENU;
        } else if (world.gameOver()) {
          state = State.GAMEOVER;
        }
        break;
      case GAMEOVER:
        if (keyboard.isButtonTapped(KeyEvent.VK_SPACE)) {
          restart();
        }
        break;
      case RESTART:
        restart();
        break;
      case QUIT:
        window.close();
        break;
    }
  }
示例#25
0
 /** 停止游戏 */
 public void stopGame() {
   m_game.stop();
   m_game = null;
   repaint();
 }
 protected void restart() {
   GameState.RemainingLives = 4;
   state = State.BEGIN;
   world.restartWorld(true);
 }