Exemple #1
0
int	move_ball(t_ole *t, int ball)
{
  int	x;
  int	y;
  int	n;
  int	i;
  int	u;

  n = SPEED_BALL;
  t->oball[ball] = t->ball[ball];
  if (is_hit(t, ball) == 1)
    t->vx[ball] = - t->vx[ball];
  else if (is_hit(t, ball) == 2)
    t->vy[ball] = - t->vy[ball];
  else if (is_hit(t, ball) >= 3)
    {
      u = 0;
      i = 0;
      while (t->hitbox[u] != 2)
	u = u + 1;
      while (i < u && t->hitbox[i] != is_hit(t, ball) - 3)
	i = i + 1;
      get_vect(t, i, u, ball);
    }
  if (t->state == 0)
    {
      x = t->ball[ball] % W + n * t->vx[ball];
      y = t->ball[ball] / W + n * t->vy[ball];
      t->ball[ball] = x + y * W;
      put_ball(t, ball);
    }
}
Exemple #2
0
inline int draw(App *app, Body *body, int x, int y)
{

#if 0
	SDL_Rect rect = { x-1, y-1, 3, 3 };
	Uint32 color = SDL_MapRGB(app->screen->format, 0xFF, 0xFF,0x00 );
	SDL_FillRect(app->screen, &rect, color);
#endif

	int target = is_hit(&app->game, body, x, y);
	// printf("hit %d,%d: %d\n", x,y, target);

	if(target==2 && app->game.indy.body.action != ACTION_DEATH) {
		hit(app, body, &app->game.indy.body);
	}
	if(target==3 && app->game.allan.body.action != ACTION_DEATH) {
		hit(app, body, &app->game.allan.body);
	}
	if(target>=4) {
		int idx = target - 4;
		hit(app, body, &app->game.board.enemies[idx].body);
	}

	return target;
}
Exemple #3
0
Vec2f Map::collsion(Object player, Object block, bool up, bool down){

    if (is_hit(player.pos, block.pos - player.size, player.size + block.size)){

        //上
        if (player.vec.y() < 0){
            if (player.pos.y() > block.pos.y() + block.size.y() - (27 * up)){
                return Vec2f(0, (block.pos.y() + block.size.y()) - player.pos.y()) + block.vec;
            }
        }
        //下
        if (player.vec.y() >= 0){
            if (player.pos.y() < block.pos.y() - player.size.y() + (27 * down)){
                return Vec2f(0, (block.pos.y() - player.size.y()) - player.pos.y());
            }
        }
        //左
        //if (player.vec.x() > 0){
        if (player.pos.x() < block.pos.x() + block.size.x() / 2)
            // if (player.pos.x() > block.pos.x()
            return Vec2f((block.pos.x() - player.size.x()) - player.pos.x(), 0);
        //}

        //右
        //if (player.vec.x() < 0){
        if (player.pos.x() > block.pos.x() + block.size.x() / 2)

            return Vec2f((block.pos.x() + block.size.x()) - player.pos.x(), 0);
        //}

    }

    return Vec2f(0, 0);

}
Exemple #4
0
Vec2f NormalBlock::collision(Vec2f _pos, Vec2f _size, Vec2f _vec)
{
	if (is_hit(pos, size, _pos, _size)) {
		//��
		if (_vec.y() < 0) {

			if (_pos.y() > (pos.y() + size.y() / 2 + _size.y() / 2) - 21) {
				return Vec2f(0, (pos.y() + size.y() / 2 + _size.y() / 2) - _pos.y());
			}
		}
		//��
		if (_vec.x() > 0) {
			if (_pos.x() < pos.x()) {
				return Vec2f(pos.x() - size.x() / 2 - _size.x() / 2 - _pos.x(), 0);
			}
		}
		//�E
		if (_vec.x() < 0) {
			if (_pos.x() > pos.x()) {
				return Vec2f(pos.x() + size.x() / 2 + _size.x() / 2 - _pos.x(), 0);
			}
		}
	}

	return Vec2f::Zero();
}
Exemple #5
0
bool windy::app::instance_validation(const nana::point& location) {

	auto canvas_rectangle = nana::rectangle(this->_canvas_stub_widget.pos().x, 
											this->_canvas_stub_widget.pos().y, 
											this->_canvas_stub_widget.size().width, 
											this->_canvas_stub_widget.size().height);

	return canvas_rectangle.is_hit(location);

}
Exemple #6
0
void update_state() {
    for (i=0; i < scur; ++i) {
        if (shots[i].alive == 0) {
            continue;
        }

        if (shots[i].isGoingUp != 0) { // shot is headed to ufos
            u = 0;
            for (x=0; x < level*2+3; ++x) {
                if (ufos[x].alive != 0) {
                    if (is_hit(ufos[x].pos, shots[i].pos, UFO_ART_SIZE)) {
                        ufos[x].alive = 0;
                        shots[i].alive = 0;
                        SCORE += 100;
                    } else {
                        u += 1;
                    }
                }
            }

            if (u == 0) {
                lvld_up();
            }
        } else { // shot is headed to the aup
            if (is_hit(aup.pos, shots[i].pos, AUP_ART_SIZE)) {
                aup.lives -= 1;
                shots[i].alive = 0;
                
                if (aup.lives < 1) {
                    gameover("Your ship is destroyed! Earth has no hope!");
                    quit("You lost the Game... Better luck next time!\n");
                }
            }
        }
    }
}
Exemple #7
0
void		control(t_en *en)
{
	en->x = 0;
	while (en->x < WIDTH)
	{
		init_while(en);
		define_step(en);
		while (en->hit == 0)
			is_hit(en);
		color(en);
		en->hit = 0;
		if (en->side == 0)
			en->perpwall = fabs((en->map.x - en->raypos.x + \
				(1 - en->step.x) / 2) / en->ray.x);
		else
			en->perpwall = fabs((en->map.y - en->raypos.y + \
				(1 - en->step.y) / 2) / en->ray.y);
		drawing(en);
		en->x++;
	}
}