Exemplo n.º 1
0
	//constructor
	Bullit :: Bullit(float xx, float yy,int dir,int ww, int hh){
		setHealth(1);
		setDirectionGoing(dir);
		setSpeed(30);
		setNumOfVertices(3);
		setDistance(0);
		width = 50;
		height = 50;
		setXPos((xx+ww/2-width/2)-(xx+ww/2));
		setYPos((yy+hh+height+10)-(yy+hh/2));
		float dist=sqrt(pow(getXPos(),2)+pow(getYPos(),2));
		setXPos(xx+ww/2-width/2+dist*cos(getDirectionGoing()*PI/180));
		setYPos(yy+hh/2-height/2+dist*sin(getDirectionGoing()*PI/180));
		x=xx;
		y=yy;
		w=ww;
		h=hh;
		setNumOfVertices(3);

		//define the bullit
		vertices[0] = getXPos();	//left x
		vertices[1] = getYPos();	//left y
		
		vertices[2] = getXPos()+width;		//right x
		vertices[3] = getYPos();		//right y
		
		vertices[4] = getXPos()+width/2;	//top x
		vertices[5] = getYPos()+height;		//top y
	}
Exemplo n.º 2
0
/**
 *  @brief      Håndter kommando med tilhørende værdi
 *  @details    Fortager en defineret handling ud fra den modtaget kommando med den tilhørende værdi.
 *  @param[in]  cmd Er den modtaget kommando.
 *  @param[in]  val Er den tilhørende værdi.
 *  @public
 *  @memberof   Handler
 *  @author     Casper Dieu Le ([email protected])
 *  @author     Kasper Hinkler Uldbjerg ([email protected])
 *  @author     Jeppe Stærk Antonsen ([email protected])
 */
void handler(uint8 cmd, uint8 val)
{
  switch (cmd) {
    case CMD_SET_X_POS :
      setXPos(val);
      break;
    case CMD_SET_Y_POS:
      setYPos(val);
      break;
    case CMD_GET_X_POS :
      i2cTxBuffer[I2C_PACKET_CMD_POS] = cmd;
      i2cTxBuffer[I2C_PACKET_VAL_POS] = (uint8)((resolution * dataXY.xPos) / dataXY.xMax + 1);
      i2c_tx();
      break;
    case CMD_GET_Y_POS :
      i2cTxBuffer[I2C_PACKET_CMD_POS] = cmd;
      i2cTxBuffer[I2C_PACKET_VAL_POS] = (uint8)((resolution * dataXY.yPos) / dataXY.yMax + 1);
      i2c_tx();
      break;
    case CMD_X_STP:
      dataXY.isrStopX = 1;
      break;
    case CMD_Y_STP:
      dataXY.isrStopY = 1;
      break;
    case CMD_X_CAL:
      calibrateX();
      break;
    case CMD_Y_CAL:
      calibrateY();
      break;
    default :
      break;
  }
}
Exemplo n.º 3
0
	void Bullit:: move(){
		setXPos(getXPos()+getSpeed()*cos(getDirectionGoing()*PI/180));
		setYPos(getYPos()+getSpeed()*sin(getDirectionGoing()*PI/180));

		//glTranslatef(getX()+getW()/2,getY()+getH()/2,0.0);
		//glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
		//glTranslatef(-getX()-getW()/2,-getY()-getH()/2,0.0);

		//setYPos(getYPos()+getSpeed());

		setDistance(getDistance()+getSpeed());
		if(getDistance()>=1000){
			setAlive(false);
			setXPos(3000);
			setYPos(3000);
		}
		setVertices();

		glTranslatef(getXPos()+width/2,getYPos()+height/2,0.0);
		glRotatef(getDirectionGoing()-90,0.0,0.0,1.0);
		glTranslatef(-getXPos()-width/2,-getYPos()-height/2,0.0);
	}
Exemplo n.º 4
0
	void Bullit:: setVertices(){
		//redefine the ship with rap around
		if(getXPos()<0-width)
			setXPos(2000);

		else if(getXPos()>2000 && isAlive())
			setXPos(0-width);

		if(getYPos()<0-height)
			setYPos(2000);

		else if(getYPos()>2000 && isAlive())
			setYPos(0-height);

		vertices[0] = getXPos();	//left x
		vertices[1] = getYPos();	//left y
		
		vertices[2] = getXPos()+width;		//right x
		vertices[3] = getYPos();		//right y
		
		vertices[4] = getXPos()+width/2;	//top x
		vertices[5] = getYPos()+height;		//top y
	}
Exemplo n.º 5
0
Bateau creerBateau(Position p, char sens, int l)
{
    /*Creer un bateau de position de tete p, avec les nouvelles position qui suivent le sens de s.*/
    Bateau *Bat=malloc(sizeof(int)+ sizeof(Position)+2*sizeof(*TListe)); //Car la liste contiendra des positions et elle est constituée de 2 pointeurs suivant et précédent du type liste doublement chainée
    Bat->longueur=l;
    Position *p1=creerPosition(getXPos(p),getYPos(p));
    AjoutDebut(Bat->positions, p1);
    int i;
    for (i=1;i<l;i++){
        if (sens=='v'){
            setYPos(p1,getYPos(p1)+1);
        }
        else if (sens=='h'){
            setXPos(p1,getXPos(p1)+1);
        }
        AjoutDebut (Bat->positions, p1);
    }
    return Bat;
}
//------------------------------------------------------------------------------
// onUpdateY() - update our y position (inches)
//------------------------------------------------------------------------------
bool Translator::onUpdateY(const Basic::Number* const newY)
{
    bool ok = false;
    if (newY != nullptr) ok = setYPos(newY->getReal());
    return ok;
}