Beispiel #1
0
void Drop_onFrame( Object* e )
{
    const int STATE_DROP = 0;
    const int STATE_FALLING = 1;
    const int STATE_FELL = MS_TO_FRAMES(1000);

    if (e->state == STATE_DROP) {
        Object* drop = createObject(level, TYPE_DROP, 0, 0);
        drop->x = e->x;
        drop->y = e->y;
        drop->state = STATE_FALLING;
        e->state -= rand() % MS_TO_FRAMES(10000);

    } else if (e->state == STATE_FALLING) {
        if (e->vy < 5) {
            e->vy += 1;
        }
        if (move(e, 0, e->vy, 0)) {
            e->y += e->vy;
            e->state += 1;
        } else {
            e->state -= 1;
        }

    } else if (e->state > STATE_FELL) {
        e->removed = 1;
    }

    e->state += 1;
}
Beispiel #2
0
void ShooterEnemy_onFrame( Object* e )
{
    const int STATE_MOVING = 0;
    const int STATE_ATTACK1 = MS_TO_FRAMES(750);
    const int STATE_ATTACK2 = MS_TO_FRAMES(1000);

    if (e->state <= STATE_MOVING) {
        if (isVisible(e, (Object*)&player)) {
            Object* shot = createObject(level, TYPE_ICESHOT, 0, 0);
            shot->x = e->anim.direction > 0 ? e->x + e->type->width : e->x - e->type->width;
            shot->y = e->y;
            shot->vx *= e->anim.direction;
            shot->anim.direction = e->anim.direction;
            e->state = STATE_MOVING + 1;
        } else if (move(e, e->vx, e->vy, 1)) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;
        }
        setAnimation(e, 1, 2, 24);

    } else if (e->state <= STATE_ATTACK1) {
        setAnimation(e, 4, 4, 24);

    } else if (e->state <= STATE_ATTACK2) {
        setAnimation(e, 1, 1, 24);

    } else {
        e->state = STATE_MOVING;
    }

    e->state += e->state > STATE_MOVING;
}
Beispiel #3
0
void Teleporting_onHit( Object* e )
{
    const int STATE_MOVING = MS_TO_FRAMES(4000); // Duplicate
    if (e->state <= STATE_MOVING) {
        Enemy_onHit(e);
    }
}
Beispiel #4
0
void Fireball_onFrame( Object* e )
{
    const int STATE_MOVING = 0;
    const int STATE_ATTACK1 = MS_TO_FRAMES(500);
    const int STATE_ATTACK2 = MS_TO_FRAMES(1000);

    if (e->state <= STATE_MOVING) {
        if (isVisible(e, (Object*)&player)) {
            Object* shot = createObject(level, TYPE_FIRESHOT, 0, 0);
            shot->x = e->x + e->anim.direction * 20;
            shot->y = e->y + 2;
            shot->vx *= e->anim.direction;
            shot->anim.direction = e->anim.direction;
            e->state = STATE_MOVING + 1;
        }
        setAnimation(e, 0, 1, 24);

    } else if (e->state <= STATE_ATTACK1) {
        setAnimation(e, 4, 4, 24);

    } else if (e->state <= STATE_ATTACK2) {
        setAnimation(e, 0, 1, 24);

    } else {
        e->state = STATE_MOVING;
    }

    const int m = move(e, e->vx , e->vy , 0);
    if (m) {
        if (m & DIRECTION_X) e->vx = -e->vx;
        if (m & DIRECTION_Y) e->vy = -e->vy;
        e->anim.direction = e->vx > 0 ? 1 : -1;
    }
    if (rand() % 100 == 99) {
        if (rand() % 2) {
            e->vx = -e->vx;
        }
        e->anim.direction = e->vx > 0 ? 1 : -1;
    }

    e->state += e->state > STATE_MOVING;
}
Beispiel #5
0
static void run_test(struct loop_timer *t)
{
	UNUSED_PARAM(t);
	enum mw_err err;

	// Join AP
	println("Associating to AP", VDP_TXT_COL_WHITE);
	err = mw_ap_assoc(0);
	if (err != MW_ERR_NONE) {
		goto err;
	}
	err = mw_ap_assoc_wait(MS_TO_FRAMES(30000));
	if (err != MW_ERR_NONE) {
		goto err;
	}
	// Wait an additional second to ensure DNS service is up
	mw_sleep(MS_TO_FRAMES(1000));
	println("DONE!", VDP_TXT_COL_CYAN);
	println(NULL, 0);

	// Connect to www.duck.com on port 443
	println("Connecting to www.duck.com", VDP_TXT_COL_WHITE);
	err = mw_tcp_connect(1, "www.duck.com", "443", NULL);
	if (err != MW_ERR_NONE) {
		goto err;
	}
	println("DONE!", VDP_TXT_COL_CYAN);
	println(NULL, 0);

	println("Test finished, all OK!", VDP_TXT_COL_WHITE);
	
	mw_tcp_disconnect(1);
	goto out;

err:
	println("ERROR!", VDP_TXT_COL_MAGENTA);

out:
	mw_ap_disassoc();
}
Beispiel #6
0
void Teleporting_onFrame( Object* e )
{
    const int STATE_MOVING = MS_TO_FRAMES(4000);
    const int STATE_TELEPORTING = MS_TO_FRAMES(7000);
    const int STATE_WAITING = MS_TO_FRAMES(7000);

    if (e->state <= STATE_MOVING) {
        if (move(e, e->vx, e->vy, 1)) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;
        }
        setAnimation(e, 1, 2, 24);

    } else if (e->state < STATE_TELEPORTING) {
        setAnimation(e, 2, 2, 24);

    } else if (e->state == STATE_TELEPORTING) {
        int r, c;
        int prevr = (e->y + CELL_HALF) / CELL_SIZE;
        int count = CELL_COUNT;
        while (count --) {
            r = rand() % (ROW_COUNT - 1);
            c = rand() % COLUMN_COUNT;
            if (isSolid(r + 1, c, SOLID_TOP) && !isSolid(r, c, SOLID_ALL) && r != prevr) {
                e->y = CELL_SIZE * r;
                e->x = CELL_SIZE * c;
            }
        }

    } else if (e->state <= STATE_WAITING) {
        setAnimation(e, 2, 2, 24);

    } else {
        e->state = -rand() % MS_TO_FRAMES(2000);
    }

    e->state += 1;
}
Beispiel #7
0
void Shot_onFrame( Object* e )
{
    const int STATE_MOVING = 0;
    const int STATE_HIT = MS_TO_FRAMES(170);

    if (e->state <= STATE_MOVING) {
        if (move(e, e->vx, e->vy, 0)) {
            setAnimation(e, 3, 3, 5);
            e->state = STATE_MOVING + 1;
        }

    } else if (e->state <= STATE_HIT) {
        e->state += 1;

    } else {
        e->removed = 1;
    }
}
Beispiel #8
0
void Enemy_onFrame( Object* e )
{
    if (e->state <= ENEMY_STATE_MOVING) {
        if (move(e, e->vx, e->vy, 1)) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;
        }
        setAnimation(e, 1, 2, 24);

    } else if (e->state <= ENEMY_STATE_WAITING) {
        setAnimation(e, 2, 2, 24);

    } else {
        e->state = ENEMY_STATE_MOVING - rand() % MS_TO_FRAMES(20000);
        if (rand() % 2) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;
        }
    }

    e->state += 1;
}
Beispiel #9
0
void Drop_onInit( Object* e )
{
    e->y = (e->y / CELL_SIZE) * CELL_SIZE - (CELL_SIZE - e->type->height) / 2 - 1;
    e->state = -rand() % MS_TO_FRAMES(2000);
}
Beispiel #10
0
 *              object->state
 *
 * Values within [0; STATE_1] belongs to STATE_1, within [STATE_1 + 1; STATE2] -
 * to STATE_2, and so on. The state's range size determines how long the object
 * will be in that state.
 *
 * Note: The minimum state value is usually 0, but it can be negative as well.
 */


void Object_onInit( Object* obj ) {}
void Object_onFrame( Object* obj ) {}
void Object_onHit( Object* obj ) {}


const int ENEMY_STATE_MOVING = MS_TO_FRAMES(10000);
const int ENEMY_STATE_WAITING = MS_TO_FRAMES(12000);

void Enemy_onInit( Object* e )
{
    const int dir = rand() % 2 ? 1 : -1;
    e->vx = e->type->speed * dir;
    e->anim.direction = dir;
}

void Enemy_onFrame( Object* e )
{
    if (e->state <= ENEMY_STATE_MOVING) {
        if (move(e, e->vx, e->vy, 1)) {
            e->vx = -e->vx;
            e->anim.direction = -e->anim.direction;