/**
   * Returns a set of all Cannons from the database
   *
   * @return
   */
  public ArrayList<Cannon> getAll() {

    final String SQLGet = "SELECT * FROM cannons";

    ArrayList<Cannon> result = new ArrayList<>();

    Cursor cursor = db.rawQuery(SQLGet, new String[] {});
    try {
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {
        Cannon cannon = new Cannon();

        cannon.setAttachPoint(new Coordinate(cursor.getString(1)));
        cannon.setEmitPoint(new Coordinate(cursor.getString(2)));
        String attackImagePath = cursor.getString(3);
        int attackImageID = ContentManager.getInstance().loadImage(attackImagePath);
        if (attackImageID == -1) {
          Log.i("modelPopulate", "Failed to load image " + attackImagePath);
          throw new Exception("Cannon failed to populate");
        }

        int attackImageHeight = cursor.getInt(4);
        int attackImageWidth = cursor.getInt(5);
        String attackSoundPath = cursor.getString(6);
        ViewableObject attackViewable =
            new ViewableObject(attackImagePath, attackImageWidth, attackImageHeight, attackImageID);
        int attackSoundID = ContentManager.getInstance().loadSound(attackSoundPath);
        int damage = cursor.getInt(7);
        cannon.setLaserShot(new Laser(attackViewable, attackSoundPath, attackSoundID, damage));

        String imagePath = cursor.getString(8);
        int imageID = ContentManager.getInstance().loadImage(imagePath);
        if (imageID == -1) {
          Log.i("modelPopulate", "Failed to load image " + imagePath);
          throw new Exception("Cannon failed to populate");
        }
        int imageWidth = cursor.getInt(9);
        int imageHeight = cursor.getInt(10);

        cannon.setMainViewableInfo(new ViewableObject(imagePath, imageWidth, imageHeight, imageID));
        result.add(cannon);

        cursor.moveToNext();
      }
    } catch (Exception e) {
      Log.i("modelPopulate", e.getMessage());
    } finally {
      cursor.close();
    }

    return result;
  }
示例#2
0
 public ViewPort() {
   mXDimension = DrawingHelper.getGameViewWidth();
   mYDimension = DrawingHelper.getGameViewHeight();
   mMiniMap = new MiniMap();
   // Loads base image for every level.
   ContentManager.getInstance().loadImage("images/space.bmp");
 }
示例#3
0
 public ViewPort(
     int XDimension,
     int YDimension,
     List<BackgroundImage> backgroundImages,
     AsteroidsGameModel game) {
   mXDimension = XDimension;
   mYDimension = YDimension;
   mBackgroundImages = backgroundImages;
   mGame = game;
   mMiniMap = new MiniMap();
   // Loads base image for every level.
   ContentManager.getInstance().loadImage("images/space.bmp");
 }
示例#4
0
  public void draw() {
    int newXPos = Math.round((mXPosition / mGame.getCurrentLevel().getWidth()) * 1300);
    int newYPos = Math.round((mYPosition / mGame.getCurrentLevel().getHeight()) * 1500);
    int newXDim =
        Math.round(newXPos + (mXDimension)); // * mGame.getCurrentLevel().getWidth()) / 2048);
    int newYDim =
        Math.round(newYPos + (mYDimension)); // * mGame.getCurrentLevel().getWidth()) / 2048);

    DrawingHelper.drawImage(
        ContentManager.getInstance().getImageId("images/space.bmp"),
        new Rect(newXPos, newYPos, newXDim, newYDim),
        null);

    mMiniMap.draw();
  }