Example #1
0
//=============================================================================
// update
// typically called once per frame
// frameTime is used to regulate the speed of movement and animation
//=============================================================================
void Boss::update(float frameTime)
{
	VECTOR2 foo = velocity*frameTime*speed;
	if (getPositionX() + Image::getWidth()*Image::getScale() > GAME_WIDTH)
	{
		setPosition(D3DXVECTOR2(0,getPositionY()));
	}
	if (getPositionX() < 0)
	{
		setPosition(D3DXVECTOR2(GAME_WIDTH-Image::getWidth()*Image::getScale(),getPositionY()));
	}
	if (getPositionY() + Image::getHeight()*Image::getScale() > GAME_HEIGHT)
	{
		setPosition(D3DXVECTOR2(getPositionX(),0));
	}
	if (getPositionY() < 0)
	{
		setPosition(D3DXVECTOR2(getPositionX(),GAME_HEIGHT-Image::getHeight()*Image::getScale()));
	}

	//velocity = D3DXVECTOR2(0,0);
	emp.update(frameTime);
	incPosition(foo);
	Image::setX(getPositionX());
	Image::setY(getPositionY());
    Entity::update(frameTime);
	emp.setPos(spriteData.x-(emp.getWidth()*emp.getScale()-getWidth()*getScale())/2,spriteData.y-(emp.getHeight()*emp.getScale()-getWidth()*getScale())/2);
}
Example #2
0
void Shuriken::update(float frameTime){
	Entity::update(frameTime);
	setRadians(getRadians()+0.05);
	//update position based on velocity changes
	incPosition(D3DXVECTOR2(velocity*frameTime));

	//apply new position
	spriteData.x = getPositionX();
	spriteData.y = getPositionY();
}
Example #3
0
void Bullet::updateBulletPosition(double elapsed_time) {
    double delta_x = direction_x_ * speed_ * elapsed_time;
    double delta_y = direction_y_ * speed_ * elapsed_time;
    incPosition(delta_x, delta_y);
}
Example #4
0
static afs_int32
ReadTapeBlock(struct butm_tapeInfo *info,
	      char *buffer, /* assumed to be 16384 bytes */
	      afs_int32 *blockType)
{
    afs_int32 code = 0;
    afs_int32 rsize, fmtype;
    struct tapeLabel *label;
    struct fileMark *fmark;
    struct blockMark *bmark;
    struct progress *p;

    *blockType = BLOCK_UNKNOWN;

    p = (struct progress *)info->tmRock;

    memset(buffer, 0, BUTM_BLOCKSIZE);
    label = (struct tapeLabel *)buffer;
    fmark = (struct fileMark *)buffer;
    bmark = (struct blockMark *)buffer;

    rsize = readData(p->fid, buffer, BUTM_BLOCKSIZE, &info->error);
    if (rsize > 0) {
	incPosition(info, p->fid, rsize);
	p->reading++;
    }

    if (rsize == 0) {		/* Read a HW EOF Marker? OK */
	*blockType = BLOCK_EOF;
	incSize(info, config.fileMarkSize);	/* Size of filemark */
	if (!isafile)
	    info->position++;	/* bump position */
	p->reading = 0;		/* No reads since EOF */
    }

    else if (rsize != BUTM_BLOCKSIZE) {	/* Didn't Read a full block */
	info->status |= BUTM_STATUS_READERROR;
	ERROR_EXIT((rsize < 0) ? BUTM_IO : BUTM_EOT);
    }

    else if (ntohl(bmark->magic) == BLOCK_MAGIC) {	/* Data block? */
	*blockType = BLOCK_DATA;
    }

    else if (ntohl(fmark->magic) == FILE_MAGIC) {	/* Read a filemark? */
	fmtype = ntohl(fmark->nBytes);

	if (fmtype == FILE_BEGIN) {	/* filemark begin */
	    *blockType = BLOCK_FMBEGIN;
	} else if (fmtype == FILE_FMEND) {	/* filemark end */
	    *blockType = BLOCK_FMEND;
	    code = SeekFile(info, 1);
	} else if (fmtype == FILE_EOD) {	/* EOD mark */
	    *blockType = BLOCK_EOD;
	    info->status |= BUTM_STATUS_EOD;
	    code = SeekFile(info, 1);
	}
    }

    else if (ntohl(label->magic) == TAPE_MAGIC) {	/* Read a tape label? */
	*blockType = BLOCK_LABEL;
	code = SeekFile(info, 1);
    }

    if (isafile)
	info->position++;

  error_exit:
    return (code);
}
Example #5
0
static afs_int32
WriteTapeBlock(struct butm_tapeInfo *info,
	       char *buffer,     /* assumed to be 16384 bytes with data in it */
	       afs_int32 length, /* amount data in buffer */
	       afs_int32 blockType)
{
    afs_int32 code = 0, rc = 0;
    afs_uint32 wsize;
    struct tapeLabel *label;
    struct fileMark *fmark;
    struct blockMark *bmark;
    struct progress *p;
    afs_int32 error = 0;

    p = (struct progress *)info->tmRock;

    if (blockType == BLOCK_DATA) {	/* Data Block */
	if (length == 0)
	    ERROR_EXIT(0);
	bmark = (struct blockMark *)buffer;
	memset(bmark, 0, sizeof(struct blockMark));
	bmark->magic = htonl(BLOCK_MAGIC);
	bmark->count = htonl(length);
    } else if (blockType == BLOCK_FMBEGIN) {	/* Filemark - begin */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_BEGIN);
    } else if (blockType == BLOCK_FMEND) {	/* Filemark - end */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_FMEND);
    } else if (blockType == BLOCK_LABEL) {	/* Label */
	label = (struct tapeLabel *)buffer;
	label->magic = htonl(TAPE_MAGIC);
    } else if (blockType == BLOCK_EOD) {	/* Filemark - EOD mark */
	fmark = (struct fileMark *)buffer;
	fmark->magic = htonl(FILE_MAGIC);
	fmark->nBytes = htonl(FILE_EOD);
    }

    /* Write the tape block */
    /* -------------------- */
    rc = USD_WRITE(p->fid, buffer, BUTM_BLOCKSIZE, &wsize);
    if ((rc == 0) && (wsize > 0)) {
	incPosition(info, p->fid, wsize);	/* record whats written */
	p->writing++;
    }

    if (wsize != BUTM_BLOCKSIZE) {
	info->status |= BUTM_STATUS_WRITEERROR;
	if (rc != 0) {
	    error = rc;
	    ERROR_EXIT(BUTM_IO);
	} else
	    ERROR_EXIT(BUTM_EOT);
    }
    if (isafile)
	info->position++;

    /* Write trailing EOF marker for some block types */
    /* ---------------------------------------------- */
    if ((blockType == BLOCK_FMEND) || (blockType == BLOCK_LABEL)
	|| (blockType == BLOCK_EOD)) {

	POLL();
	error = WriteEOF(p->fid, 1);
	POLL();
	if (error) {
	    info->status |= BUTM_STATUS_WRITEERROR;
	    ERROR_EXIT(BUTM_IOCTL);
	}

	incSize(info, config.fileMarkSize);
	if (!isafile)
	    info->position++;
	p->writing = 0;
    }

  error_exit:
    if (error)
	info->error = error;
    return (code);
}
Example #6
0
/*	Function Name: updatePosition
 *	Arguments:     t -- time of next position (in milliseconds)
 *	Description:   update the robot position in the simulator
 *                     and communicate the change to base_frontend
 *	Returns:       nothing
 *
 * Pre: Given the following for time t0: robot_x, robot_y, robot_o,
 *     rotation_velocity, translation_velocity, (may be positive or negative)
 *     rotation_distance, translation_distance (absolute distance,
 *     without sign)
 * Post: update robot_x, robot_y, robot_o,
 *      rotation_position, translation_position to reflect time t.
 */
void updatePosition(unsigned long tMsec)
{
  double incX, incY, incTheta;
  double tSec, dt, maxRotT, maxTransT; /* In seconds */
  double prev_X, prev_Y;
  int event = 0;
  
  if (tMsec != 0) {

    tSec = (double)tMsec/1000.0;

    prev_X = robot_x;
    prev_Y = robot_y;
  
    dt = tSec;
    if ((rotation_distance != 0.0) && (rotation_velocity != 0.0)) {
      maxRotT = FABS(rotation_distance/rotation_velocity);
      if (maxRotT < dt) dt = maxRotT;
    }
    if ((translation_distance != 0.0) && (translation_velocity != 0.0)) {
      maxTransT = FABS(translation_distance/translation_velocity);
      if (maxTransT < dt) dt = maxTransT;
    }

    incPosition(rotation_velocity, translation_velocity, dt,
		robot_o, &incX, &incY, &incTheta);
  
    /* Change in coordinates: incY = incX and incX = incY. The 
       simulator considers north = 0 degrees and east = 90, while
       we consider north = 90 and east = 0 */
  
    doChange(incY, incX, incTheta);
  
    /* Update distances, stopping the movement if the robot
       has achieve the goal */
  
    if (rotation_distance != 0.0) {
      rotation_distance -= rotation_velocity * dt;
      if (FABS(rotation_distance) < EPSILON) {
	rotation_distance = 0.0;
	rotation_velocity = 0.0;
      }
    }
  
    if (translation_distance != 0.0) {
      translation_distance -= translation_velocity * dt;
      if (FABS(translation_distance) < EPSILON) {
	translation_distance = 0.0;
	translation_velocity = 0.0;
      }
    }
  
    if (dt < tSec) {
    
      /* the rest of the time is moving straigtforward, or it is 
	 rotating in the same place */
    
      dt = tSec - dt;
      incPosition(rotation_velocity, translation_velocity, dt,
		  robot_o, &incX, &incY, &incTheta);

      /* The same change in coordinates */
      doChange(incY, incX, incTheta);
    }
  
    /* check if the robot is blocked */
    if (collision) {
      translation_velocity = 0.0;
      rotation_velocity = 0.0;
    }
  
    currentTime += tMsec;
    /* Force update of display if at end of move, regardless of refresh rate */
    refreshSimDisplay(event);
  }
}