コード例 #1
0
ファイル: application.cpp プロジェクト: alfarmaks/fruit-click
void Application::touch(float x, float y)
{
    b2AABB aabb;
    aabb.lowerBound.x = toWorld(x - 1);
    aabb.lowerBound.y = toWorld(y - 1);
    aabb.upperBound.x = toWorld(x + 1);
    aabb.upperBound.y = toWorld(y + 1);

    m_world.QueryAABB(this, aabb);
}
コード例 #2
0
ファイル: application.cpp プロジェクト: alfarmaks/fruit-click
Application::Application()
    : m_world(b2Vec2(0, -2))
    , m_step(0)
    , m_appleInterval(100)
    , m_score(0)
    , m_lives(10)
    , m_grass(m_world)
    , m_leftBound(m_world)
    , m_rightBound(m_world)
{
    m_world.SetContactListener(this);
    m_leftBound.setPosition(0, toWorld(FRUITCLICK_HEIGHT / 2));
    m_rightBound.setPosition(toWorld(FRUITCLICK_WIDTH), toWorld(FRUITCLICK_HEIGHT / 2));
    m_grass.setPosition(toWorld(FRUITCLICK_WIDTH / 2), 0);
}
コード例 #3
0
ファイル: application.cpp プロジェクト: alfarmaks/fruit-click
void Application::spawnApple()
{
    if (m_step % m_appleInterval == 0)
    {
        float x = (rand() % (FRUITCLICK_WIDTH - FRUITCLICK_APPLE_RADIUS*2)) + FRUITCLICK_APPLE_RADIUS;
        float y = FRUITCLICK_HEIGHT + 10;

        float vx = (rand() % 9) - 4;
        float vy = -3;

        Apple* apple = new Apple(m_world);
        apple->setPosition(toWorld(x), toWorld(y));
        apple->setVelocity(vx, vy);
        apple->setAngularVelocity((rand() % 32) - 16);
        m_apples.insert(apple);

        if (m_appleInterval > 25)
            m_appleInterval -= 2;

        m_step = 0;
    }
}
コード例 #4
0
ファイル: core.c プロジェクト: Zugamifk/asteroids-mp
// Wraps objects that go outside the screen's bounds
void wrapPosition(object *o) {
	
	// Convert object position to screen space
	vector toCheck = fromWorld(&(o->pos));
	
	// If a laser, deactivate the object
	if (o->type == LAZOR &&
		(toCheck.x > 1.0 || toCheck.x < -1.0 || 
		toCheck.y > 1.0 || toCheck.y < -1.0)) {
			o->state &= !LAZER_ACTIVE;
			return;
	}
	
	// Adjust position
	if (toCheck.x > 1.0) toCheck.x = -1.0;
	else if (toCheck.x < -1.0) toCheck.x = 1.0;
	if (toCheck.y > 1.0) toCheck.y = -1.0;
	else if (toCheck.y < -1.0) toCheck.y = 1.0;
	
	// Convert position back to world space
	o->pos = toWorld(&toCheck);
}