Пример #1
0
//movement of zombies to follow player
void Zombie::move(){

     if((x()<player1->x()) && (y()<player1->y())){
        zombieCollision();
        setPos(x()+.7, y() + .7);
        zombieCollision();
        collision();
        deleteZombie();
        direct=1;
    }
    if((x()>player1->x()) && (y()<player1->y())){
        zombieCollision();
        setPos(x()-.7,y()+.7);
        zombieCollision();
        collision();
        deleteZombie();
        direct=2;
    }
    if((x()<player1->x()) && (y()>player1->y())){
        zombieCollision();
        setPos(x()+.7, y() -.7);
        zombieCollision();
        collision();
        deleteZombie();
        direct=3;
    }
    if((x()>player1->x()) && (y()>player1->y())){
        zombieCollision();
        setPos(x()-.7,y()-.7);
        zombieCollision();
        collision();
        deleteZombie();
        direct=4;
    }


}
Пример #2
0
int main() {
	setMode(MODE_4 | BG2_ENABLE);
	startGame();
	while(1) {
		if (KEY_DOWN_NOW(KEY_START) && state == 0) {			
			state = 1;
			numOfLives = 3;
			loadAvatar();
			fillPalette(GPalette_palette, 0, GPALETTE_PALETTE_SIZE);
			PALETTE[200] = BLACK;
			PALETTE[201] = WHITE;
			PALETTE[202] = RED;
			PALETTE[203] = GREEN;
			PALETTE[204] = BLUE;
			
			for (int i = 0; i < 5; i++) {
				homeFlags[i] = 0;
			}
		}
		if (state == 1) {
			drawBG();
			char liveStr[7];
		if (numOfLives >= 0) {
			sprintf(liveStr, "%d", numOfLives);
			drawString4(10, 147, "LIVES LEFT:  ", PALETTE[1]);
			drawString4(80, 147, liveStr, PALETTE[1]);
		}
			drawTrucks();
			drawCars();
			drawCrocodiles();
			drawWoods();
			drawFrog();
			collision();
			reset();
			delay(2);
			waitForVblank();
			flipPage();
		}
		if (state == 2) {
			while (1) {
				if (KEY_DOWN_NOW(KEY_START)) {
					state = 0;
					break;
				}
			}
		}
	}
	return 0;
}
Пример #3
0
/*
    Modified from original.
    Now invisible sprites may still collide.
*/
void Engine::TestForCollisions()
{
    std::list<Entity*>::iterator first;
    std::list<Entity*>::iterator second;
    Sprite *sprite1;
    Sprite *sprite2;

    first = p_entities.begin();
    while (first != p_entities.end() )
    {
        //we only care about sprite collisions
        if ( (*first)->getRenderType() == RENDER2D )
        {
            //point local sprite to sprite contained in the list
            sprite1 = (Sprite*) *first;

            //if this entity is alive and visible...
            //if ( sprite1->getAlive() && sprite1->getVisible() && sprite1->isCollidable() )
            if ( sprite1->getAlive() && sprite1->isCollidable() )
            {
                //test all other entities for collision
                second = p_entities.begin();
                while (second != p_entities.end() )
                {
                    //point local sprite to sprite contained in the list
                    sprite2 = (Sprite*) *second;

                    //if other entity is active and not same as first entity...
                    //if ( sprite2->getAlive() && sprite2->getVisible() && sprite2->isCollidable() && sprite1 != sprite2 )
                    if ( sprite2->getAlive() && sprite2->isCollidable() && sprite1 != sprite2 )
                    {
                        //test for collision
                        if ( collision(sprite1, sprite2 ) ) {

                            //notify game of collision
                            game_entityCollision( sprite1, sprite2 );
                        }

                    }
                    //go to the next sprite in the list
                    second++;
                }

            }
            //go to the next sprite in the list
            first++;
        }//render2d
    } //while
}
Пример #4
0
Status SearchHash(HashTable H, HKeyType K, int &p, int &c) {  
   // 算法9.17
   // 在开放定址哈希表H中查找关键码为K的元素,
   // 若查找成功,以p指示待查数据元素在表中位置,并返回SUCCESS;
   // 否则,以p指示插入位置,并返回UNSUCCESS,
   // c用以计冲突次数,其初值置零,供建表插入时参考
   p = Hash(K);                          // 求得哈希地址
   while ((H.elem[p].key != NULLKEY) &&  // 该位置中填有记录
          !equal(K, (H.elem[p].key)))   // 并且关键字不相等
      collision(p, ++c);                 // 求得下一探查地址p
   if (equal(K, (H.elem[p].key)))
      return SUCCESS;        // 查找成功,p返回待查数据元素位置
   else return UNSUCCESS;    // 查找不成功(H.elem[p].key == NULLKEY),
                             // p返回的是插入位置
} // SearchHash
Пример #5
0
void move_shape(_shape_book *s_book)
{
    int i, j;
    
    for (i=0; i<s_book->t_blocade; i++) {
        s_book->shape_ptr[i]->checked = false;
    }
    for (j=0; j<s_book->t_blocade; j++) {
        collision(s_book, j);
        for (i=0; i<4; i++) {
            s_book->shape_ptr[j]->pt[i].y += s_book->shape_ptr[j]->vector.y;
            s_book->shape_ptr[j]->pt[i].x += s_book->shape_ptr[j]->vector.x;
        }
    }
}
Пример #6
0
static void new_apple(void) {
	if(length == LED_WIDTH * LED_HEIGHT) {
		end = 1;
		return;
	}

	for(;;) {
		apple[0] = rand() % LED_WIDTH;
		apple[1] = rand() % LED_HEIGHT;

		if(!collision(apple[0], apple[1], 0)) {
			break;
		}
	}
}
Пример #7
0
// Player
Player::Player(QGraphicsItem *parent): QGraphicsPixmapItem(parent)
{
    // set pixmap image for player ship
    // setRect(0,0,100,100);
    setPixmap(QPixmap(":/player-sprites/player-ship.png"));

    // set bullet sound
    bulletsound = new QMediaPlayer();
    bulletsound->setMedia(QUrl("qrc:/sounds/gun-shot.wav"));

    // check for enemy collisions
    QTimer * collisionTimer = new QTimer();
    QObject:: connect(collisionTimer,SIGNAL(timeout()), this, SLOT(collision()));
    collisionTimer->start(250);
}
Пример #8
0
static dNewtonDynamicBody* CreateFreeFallBall(dNewton* const world)
{
	// crate a collision sphere instance, of radio 1.0 and a collision mask 1 
	dNewtonCollisionSphere collision (world, 1.0f, 1);

	// create a dynamic body with a sphere shape, mass of 1.0 kg, located 50 units above the ground 
	dMatrix matrix (dGetIdentityMatrix());
	matrix.m_posit.m_y = 50.0f;
	dNewtonDynamicBody* const body = new MyDynamicBody (world, 1.0, &collision, NULL, matrix);

	// set the linear damping to zero
	body->SetLinearDrag (0.0f);

	return body;
}
Пример #9
0
std::vector < Objet* > CollisionManager::spritecollide(Objet& obj,Group& groupe,bool supprimer) {
	std::vector < Objet* > sprites_collisions;
	std::vector < Objet* > objets_groupe = groupe.objets();
	//Pour tous les objets du groupe on regarde s'ils sont en collision avec un objet
	for(unsigned int i = 0;i < objets_groupe.size();i++) {
		if(collision(objets_groupe[i] -> boundingBox(),obj.boundingBox())) {
			//s'ils sont en collision, on ajoute l'objet du groupe au tableau
			sprites_collisions.push_back(objets_groupe[i]);
			if(supprimer)
				//Si on doit supp
				objets_groupe[i] -> supprimer();
		}
	}

	return sprites_collisions;
}
Пример #10
0
int Level::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: collision((*reinterpret_cast< QVector3D(*)>(_a[1]))); break;
        case 1: inclineChanged((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break;
        case 2: update(); break;
        default: ;
        }
        _id -= 3;
    }
    return _id;
}
Пример #11
0
Файл: cgii.c Проект: chamun/CGII
void
collided_points(void)
{
    int i;

    for (i = 0; i < DYNAMIC_OBJECTS_NUMBER; i++) {
        if (coins[i].visible) {
            if (collision(compass[P].x, compass[P].y, &coins[i])) {
                score++;
                coins[i].visible = 0;
            }
        }
    }
    if(score == DYNAMIC_OBJECTS_NUMBER)
        playing = 0;
}
Пример #12
0
size_t ContainerGrid::getSlot(const ScreenPoint &mousePos) const {
  if (!collision(mousePos, ScreenRect{0, 0, width(), height()})) return NO_SLOT;
  size_t x = static_cast<size_t>((mousePos.x) / (Client::ICON_SIZE + _gap + 2)),
         y = static_cast<size_t>((mousePos.y - 1) /
                                 (Client::ICON_SIZE + _gap + 2));
  // Check inside gaps
  if (mousePos.x - static_cast<px_t>(x) * (Client::ICON_SIZE + _gap + 2) >
      Client::ICON_SIZE + 2)
    return NO_SLOT;
  if (mousePos.y - static_cast<px_t>(y) * (Client::ICON_SIZE + _gap + 2) >
      Client::ICON_SIZE + 2)
    return NO_SLOT;
  size_t slot = y * _cols + x;
  if (slot >= _linked.size()) return NO_SLOT;
  return slot;
}
Пример #13
0
static void drop_cb(struct game_state *gs)
{
	if (collision(gs, 0, 1)) {

		int old = value(gs);
		put_shape(gs, 1);
		fix_grid(gs);
		fprintf(gs->log, "%d %d\n", old, gs->lines);
		printf("%d\n", value(gs) - old);
		load_block(gs);
	} else {
		put_shape(gs, 0);
		gs->y += 1;
		put_shape(gs, 4);
	}
}
Пример #14
0
void game_state::check_bullets( void )
{
    for( size_t b = bullets.size(); b > 0; --b )
    {
        for( size_t t = tanks.size(); t > 0; --t )
        {
            if( collision( *bullets[b-1], *tanks[t-1] ) )
            {
                spawn_explosion( bullets[ b - 1 ]->getPos() );
                destroy_tank( t - 1 );
                destroy_bullet( b - 1 );
                break;
            }
        }
    }
}
Пример #15
0
int main(){
	clock_t timelim;
	init();
	printw("Strawb catcher version 1\n");
	printw("\t\tPress F1 or ESC to quit");
	entity p;
	p.x = 10;
	p.y = 20;
	p.display = '@';
	p.score = 0;
	p.colour = 2;
	entity *playerptr = &p;
	entity fr[10];
	entity *fruitpointer = &fr;
	int i;
	definestats(fruitpointer);
	timelim = clock();
	int escape;
	
	while(1 == 1){
		int score = p.score;
		int o = 0;
		mvprintw(0,30,"Score : %d", score);
		movep(playerptr);
		draw(playerptr);
		collision(fruitpointer, playerptr);
		drawf(fruitpointer);
		timelim = clock() - timelim;
		escape = ((int)timelim)/CLOCKS_PER_SEC;
		mvprintw(0, 60,"Seconds : %d", ((int)timelim)/CLOCKS_PER_SEC);
		if(escape > 30){
		
			int d = 0;
			int displayscore = p.score;
			
			clear();
			mvprintw(10, 20, "Congratulations, you have scored %d points\n", displayscore);
			refresh();
			wait(10);
			deinit();
			}
	}
	



}
Пример #16
0
Status SearchHash(HashTable H,KeyType K,int *p,int *c)
{   /* 在开放定址哈希表H中查找关键码为K的元素,若查找成功,以p指示待查数据 */
    /* 元素在表中位置,并返回SUCCESS;否则,以p指示插入位置,并返回UNSUCCESS */
    /* c用以计冲突次数,其初值置零,供建表插入时参考。算法9.17 */
    *p=Hash(K); /* 求得哈希地址 */
    while(H.elem[*p].key!=NULL_KEY&&!EQ(K,H.elem[*p].key))
    {   /* 该位置中填有记录.并且关键字不相等 */
        (*c)++;
        if(*c<m)
            collision(p,*c); /* 求得下一探查地址p */
        else
            break;
    }
    if EQ(K,H.elem[*p].key)
        return SUCCESS; /* 查找成功,p返回待查数据元素位置 */
    else
        return UNSUCCESS; /* 查找不成功(H.elem[p].key==NULL_KEY),p返回的是插入位置 */
Пример #17
0
Status SearchHash(HashTable H, KeyType K, int &p, int &c)
{/* 在开放定址哈希表H中查找关键码为K的元素,若查找成功,以p指示待查数据 */
   /* 元素在表中位置,并返回SUCCESS;否则,以p指示插入位置,并返回UNSUCCESS */
   /* c用以计冲突次数,其初值置零,供建表插入时参考。算法9.17 */
	p = Hash(K); /* 求得哈希地址 */
	while (H.elem[p].key != NULLKEY && !EQ(K, H.elem[p].key))
	{ /* 该位置中填有记录.并且关键字不相等 */
		c++;
		if (c < length)
			collision(p, c); /* 求得下一探查地址p */
		else
			break;
	}
	if EQ(K,H.elem[p].key)
		return SUCCESS; /* 查找成功,p返回待查数据元素位置 */
	else
		return UNSUCCESS; /* 查找不成功(H.elem[p].key==NULLKEY),p返回的是插入位置 */
Пример #18
0
std::vector < Objet* > CollisionManager::groupcollide(Group& groupe2,Group& groupe,bool tuer2,bool tuer1) {
	std::vector < Objet* > sprites_collisions,objets_groupe1 = groupe.objets(),objets_groupe2 = groupe2.objets();
	for(unsigned int i = 0;i < objets_groupe1.size();i++) {
		for(unsigned int j = 0;j < objets_groupe2.size();j++) {
			if(collision(objets_groupe1[i] -> boundingBox(),objets_groupe2[j] -> boundingBox())) {
				sprites_collisions.push_back(objets_groupe1[i]);
				sprites_collisions.push_back(objets_groupe2[j]);
				if(tuer1)
					objets_groupe1[i] -> supprimer();
				if(tuer2)
					objets_groupe2[j] -> supprimer();
			}
		}
	}

	return sprites_collisions;
}
Пример #19
0
	bool collision(const CircleHitBox &circleBox, const RoadBox &roadBox, LineHitBox &lineBox)
	{
		bool collided = false;
		const std::vector<collision::LineHitBox> &hitBox = roadBox.getLineArray();

		for(unsigned int i = 0; i < hitBox.size() && !collided; i++)
		{
			collided = collision(circleBox, hitBox[i]);
			if(collided)
			{
				//std::cout<< "collision\n";
				lineBox = hitBox[i]; //save which line made the collision
			}
		}

		return collided;
	}
Пример #20
0
void jump(char **tela, int score_global) {  //Função que cuida da movimentação do "tijolo" para cima.
    int i, j;

    for(i = 0; i < LINHAS; i++)
            for(j = 0; j < COLUNAS; j++) {
                    if(tela[i][j] == 'X') {
			                     if(tela[i - 1][j] == '#') {
				                        gameover(tela, score_global);
			                      }
			                      else {
                                tela[i - 1][j] = 'X';
                                tela[i][j] = '.';
			                      }
                    }
            }
    collision(tela, score_global);
}
Пример #21
0
//hacia la camara es positivo
//hacia la camara es positivo
void moverAdelante(){
	interaccionCuadros();
	Objeto *aux=escena->objetos["protagonista"];
	if(!checarSubirBajar()){
		if(!collision(aux->rotY-180)){
			double rotYRad= degToRad(aux->rotY-180);
			aux->posZ-= dtran*5 * (cos(rotYRad));
			aux->posX-=  dtran*5 * (sin(rotYRad));
			camaraPrimeraPersona->xview=aux->posX+sin(degToRad(aux->rotY-180));
			camaraPrimeraPersona->zview=aux->posZ+cos(degToRad(aux->rotY-180));
			redimensiona(currWidth,currHeight);	
		}
	}else{
		redimensiona(currWidth,currHeight);	
	}
	
}
Пример #22
0
void rotate()
{
    int i;
    render_tetromino('.');

    tetromino_t* tet = &game_state.current_T;

    ++tet->orientation;
    tet->orientation %= 4;
    if(collision())
    {
        tet->orientation += 3;
        tet->orientation %= 4;
    }

    render_tetromino('*');
}
Пример #23
0
 Status SearchHash(HashTable H,KeyType K,int &p,int &c)
 { // 在开放定址哈希表H中查找关键码为K的元素,若查找成功,以p指示待查数据
   // 元素在表中位置,并返回SUCCESS;否则,以p指示插入位置,并返回UNSUCCESS
   // c用以计冲突次数,其初值置零,供建表插入时参考。算法9.17
   p=Hash(K); // 求得哈希地址
   while(H.elem[p].key!=NULL_KEY&&!EQ(K,H.elem[p].key))
   { // 该位置中填有记录.并且关键字不相等
     c++;
     if(c<m)
       collision(p,c); // 求得下一探查地址p
     else
       break;
   }
   if EQ(K,H.elem[p].key)
     return SUCCESS; // 查找成功,p返回待查数据元素位置
   else
     return UNSUCCESS; // 查找不成功(H.elem[p].key==NULL_KEY),p返回的是插入位置
Пример #24
0
void DynamicsWorld::CollisionImpact( Integration::DynamicsCollisionData* collisionData )
{
    DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);

    DALI_ASSERT_DEBUG(collisionData->mBodyA);
    DALI_ASSERT_DEBUG(collisionData->mBodyB);

    if ( !mCollisionSignalV2.Empty() )
    {
        BodyContainer::iterator it = mBodies.begin();
        BodyContainer::iterator endIt = mBodies.end();

        for( ; it != endIt; ++it )
        {
            if( it->first->GetBody() == collisionData->mBodyA )
            {
                BodyContainer::iterator it2 = mBodies.begin();
                for( ; it2 != endIt; ++it2 )
                {
                    if( it2->first->GetBody() == collisionData->mBodyB )
                    {
                        ActorPtr actorA( (*it).second );
                        ActorPtr actorB( (*it2).second );

                        DynamicsCollisionPtr collision( new DynamicsCollision );
                        collision->SetActorA(actorA);
                        collision->SetActorB(actorB);
                        collision->SetPointOnA(collisionData->mPointOnA);
                        collision->SetPointOnB(collisionData->mPointOnB);
                        collision->SetNormal(collisionData->mNormal);
                        collision->SetImpactForce(collisionData->mImpact);

                        Dali::DynamicsCollision collisionHandle( collision.Get() );
                        Dali::DynamicsWorld worldHandle( this );

                        mCollisionSignalV2.Emit( worldHandle, collisionHandle );

                        break;
                    }
                }

                break;
            }
        }
    }
}
Пример #25
0
int isNearObstacle(Entity *e)
{
	EntityList *el, *entities;

	entities = getEntities();

	for (el=entities->next;el!=NULL;el=el->next)
	{
		if (el->entity->inUse == TRUE && (el->entity->flags & (OBSTACLE|PUSHABLE))
			&& collision(e->x, e->y, e->w, e->h, el->entity->x, el->entity->y, el->entity->w, el->entity->h) == 1)
		{
			return TRUE;
		}
	}

	return FALSE;
}
Пример #26
0
void move_block(Block * block, int dx, int dy, Field field) {
  if (NULL_BLOCK(*block)) return;

  Block new_block = *block;
  new_block.x += dx;
  new_block.y += dy;

  if (collision(&new_block, field)) {
    // if the block is moving down, then it should come to rest.
    // otherwise just do nothing.
    if (dy) {
      freeze_block(block, field);
    }
  } else {
    *block = new_block;
  }
}
Пример #27
0
int isOnBattleScreen(int x, int y, int w, int h)
{
	x -= (w / 2);
	x -= (SCREEN_WIDTH / 2);
	x -= battle.camera.x;
	
	y -= (h / 2);
	y -= (SCREEN_HEIGHT / 2);
	y -= battle.camera.y;
	
	w *= 2;
	w += SCREEN_WIDTH;
	
	h *= 2;
	h += SCREEN_HEIGHT;
	
	return collision(x, y, w, h, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
Пример #28
0
static void set_ghost_block(Tetris *tetris)
{
    tetris->ghost_block->x = tetris->current_block->x;
    tetris->ghost_block->y = tetris->current_block->y;

    Block_set_type(tetris->ghost_block,
                   tetris->current_block->type,
                   tetris->current_block->rotate);

    tetris->ghost_block->color = COLOR_GRAY;

    while (!collision(COORDINATE_BOTTOM_COLLISION,
                             tetris->ghost_block,
                             tetris->renderer->buffer)
    ) {
        ++tetris->ghost_block->y;
    }
}
Пример #29
0
void dragon::update()
{
	aware();

	if(_isAware)
		attack();

	for (int i = 0; i < 3; ++i)
	{
		_bubbles[i].update();
	}

	collision();

	deadMotion();

	setImage();
}
Пример #30
0
void serviceGame(void) {
    move_head(change_dir);
    if (ate_fruit(corners[head].x,corners[head].y))
    {
      snake_length_limit += (snake_length_limit/10);
      make_fruit();
    }
    if (collision()) game_over();
    else {
        gameSetMetaPixel(corners[head].x, corners[head].y, ON); //Redraw
        if (snake_length_current > snake_length_limit)
        {
            gameSetMetaPixel(corners[tail].x, corners[tail].y, OFF); //Erase
            follow_tail();
        }
    }    
    move_tick = 0;
}