コード例 #1
0
SFAsset::SFAsset(SFASSETTYPE type, std::shared_ptr<SFWindow> window): type(type), sf_window(window) {
  this->id   = ++SFASSETID;

  switch (type) {
  case SFASSET_PLAYER:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/player.png");
    break;
  case SFASSET_PROJECTILE:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/projectile.png");
    break;
  case SFASSET_ALIEN:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/alien.png");
    break;
  case SFASSET_COIN:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/coin.png");
    break;
  }

  if(!sprite) {
    cerr << "Could not load asset of type " << type << endl;
    throw SF_ERROR_LOAD_ASSET;
  }

  // Get texture width & height
  int w, h;
  SDL_QueryTexture(sprite, NULL, NULL, &w, &h);

  // Initialise bounding box
  bbox = make_shared<SFBoundingBox>(SFBoundingBox(Vector2(0.0f, 0.0f), w, h));
}
コード例 #2
0
void SFAsset::LoadSprite(){
  if(!sprite) {
    cerr << "Could not load asset of type " << endl;
    throw SF_ERROR_LOAD_ASSET;
  }
  // Get texture width & height
  SDL_QueryTexture(sprite, NULL, NULL, &sprite_width, &sprite_height);
  // Initialise bounding box
  bbox = make_shared<SFBoundingBox>(SFBoundingBox(Vector2(0.0f, 0.0f), sprite_width, sprite_height));
}
コード例 #3
0
/*********************************************************
  This is the main code for SFAsset.cpp

  It will be used to setup each object in-game by giving
  it a sprite based on the passed type and applying it to
  the window specified.
*********************************************************/
SFAsset::SFAsset(SFASSETTYPE type, std::shared_ptr<SFWindow> window): type(type), sf_window(window) {

  // Set the asset ID.
  this->id   = ++SFASSETID;

  // Setup what sprite this asset will use
  switch (type) {
    case SFASSET_PLAYER:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/player.png");
      break;
    case SFASSET_PROJECTILE:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/projectile.png");
      break;
    case SFASSET_ALIEN:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/alien.png");
      break;
    case SFASSET_COIN:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/coin.png");
      break;
    case SFASSET_STARS: 
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/stars.png");
      break;
    case SFASSET_HEALTHBAR:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthbar.png");
      break;
    case SFASSET_HEALTHBLOCKG:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthblockgreen.png");
      break;
    case SFASSET_HEALTHBLOCKY:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthblockyellow.png");
      break;
    case SFASSET_HEALTHBLOCKR:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthblockred.png");
      break;
    case SFASSET_POWERUP:
      sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/projectile.png");
      break;
  }

  // If the sprite was not set, then throw an error as it may not exist
  if(!sprite) {
    cerr << "Could not load asset of type " << type << endl;
    throw SF_ERROR_LOAD_ASSET;
  }

  // Get texture width & height
  int w, h;
  SDL_QueryTexture(sprite, NULL, NULL, &w, &h);

  // Initialise bounding box
  bbox = make_shared<SFBoundingBox>(SFBoundingBox(Vector2(0.0f, 0.0f), w, h));
}
コード例 #4
0
SFAsset::SFAsset(SFASSETTYPE type) {
  this->type = type;
  this->id   = ++SFASSETID;
  SDL_Surface * tmp_surf;

  movingLeft = false;
	movingRight = false;
	movingUp = false;
	movingDown = false;

  switch (type) {
  case SFASSET_PLAYER:
    tmp_surf = IMG_Load("../assets/pacman.png");
    break;
  case SFASSET_CHERRY:
    tmp_surf = IMG_Load("../assets/cherry.png");
    break;
  case SFASSET_WALL:
    tmp_surf = IMG_Load("../assets/wall.png");
    break;
  case SFASSET_FOOD:
    tmp_surf = IMG_Load("../assets/food.png");
    break;
  }

  if(!tmp_surf) {
    cerr << "Could not load asset of type " << type << endl;
    throw SF_ERROR_LOAD_ASSET;
  }

  sprite = SDL_DisplayFormatAlpha(tmp_surf);
  SDL_FreeSurface(tmp_surf);

  // Initialise bounding box
  bbox = make_shared<SFBoundingBox>(SFBoundingBox(Vector2(0.0f, 0.0f), sprite->w, sprite->h));
}
コード例 #5
0
ファイル: SFAsset.cpp プロジェクト: Wolfkhan66/starship-
SFAsset::SFAsset(SFASSETTYPE type, std::shared_ptr<SFWindow> window): type(type), sf_window(window) {
  this->id   = ++SFASSETID;

  switch (type) {

///////////////////////////player///////////////////////////////
  case SFASSET_PLAYER:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/player/player.png");
    break;
  case SFASSET_PROJECTILE:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/player/projectile.png");
    break;

///////////////////////////enemies///////////////////////////////
  case SFASSET_ALIEN:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/enemies/alien.png");
    break;
  case SFASSET_SCOUT:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/enemies/scout.png");
    break;
  case SFASSET_RANGER:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/enemies/ranger.png");
    break;
  case SFASSET_ALIENFIRE:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/enemies/alienfire.png");
    break;
  case SFASSET_BOSS:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/enemies/boss.png");
    break;


///////////////////////////collectibles///////////////////////////////
  case SFASSET_COIN:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/collectibles/coin.png");
    break;
  case SFASSET_PICKUP:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/collectibles/pickup.png");
    break;
  case SFASSET_HEALTHPACK:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/collectibles/health.png");
    break;

///////////////////////////misc///////////////////////////////
  case SFASSET_HUD:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/misc/hud.png");
    break;
	case SFASSET_CLOUD:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/misc/cloud.png");
    break;
  case SFASSET_EXPLOSION:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/misc/explosion.png");
    break;
  case SFASSET_GAMEOVER:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/misc/gameover.png");
    break;
  case SFASSET_POW:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/misc/power.png");
    break;

///////////////////////////healthbar///////////////////////////////
  case SFASSET_LIFE:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthbar/lives.png");
    break;
  case SFASSET_HEALTHBARBLUE:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthbar/healthbarblue.png");
    break;
  case SFASSET_HEALTHBARYELLOW:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthbar/healthbaryellow.png");
    break;
  case SFASSET_HEALTHBARRED:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/healthbar/healthbarred.png");
    break;

///////////////////////////NumberAssets/////////////////////////
  case SFASSET_NUM0:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num0.png");
    break;
  case SFASSET_NUM1:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num1.png");
    break;
  case SFASSET_NUM2:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num2.png");
    break;
  case SFASSET_NUM3:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num3.png");
    break;
  case SFASSET_NUM4:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num4.png");
    break;
  case SFASSET_NUM5:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num5.png");
    break;
  case SFASSET_NUM6:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num6.png");
    break;
  case SFASSET_NUM7:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num7.png");
    break;
  case SFASSET_NUM8:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num8.png");
    break;
  case SFASSET_NUM9:
    sprite = IMG_LoadTexture(sf_window->getRenderer(), "assets/numbers/num9.png");
    break;

}
  if(!sprite) {
    cerr << "Could not load asset of type " << type << endl;
    throw SF_ERROR_LOAD_ASSET;
  }

  // Get texture width & height
  int w, h;
  SDL_QueryTexture(sprite, NULL, NULL, &w, &h);

  // Initialise bounding box
  bbox = make_shared<SFBoundingBox>(SFBoundingBox(Vector2(0.0f, 0.0f), w, h));
}