예제 #1
0
파일: logic.c 프로젝트: mbelicki/theseus.f
extern State *update_free( State * const state
                         , const double time
                         )
{
    Entity * const player_entity = & state->player.entity;

    const TileType non_walkable = TILE_WALL;
    TileType dst_tile = update_entity( player_entity, & state->map, 
                                       non_walkable, time );

    const int current = tile_at( & state->map, player_entity->position );
    if (current == TILE_TRAP) {
        die(state);
    } else if (current == TILE_TRADER) {
        change_state(state, STATE_TRADE);
    } else if (current == TILE_BOSS) {
        change_state(state, STATE_BOSS);
    }

    if (player_entity->position.x == state->map.width - 1) {
        state->current_level_no += 1;

        clean_map_data( & state-> map );
        change_level( & state->map, state->current_level_no );
        reset_entities( state );
        
        player_entity->position.x = 0;
        player_entity->destination 
            = player_entity->previous_position = player_entity->position;
    }

    for (int i = 0; i < state->enemies_count; i++) {
        Enemy *enemy = state->enemies + i;
        update_enemy( enemy, & state->map, time );
        if ( POINT_EQ( state->player.entity.position
                     , enemy->entity.position
                     ) ) {
            die(state);
        }

        Boulder * b = boulder_at( state, enemy->entity.destination );
        if ( b != NULL ) {
            cancel_move( & enemy->entity );
            swap_enemy_direction( enemy );
        }
    }

    for (int i = 0; i < state->boulders_count; i++) {
        Boulder *boulder = state->boulders + i;
        update_entity( & boulder->entity, & state->map, 0, time );
    }
        
    return state;
}
예제 #2
0
파일: logic.c 프로젝트: mbelicki/theseus.f
static void update_enemy( Enemy * const enemy
                        , const Map * const map
                        , const double time
                        )
{
    const int is_horizontal = enemy->flags & ENEMY_MOVING_HORIZONTAL;
    const int is_going_back = enemy->flags & ENEMY_GOING_BACK;
    
    /* update the target testination */
    if ( is_moving( & enemy->entity ) == 0 ) {
        const int delta = is_going_back ? 1 : -1;
        if ( is_horizontal ) {
            enemy->entity.destination.x += delta;
        } else {
            enemy->entity.destination.y += delta;
        }
    }
    /* do the walking */
    const TileType non_walkable = TILE_WALL | TILE_STRING | TILE_TRAP;
    update_entity( & enemy->entity, map, non_walkable, time );
    /* handle wall hit */
    if ( enemy->entity.flags & ENTITY_HAS_HIT_WALL ) {
        swap_enemy_direction( enemy );
        enemy->entity.flags &= ~ENTITY_HAS_HIT_WALL;
    }
}
예제 #3
0
파일: scene3D.cpp 프로젝트: DoubleJump/IMGL
	fn void
	update()
	{
		auto root = get_entity(0);
		if(root->dirty)
		{
			root->world_matrix = mat4::compose(root->position, root->scale, root->rotation);
		}
		for(i32 i = 1; i < scene::ctx->num_entities; ++i)
		{
			auto entity = get_entity(i);
			update_entity(entity);
		}
	}
예제 #4
0
파일: scene3D.cpp 프로젝트: DoubleJump/IMGL
	fn void
	update_entity(Entity* e)
	{
		if(!e->active) return;
		auto parent = get_entity(e->parent);

		if(e->dirty)
		{
			e->local_matrix = mat4::compose(e->position, e->scale, e->rotation);
		}
		e->world_matrix = parent->world_matrix * e->local_matrix;
		
		for(i32 i = 0; i < 8; ++i)
		{
			auto id = e->children[i];
			if(id != -1)
			{
				auto child = get_entity(id);
				update_entity(child);
			}
		}
		e->dirty = false;
	}