//
// barrier.h
//
// barriers in the game
//
//
// Author: Tomi Belan <tomi.belan@gmail.com>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include <iostream> // @debug
#include <stdlib.h> // random()
#include <SDL.h>

#include "barrier.h"
#include "main.h"
#include "gamehandler.h"

Barrier::Barrier(GameHandler *handler, int type)
{
  this->type = type;
  this->handler = handler;
  
  switch(type) {
    case 0: image = imagePool["prekazka1.png"]; break;
    case 1: image = imagePool["prekazka2.png"]; break;
    case 2: image = imagePool["prekazka3.png"]; break;
  }
  relocate();
  handler->barriers.push_back(this);
}

Barrier::~Barrier()
{
}

void Barrier::relocate()
{
  set_rect_dim(rect, image->w, image->h);
  set_rect_pos(rect, random()%(handler->world->w-rect.w), random()%(handler->world->h-rect.h));
  if(handler->collidesWithBarriers(rect))
    relocate();
}

void Barrier::update(SDL_Surface *where)
{
  SDL_BlitSurface(image, NULL, where, &rect);
}


