Esempio n. 1
0
/* We use here the fact that C strings get automatically concatenated by the preprocessor
 * Ie, "aze" "rty" is changed into "azerty" by the preprocessor
 */
exercise_t logo_forward_create(void) {
	core_world_t w = world_new(200,200);
	world_entity_add(w,entity_new(100,100,0.));
	exercise_t res = exercise_new(
			"<b>Dans cet exercice</b>, vous devez avancer de 30.\n",

			"void run() {\n"
			"  if(get_x()>50)\n"
			" 	forward(30);\n"
			"}",
			"void run() {\n"
			"  if(get_x()>50)\n"
			" 	forward(30);\n"
			"}");
	exercise_add_world(res, w);
	
	core_world_t w2 = world_new(200,200);
	world_entity_add(w2,entity_new(0,0,0.));
	exercise_add_world(res, w2);
	
	char** functionList = malloc(sizeof(char*)*1);
	functionList[0] = strdup("backward");
	exercise_set_unauthorizedFunction(res, functionList, 1);
	return res;
}
Esempio n. 2
0
static int load_resources(void* unused) {
  
  load_folder("./resources/terrain/");
  load_folder("./resources/vegetation/");
  
  static_object* skydome = entity_new("skydome", static_object);
  skydome->renderable = asset_get("./resources/terrain/skydome.obj");
  renderable_set_material(skydome->renderable, asset_get("./resources/terrain/skydome.mat"));
  skydome->position = v3(512, 0, 512);
  skydome->scale = v3(1024, 1024, 1024);
  
  landscape* world = entity_new("world", landscape);
  world->terrain = asset_get("./resources/terrain/heightmap.raw");
  world->normalmap = asset_get("./resources/terrain/normalsmap.dds");
  world->colormap = asset_get("./resources/terrain/colormap.dds");
  world->attributemap = asset_get("./resources/terrain/attributemap.dds");

  landscape_set_surface(world, 0, asset_get("./resources/terrain/grass.dds"), 
                                  asset_get("./resources/terrain/grass_nm.dds"), 
                                  asset_get("./resources/terrain/grass_far.dds"), 
                                  asset_get("./resources/terrain/grass_far_nm.dds"));
  
  landscape_set_surface(world, 1, asset_get("./resources/terrain/grass2.dds"), 
                                  asset_get("./resources/terrain/grass2_nm.dds"), 
                                  asset_get("./resources/terrain/grass_far.dds"), 
                                  asset_get("./resources/terrain/grass_far_nm.dds"));
  
  landscape_set_surface(world, 2, asset_get("./resources/terrain/earth.dds"), 
                                  asset_get("./resources/terrain/earth_nm.dds"), 
                                  asset_get("./resources/terrain/earth_far.dds"), 
                                  asset_get("./resources/terrain/earth_far_nm.dds"));
  
  landscape_set_surface(world, 3, asset_get("./resources/terrain/rock.dds"), 
                                  asset_get("./resources/terrain/rock_nm.dds"), 
                                  asset_get("./resources/terrain/rock_far.dds"), 
                                  asset_get("./resources/terrain/rock_far_nm.dds"));
  
  vegetation_init();
  vegetation_add_type(asset_get("./resources/terrain/heightmap.raw"), 
                      asset_get("./resources/vegetation/grass.obj"), 
                      4.0);
  
  ui_button* loading = ui_elem_get("loading");
  ui_spinner* load_spinner = ui_elem_get("load_spinner");
  ui_button* framerate = ui_elem_get("framerate");
  ui_button* wireframe = ui_elem_get("wireframe");
  ui_button* freecam = ui_elem_get("freecam");
  loading->active = false;
  load_spinner->active = false;
  framerate->active = true;
  wireframe->active = true;
  freecam->active = true;
  
  loading_resources = false;
  return 1;
}
Esempio n. 3
0
Entity *newCube(Vec3D position,const char *name)
{
    Entity * ent;
    char buffer[255];
    int i;
    ent = entity_new();
    if (!ent)
    {
        return NULL;
    }
    /*for (i = 0; i < 24;i++)
    {
        //sprintf(buffer,"models/robot/walk_bot_%06i.obj",i + 1);
        ent->objAnimation[i] = obj_load(buffer);
    }*/
    ent->objModel = obj_load("models/cube.obj");//ent->objAnimation[0];
	if( !ent->objModel )
		slog( "test" );
    ent->texture = LoadSprite("models/cube_text.png",1024,1024); //LoadSprite("models/robot/robot.png",1024,1024);
    vec3d_cpy(ent->body.position,position);
	vec3d_set(ent->scale,1,1,1);
	vec3d_set(ent->rotation,0,0,0);
	vec4d_set(ent->color,1,1,1,1);
    cube_set(ent->body.bounds,-1,-1,-1,2,2,2);
    ent->rotation.x = 90;
    sprintf(ent->name,"%s",name);
    ent->think = think;
    ent->state = 0;
    mgl_callback_set(&ent->body.touch,touch_callback,ent);
    return ent;
}
Esempio n. 4
0
entity_t *
entity_add (entity_t *entity,
            char *id, entity_inventory_t inventory, char *state,
            condition_t *conditions, room_t *parent)
{
  if (!entity)
  {
    entity = entity_new (id, inventory, state, conditions, parent);
    return entity;
  }

  while (entity->next)
    entity = entity->next;
  entity->next = entity_new (id, inventory, state, conditions, parent);
  return entity->next;
}
Esempio n. 5
0
File: game.c Progetto: ljg6/MyGame2D
void fire_Heavy_Machinegun()
{
	Entity *round;
	if(playerData.rounds > 0&& playerData.shotTimer <= 0)
	{
		playerData.rounds--;
		if(playerData.shotCounter >= 80)
		{
			playerData.shotCounter = 0;
			playerData.shotTimer = 700;
		}else{
			playerData.shotCounter++;
			playerData.shotTimer = 70;
		}
		round = entity_new();
		round->position.x = player->position.x + 45;
		round->position.y = player->position.y + 42;
		round->sprite = loadSprite("images/round.png",20,10,1);
		round->velocity.x = 35;
		if(player->facingLeft == 1)
		{
			round->velocity.x =-35;
		}
	}
}
Esempio n. 6
0
exercise_t logo_square_create(void) {
	world_t w = world_new(200,200);
	world_entity_add(w, entity_new(100,100,0.000000));
	exercise_t res = exercise_new(
"lalalalalalalalalalallalalalalaallal la\n"
" \n"
"on rajout un truc pour l'honneur\n"
,"\n"
"\n"
,"\n"
"\n"
"\n"
"void square(int size) {\n"
"	int i;\n"
"	for (i=0;i<4;i++) {\n"
"		forward(size);\n"
"		right(90);\n"
"	}\n"
"}\n"
"void run (){\n"
"	square(90);\n"
"	square(60);\n"
"	square(30);\n"
"}\n"
"\n"
"\n"
, w);
	return res;
}
Esempio n. 7
0
File: game.c Progetto: ljg6/MyGame2D
/**
* @brief Fires the players shotgun.
*/
void fire_Shotgun()
{
	Entity *shellHigh;
	Entity *shellLow;
	Entity *shellMid;
	if(playerData.shells > 0 && playerData.shotTimer <= 0)
	{
		playerData.shells--;
		playerData.shotTimer = 1400;
		shellHigh = entity_new();
		shellLow = entity_new();
		shellMid = entity_new();


		shellMid->position.x = player->position.x + 45;
		shellMid->position.y = player->position.y + 42;
		shellMid->sprite = loadSprite("images/shell.png",20,10,1);
		shellMid->velocity.x = 30;
		if(player->facingLeft == 1)
		{
			shellMid->velocity.x =-30;
		}

		shellHigh->position.x = player->position.x + 45;
		shellHigh->position.y = player->position.y + 42;
		shellHigh->sprite = loadSprite("images/shell.png",20,10,1);
		shellHigh->velocity.x = 30;
		shellHigh->velocity.y = 1;
		if(player->facingLeft == 1)
		{
			shellHigh->velocity.x =-30;
		}

		shellLow->position.x = player->position.x + 45;
		shellLow->position.y = player->position.y + 42;
		shellLow->sprite = loadSprite("images/shell.png",20,10,1);
		shellLow->velocity.x = 30;
		shellLow->velocity.y = -1;
		if(player->facingLeft == 1)
		{
			shellLow->velocity.x =-30;
		}
	}
}
Esempio n. 8
0
File: game.c Progetto: ljg6/MyGame2D
void init_lvlOnePickups()
{
	healthPickup = entity_new();
  healthPickup->sprite = loadSpriteGraphics("images/health.png","text/health.anim",20,20,4);
  resetAnimation(healthPickup,0);
  healthPickup->bounds.x = 0;
  healthPickup->bounds.y = 0;
  healthPickup->bounds.w = 20;
  healthPickup->bounds.h = 21;
  healthPickup->touch = pickup_Health;

  pistolAmmoPickup = entity_new();
  pistolAmmoPickup->sprite = loadSpriteGraphics("images/pistolAmmo_sheet.png","text/pistol.anim",19,17,4);
  pistolAmmoPickup->bounds.x = 0;
  pistolAmmoPickup->bounds.y = 0;
  pistolAmmoPickup->bounds.w = 19;
  pistolAmmoPickup->bounds.h = 17;
  pistolAmmoPickup->touch = pickup_PistolAmmo;

  shotgunAmmoPickup = entity_new();
  shotgunAmmoPickup->sprite = loadSpriteGraphics("images/shotgunAmmo_sheet.png","text/pistol.anim",20,18,4);
  shotgunAmmoPickup->bounds.x = 0;
  shotgunAmmoPickup->bounds.y = 0;
  shotgunAmmoPickup->bounds.w = 20;
  shotgunAmmoPickup->bounds.h = 18;
  shotgunAmmoPickup->touch = pickup_ShotgunAmmo;

  machinegunAmmoPickup = entity_new();
  machinegunAmmoPickup->sprite = loadSpriteGraphics("images/machinegunAmmo_sheet.png","text/pistol.anim",17,18,4);
  machinegunAmmoPickup->bounds.x = 0;
  machinegunAmmoPickup->bounds.y = 0;
  machinegunAmmoPickup->bounds.w = 17;
  machinegunAmmoPickup->bounds.h = 18;
  machinegunAmmoPickup->touch = pickup_MachinegunAmmo;

  pistolPickup = entity_new();
  shotgunPickup = entity_new();
  machinegunPickup = entity_new();
  heavyMachinegunPickup = entity_new();

  healthPickup->position.x = 50;
  healthPickup->position.y = 400;

  pistolAmmoPickup->position.x = 100;
  pistolAmmoPickup->position.y = 400;
  
  shotgunAmmoPickup->position.x = 150;
  shotgunAmmoPickup->position.y = 400;

  machinegunAmmoPickup->position.x = 200;
  machinegunAmmoPickup->position.y = 400;
}
Esempio n. 9
0
File: game.c Progetto: ljg6/MyGame2D
void init_UI()
{
	health_title = entity_new();
	health_title->sprite = loadSprite("images/healthbartitle.png",216,36,1);
    health_title->position.x = 0;
    health_title->position.y = 0;
	bulletFont = TTF_OpenFont("fonts/FantasqueSansMono-Regular.ttf",12);
	healthFont = TTF_OpenFont("fonts/FantasqueSansMono-Regular.ttf",14);
    health_bar  = loadSprite("images/healthbar.png",352,32,1);

	healthTrack.x = 176;
	healthTrack.y = 60;
	sprintf(healthText,"%3d%%",playerData.health);
	health_Surface = TTF_RenderText_Solid(healthFont,healthText,healthColor);
	health_Texture = SDL_CreateTextureFromSurface(gt_graphics_get_active_renderer(),health_Surface);
	healthTrack.w = health_Surface->w;
	healthTrack.h = health_Surface->h;
	SDL_FreeSurface(health_Surface);
	SDL_RenderCopy(gt_graphics_get_active_renderer(),health_Texture,NULL,&healthTrack);
	

	bulletTarget.x = 700;
    bulletTarget.y = 100;
	sprintf(bulletText,"Bullets: %d",playerData.bullets);
	bullet_Surface = TTF_RenderText_Solid(bulletFont,bulletText,projectileColor);
	bullet_Texture = SDL_CreateTextureFromSurface(gt_graphics_get_active_renderer(),bullet_Surface);
	bulletTarget.w = bullet_Surface->w;
	bulletTarget.h = bullet_Surface->h;
	SDL_FreeSurface(bullet_Surface);
	SDL_RenderCopy(gt_graphics_get_active_renderer(),bullet_Texture,NULL,&bulletTarget);
	

	bulletTarget.x = 700;
    bulletTarget.y = 125;
	sprintf(bulletText,"shells: %d",playerData.shells);
	bullet_Surface = TTF_RenderText_Solid(bulletFont,bulletText,projectileColor);
	bullet_Texture = SDL_CreateTextureFromSurface(gt_graphics_get_active_renderer(),bullet_Surface);
	bulletTarget.w = bullet_Surface->w;
	bulletTarget.h = bullet_Surface->h;
	SDL_FreeSurface(bullet_Surface);
	SDL_RenderCopy(gt_graphics_get_active_renderer(),bullet_Texture,NULL,&bulletTarget);
	

	bulletTarget.x = 700;
    bulletTarget.y = 150;
	sprintf(bulletText,"Rounds: %d",playerData.rounds);
	bullet_Surface = TTF_RenderText_Solid(bulletFont,bulletText,projectileColor);
	bullet_Texture = SDL_CreateTextureFromSurface(gt_graphics_get_active_renderer(),bullet_Surface);
	bulletTarget.w = bullet_Surface->w;
	bulletTarget.h = bullet_Surface->h;
	SDL_FreeSurface(bullet_Surface);
	SDL_RenderCopy(gt_graphics_get_active_renderer(),bullet_Texture,NULL,&bulletTarget);
	
}
Esempio n. 10
0
Entity *weapon_create_for_player(Entity *player_ent) {
    if (player_get_for_id(connection_get_user_id()) != player_ent) {
        return NULL;
    }
    Entity *ent = entity_new(&WeaponEntity);

    WeaponEntityData *data = entity_data(ent);
    data->owner = player_ent;

    return ent;
}
Esempio n. 11
0
static int load_resources(void* unused) {
  
  folder_load(P("./resources/terrain/"));
  folder_load(P("./resources/vegetation/"));
  
  static_object* skydome = entity_new("skydome", static_object);
  skydome->renderable = asset_hndl_new_load(P("./resources/terrain/skydome.obj"));
  ((renderable*)asset_hndl_ptr(skydome->renderable))->material = asset_hndl_new_load(P("$CORANGE/shaders/skydome.mat"));
  skydome->position = vec3_new(512, 0, 512);
  skydome->scale = vec3_new(1024, 1024, 1024);
  
  landscape* world = entity_new("world", landscape);
  world->terrain = asset_hndl_new_load(P("./resources/terrain/heightmap.raw"));
  world->normalmap = asset_hndl_new_load(P("./resources/terrain/normalsmap.dds"));
  world->colormap = asset_hndl_new_load(P("./resources/terrain/colormap.dds"));
  world->attributemap = asset_hndl_new_load(P("./resources/terrain/attributemap.dds"));

  landscape_set_textures(world, asset_hndl_new_load(P("./resources/terrain/surface.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_bump.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_far.dds")), 
                                asset_hndl_new_load(P("./resources/terrain/surface_far_bump.dds")));
  
  vegetation_init();
  //vegetation_add_type(asset_get("./resources/terrain/heightmap.raw"), 
  //                    asset_get("./resources/vegetation/grass.obj"), 
  //                    4.0);
  
  ui_button* loading = ui_elem_get("loading");
  ui_spinner* load_spinner = ui_elem_get("load_spinner");
  ui_button* framerate = ui_elem_get("framerate");
  ui_button* wireframe = ui_elem_get("wireframe");
  ui_button* freecam = ui_elem_get("freecam");
  loading->active = false;
  load_spinner->active = false;
  framerate->active = true;
  wireframe->active = true;
  freecam->active = true;
  
  loading_resources = false;
  return 1;
}
Esempio n. 12
0
File: entity.c Progetto: icule/CLE
entity_t entity_copy(entity_t from) {
	entity_t res = entity_new(from->x,from->y, 0);
	/* We don't use the heading argument of turtle_new to avoid converting from radian to degree and back to radian [catched by Loic Poulain] */
	res->heading = from->heading;
	res->pen_is_down = from->pen_is_down;
	res->rank = from->rank;
	if(from->binary)
	  res->binary = strdup(from->binary);
	else
	  res->binary=NULL;
	return res;
}
Esempio n. 13
0
Entity *newCube(Vec3D position,const char *name)
{
    Entity * ent;
    ent = entity_new();
    if (!ent)
    {
        return NULL;
    }
    ent->objModel = obj_load("models/cube.obj");
    ent->texture = LoadSprite("models/cube_text.png",1024,1024);
    vec3d_cpy(ent->body.position,position);
    cube_set(ent->body.bounds,-1,-1,-1,2,2,2);
    sprintf(ent->name,"%s",name);
    mgl_callback_set(&ent->body.touch,touch_callback,ent);
	ent->body.id = -3;
    return ent;
}
Esempio n. 14
0
void vegetation_init() {
  
  blocks = malloc(X_NUM * Y_NUM * sizeof(static_object*));
  
  for(int x = 0; x < X_NUM; x++)
  for(int y = 0; y < Y_NUM; y++) {
    
    char blockname[512];
    sprintf(blockname, "vegblock_%i_%i", x, y);
    
    static_object* block = entity_new(blockname, static_object);
    block->renderable = asset_hndl_null();
    
    blocks[x + y*X_NUM] = block;
  }

}
Esempio n. 15
0
static void entity_update(const entity_state_t *state)
{
    centity_t *ent = &cl_entities[state->number];
    const vec_t *origin;
    vec3_t origin_v;

    // if entity is solid, decode mins/maxs and add to the list
    if (state->solid && state->number != cl.frame.clientNum + 1
        && cl.numSolidEntities < MAX_PACKET_ENTITIES) {
        cl.solidEntities[cl.numSolidEntities++] = ent;
        if (state->solid != PACKED_BSP) {
            // encoded bbox
            if (cl.esFlags & MSG_ES_LONGSOLID) {
                MSG_UnpackSolid32(state->solid, ent->mins, ent->maxs);
            } else {
                MSG_UnpackSolid16(state->solid, ent->mins, ent->maxs);
            }
        }
    }

    // work around Q2PRO server bandwidth optimization
    if (entity_optimized(state)) {
        VectorScale(cl.frame.ps.pmove.origin, 0.125f, origin_v);
        origin = origin_v;
    } else {
        origin = state->origin;
    }

    if (entity_new(ent)) {
        // wasn't in last update, so initialize some things
        entity_update_new(ent, state, origin);
    } else {
        entity_update_old(ent, state, origin);
    }

    ent->serverframe = cl.frame.number;
    ent->current = *state;

    // work around Q2PRO server bandwidth optimization
    if (entity_optimized(state)) {
        Com_PlayerToEntityState(&cl.frame.ps, &ent->current);
    }
}
Esempio n. 16
0
void animal_initialize_normalcat(int x, int y, State direction)
{
	animal_now = SDL_GetTicks();
	Sprite *animal_sprite = sprite_load("images/reg_cat_sprite.png", ANIMAL_FRAME_W, ANIMAL_FRAME_H);
	
	animal = entity_new();
	animal->sprite = animal_sprite;
	animal->frame = 0;
	animal->frameSize.x = ANIMAL_FRAME_W;
	animal->frameSize.y = ANIMAL_FRAME_H;
	animal->position.x = x;
	animal->position.y = y;
	animal->velocity = 0;
	animal->state = direction;
	animal->animal_type = CAT;
	animal->free = animal_free;
	animal->think = animal_think;
	animal->draw = animal_draw;
	animal->update = animal_update;
}
Esempio n. 17
0
File: game.c Progetto: ljg6/MyGame2D
/**
* @brief Fires the players pistol.
*/
void fire_Pistol()
{
	Entity *bullet;
	int clip = 8;
	if(playerData.bullets > 0 && playerData.shotTimer <= 0)
	{

		playerData.bullets--;
		playerData.shotTimer = 500;
		bullet = entity_new();
		bullet->position.x = player->position.x + 45;
		bullet->position.y = player->position.y + 42;
		bullet->sprite = loadSprite("images/bullet.png",10,10,1);
		bullet->velocity.x = 30;
		if(player->facingLeft == 1)
		{
			bullet->velocity.x =-30;
		}
	}
}
Esempio n. 18
0
File: sea.c Progetto: RicoP/Corange
void sea_event(SDL_Event event) {

    camera* cam = entity_get("camera");
    light* sun = entity_get("sun");

    switch(event.type) {
    case SDL_KEYUP:

        if (event.key.keysym.sym == SDLK_SPACE) {

            char ball_name[20];
            sprintf(ball_name, "ball_%i", ball_count);
            ball_count++;

            physics_object* ball = entity_new(ball_name, physics_object);
            ball->renderable = asset_get("./resources/ball.obj");
            ball->collision_body = collision_body_new_sphere(sphere_new(v3_zero(), 1));
            ball->position = cam->position;
            ball->scale = v3(0.5, 0.5, 0.5);
            ball->velocity = v3_mul(v3_normalize(v3_sub(cam->target, cam->position)), 75);

        }

    case SDL_MOUSEBUTTONDOWN:

        if (event.button.button == SDL_BUTTON_WHEELUP) {
            cam->position = v3_sub(cam->position, v3_normalize(cam->position));
        }
        if (event.button.button == SDL_BUTTON_WHEELDOWN) {
            cam->position = v3_add(cam->position, v3_normalize(cam->position));
        }

        break;

    case SDL_MOUSEMOTION:
        mouse_x = event.motion.xrel;
        mouse_y = event.motion.yrel;
        break;
    }

}
Esempio n. 19
0
exercise_t logo_forward_back_create(void) {
	core_world_t w = world_new(200.000000,200.000000);
	world_entity_add(w, entity_new(100,100,0.000000));
	exercise_t res = exercise_new(
"avancer de 40 puis reculer\n"
," \n"
"  \n"
"void run (){\n"
" \n"
"}\n"
," \n"
"  \n"
"void run (){\n"
" \n"
"	forward(40);\n"
"	backward(40);\n"
" \n"
"}\n");
	exercise_add_world(res, w);
	return res;
}
Esempio n. 20
0
File: game.c Progetto: ljg6/MyGame2D
void init_player()
{
	if(player != NULL)
	{
		return;
	}
  player = entity_new();
  player->sprite = loadSpriteGraphics("images/player_sheet.png","text/player.anim",128,128,9);
  player->cameraEnt = 1;
  player->position.x = 0;
  player->position.y = 350;
  player->bounds.x = 40;
  player->bounds.y = 32;
  player->bounds.w = 40;
  player->bounds.h = 68;

  playerData.health = 75;
  playerData.maxhealth = 100;
  playerData.bullets = 0;
  playerData.shells = 0;
  playerData.rounds = 0;
}
Esempio n. 21
0
/* We use here the fact that C strings get automatically concatenated by the preprocessor
 * Ie, "aze" "rty" is changed into "azerty" by the preprocessor
 */
exercise_t fork_what_the_fork_create(void) {
	printf("Construction de l'exercise what_the_fork\n");
	core_world_t w = world_new(400,400);
	world_entity_add(w,entity_new(10.0, 300.0, 0.));
	exercise_t res = exercise_new(
			"Dans cet exercice, prie!!!!!!!!!!!!!\n",

			"void run() {\n"
			"  fork();\n"
			"  fork();\n"
			"  fork();\n"
			"  fork();\n"
			"}",
			"void run() {\n"
			"  fork();\n"
			"  fork();\n"
			"  fork();\n"
			"  fork();\n"
			"}");
			
	exercise_add_world(res, w);

	return res;
}
Esempio n. 22
0
void scotland_init() {
  
  graphics_viewport_set_dimensions(1280, 720);
  graphics_viewport_set_title("Scotland");
  
  ui_button* loading = ui_elem_new("loading", ui_button);
  ui_button_move(loading, vec2_new(graphics_viewport_width() / 2 - 40,graphics_viewport_height() / 2 - 13));
  ui_button_resize(loading, vec2_new(80,25));
  ui_button_set_label(loading, "Loading...");
  ui_button_disable(loading);
  
  ui_spinner* load_spinner = ui_elem_new("load_spinner", ui_spinner);
  load_spinner->color = vec4_white();
  load_spinner->top_left = vec2_new(graphics_viewport_width() / 2 + 50, graphics_viewport_height() / 2 - 13);
  load_spinner->bottom_right = vec2_add(load_spinner->top_left, vec2_new(24,24));
  
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, vec2_new(10,10));
  ui_button_resize(framerate, vec2_new(30,25));
  ui_button_set_label(framerate, "FRAMERATE");
  ui_button_disable(framerate);
  framerate->active = false;
  
  ui_button* wireframe = ui_elem_new("wireframe", ui_button);
  ui_button_move(wireframe, vec2_new(50,10));
  ui_button_resize(wireframe, vec2_new(80,25));
  ui_button_set_label(wireframe, "wireframe");
  wireframe->active = false;
  
  ui_elem_add_event("wireframe", toggle_wireframe);
  
  ui_button* freecam = ui_elem_new("freecam", ui_button);
  ui_button_move(freecam, vec2_new(140,10));
  ui_button_resize(freecam, vec2_new(65,25));
  ui_button_set_label(freecam, "freecam");
  freecam->active = false;
  
  ui_elem_add_event("freecam", toggle_freecam);
  
  loading_resources = true;
  SDL_Thread* load_thread = SDL_GL_CreateThread(load_resources, NULL);
  
  /* New Camera and light */
  
  camera* cam = entity_new("camera", camera);
  cam->position = vec3_new(512.0, 200.0, 512.0);
  cam->target =  vec3_new(0.0, 0.0, 0.0);
  
  light* sun = entity_new("sun", light);
  light_set_type(sun, light_type_sun);
  sun->position = vec3_new(0, 512, 0);
  sun->target = vec3_new(512, 0, 512);
  
  /* Renderer Setup */
  
  shadow_mapper_init(sun);
  
  forward_renderer_init();
  forward_renderer_set_camera(cam);
  forward_renderer_set_shadow_light(sun);
  forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
  forward_renderer_add_light(sun);
  
}
Esempio n. 23
0
File: sea.c Progetto: RicoP/Corange
void sea_init() {

    graphics_viewport_set_dimensions(1280, 720);
    graphics_viewport_set_title("Sea");

    camera* cam = entity_new("camera", camera);
    cam->position = v3(50.0, 50.0, 50.0);
    cam->target = v3(0, 5, 0);
    cam->near_clip = 0.1;

    light* sun = entity_new("sun", light);
    light_set_type(sun, light_type_spot);
    sun->position = v3(20,23,16);
    sun->ambient_color = v3(0.5, 0.5, 0.5);
    sun->diffuse_color = v3(1.0,  0.894, 0.811);
    sun->specular_color = v3_mul(v3(1.0,  0.894, 0.811), 4);
    sun->power = 5;

    light* backlight = entity_new("backlight", light);
    light_set_type(backlight, light_type_point);
    backlight->position = v3(-22,10,-13);
    backlight->ambient_color = v3(0.2, 0.2, 0.2);
    backlight->diffuse_color = v3(0.729, 0.729, 1.0);
    backlight->specular_color = v3_mul(v3(0.729, 0.729, 1.0), 1);
    backlight->power = 2;

    shadow_mapper_init(sun);

    forward_renderer_init();
    forward_renderer_set_camera(cam);
    forward_renderer_set_shadow_light(sun);
    forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
    forward_renderer_add_light(sun);
    forward_renderer_add_light(backlight);

    load_folder("./resources/");

    texture* noise1 = asset_get("./resources/noise1.dds");
    texture* noise2 = asset_get("./resources/noise2.dds");
    texture* noise3 = asset_get("./resources/noise3.dds");
    texture* noise4 = asset_get("./resources/noise4.dds");
    texture* noise5 = asset_get("./resources/noise5.dds");

    texture* skydome_tex = asset_get("./resources/skybox_cloud_10.dds");

    texture* water_calm = asset_get("./resources/water_calm.dds");
    texture* water_foam = asset_get("./resources/water_foam.dds");

    material* seaplane_mat = asset_get("./resources/seaplane.mat");

    material_set_property(seaplane_mat, "tex_noise1", noise1, mat_type_texture);
    material_set_property(seaplane_mat, "tex_noise2", noise2, mat_type_texture);
    material_set_property(seaplane_mat, "tex_noise3", noise3, mat_type_texture);
    material_set_property(seaplane_mat, "tex_noise4", noise4, mat_type_texture);
    material_set_property(seaplane_mat, "tex_noise5", noise5, mat_type_texture);

    material_set_property(seaplane_mat, "tex_skybox", skydome_tex, mat_type_texture);

    material_set_property(seaplane_mat, "tex_calm_water", water_calm, mat_type_texture);
    material_set_property(seaplane_mat, "tex_foam_water", water_foam, mat_type_texture);

    renderable* r_seaplane = asset_get("./resources/seaplane.obj");
    renderable_set_material(r_seaplane, seaplane_mat);
    static_object* s_seaplane = entity_new("seaplane", static_object);
    s_seaplane->renderable = r_seaplane;
    s_seaplane->scale = v3(3,1,3);

    static_object* skydome = entity_new("skydome", static_object);
    skydome->renderable = asset_get("./resources/skydome.obj");
    renderable_set_material(skydome->renderable, asset_get("./resources/skydome.mat"));
    skydome->position = v3(0, -512, 0);
    skydome->scale = v3(1024, 1024, 1024);

    load_folder("./resources/corvette/");

    renderable* r_corvette = asset_get("./resources/corvette/corvette.obj");
    multi_material* m_corvette = asset_get("./resources/corvette/corvette.mmat");
    renderable_set_multi_material(r_corvette, m_corvette);

    static_object* s_corvette = entity_new("corvette", static_object);
    s_corvette->renderable = r_corvette;
    s_corvette->collision_body = collision_body_new_mesh(asset_get("./resources/corvette/corvette.col"));
    s_corvette->scale = v3(1.5, 1.5, 1.5);
    s_corvette->position = v3(0, 0.5, 0);

    static_object* center_sphere = entity_new("center_sphere", static_object);
    center_sphere->position = v3(0, 5, 0);
    center_sphere->renderable = asset_get("./resources/ball.obj");
    center_sphere->collision_body = collision_body_new_sphere(sphere_new(v3_zero(), 1.0f));

    ui_button* framerate = ui_elem_new("framerate", ui_button);
    ui_button_move(framerate, v2(10,10));
    ui_button_resize(framerate, v2(30,25));
    ui_button_set_label(framerate, "FRAMERATE");
    ui_button_disable(framerate);

}
Esempio n. 24
0
int main(int argc, char *argv[]) {
	if (!window_init()) {
		return 1;
	}

	gameRunning = true;
	SDL_Event sdlEvent;

	u32 lastTickCount = 0;

	g_entities = entityManager_new();
	g_sprites = spriteMngr_new();

	{
		Entity *player = entity_new();
		
		CTransform *tx = player->transform;
		tx->position->x = 200;
		tx->position->y = SCREEN_HEIGHT / 2;

		CSpriteRenderer *sr = 
			(CSpriteRenderer *)entity_addComponent(player, C_SPRITE_RENDERER);

		entity_addComponent(player, C_PLAYER_CONTROLLER);
		sprite_setTexture(sr->sprite, "pship3_blue");
		entityManager_add(g_entities, player);
	}

	entityManager_start(g_entities);

	u32 secondCounter = 0;
	u32 framesCounted = 0;

	while (gameRunning) {
		while(SDL_PollEvent(&sdlEvent) != 0) {
			app_handle_event(sdlEvent);
		}

		u32 ticks = SDL_GetTicks();
		u32 delta = ticks - lastTickCount;

		f32 dt = delta / 1000.0f;
		lastTickCount = ticks;

		game_update(dt);
		game_render();

		++framesCounted;
		secondCounter += delta;

		if (secondCounter >= 1000) {
			printf("FPS: %d\n", framesCounted);
			secondCounter -= 1000;
			framesCounted = 0;
		}
	}

	window_destroy();

	return 0;
}
Esempio n. 25
0
void metaballs_init() {
  
  graphics_viewport_set_title("Metaballs");
  graphics_viewport_set_dimensions(1280, 720);
  graphics_set_multisamples(16);
  
#ifdef OPEN_GL_CPU
  kernels_init_with_cpu();
#else 
  kernels_init_with_opengl();
#endif
  
  asset_manager_handler(kernel_program, "cl", cl_load_file, kernel_program_delete);
  
  load_folder("./kernels/");
  
  particles_init();
  
  load_folder("./resources/podium/");
  load_folder("./resources/particles/");
  
  renderable* r_podium = asset_get("./resources/podium/podium.obj");
  renderable_set_material(r_podium, asset_get("./resources/podium/podium.mat"));
  
  static_object* s_podium = entity_new("podium", static_object);
  s_podium->renderable = r_podium;
  s_podium->position = v3(32, 10, 32);
  
  camera* cam = entity_new("camera", camera);
  cam->position = v3(50, 50, 50);
  cam->target = v3(32, 20, 32);
  
  light* sun = entity_new("sun", light);
  sun->position = v3(50,40,50);
  sun->ambient_color = v3(0.5, 0.5, 0.5);
  sun->diffuse_color = v3_mul(v3_one(), 2);
  sun->specular_color = v3_mul(v3_one(), 5);
  light_set_type(sun, light_type_spot);  
  
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, v2(10,10));
  ui_button_resize(framerate, v2(30,25));
  ui_button_set_label(framerate, "");
  ui_button_disable(framerate);
  
  ui_button* score = ui_elem_new("score", ui_button);
  ui_button_move(score, v2(50, 10));
#ifdef VOLUME_RENDERER
  ui_button_resize(score, v2(125, 25));
  ui_button_set_label(score, "Volume Renderer");
#endif
#ifdef MARCHING_CUBES
  ui_button_resize(score, v2(120, 25));
  ui_button_set_label(score, "Marching Cubes");
#endif
#ifndef VOLUME_RENDERER
#ifndef MARCHING_CUBES
  ui_button_resize(score, v2(80, 25));
  ui_button_set_label(score, "Particles");
#endif
#endif
  ui_button_disable(score);
  
#ifdef VOLUME_RENDERER
  volume_renderer_init();
  volume_renderer_set_camera(cam);
  volume_renderer_set_light(sun);
#endif
 
#ifdef MARCHING_CUBES
  shadow_mapper_init(sun);  
  
  forward_renderer_init();
  forward_renderer_set_camera(cam);
  forward_renderer_set_shadow_light(sun);
  forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
  forward_renderer_add_light(sun);

  marching_cubes_init();
#endif
  
}
Esempio n. 26
0
void sea_init() {
  
  graphics_viewport_set_dimensions(1280, 720);
  graphics_viewport_set_title("Sea");

  camera* cam = entity_new("camera", camera);
  cam->position = vec3_new(50.0, 50.0, 50.0);
  cam->target = vec3_new(0, 5, 0);
  cam->near_clip = 0.1;
  
  light* sun = entity_new("sun", light);
  light_set_type(sun, light_type_spot);
  sun->position = vec3_new(20,23,16);
  sun->ambient_color = vec3_new(0.5, 0.5, 0.5);
  sun->diffuse_color = vec3_new(1.0,  0.894, 0.811);
  sun->specular_color = vec3_mul(vec3_new(1.0,  0.894, 0.811), 4);
  sun->power = 5;
  
  light* backlight = entity_new("backlight", light);
  light_set_type(backlight, light_type_point);
  backlight->position = vec3_new(-22,10,-13);
  backlight->ambient_color = vec3_new(0.2, 0.2, 0.2);
  backlight->diffuse_color = vec3_new(0.729, 0.729, 1.0);
  backlight->specular_color = vec3_mul(vec3_new(0.729, 0.729, 1.0), 1);
  backlight->power = 2;
  
  shadow_mapper_init(sun);  
  
  forward_renderer_init();
  forward_renderer_set_camera(cam);
  forward_renderer_set_shadow_light(sun);
  forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
  forward_renderer_add_light(sun);
  forward_renderer_add_light(backlight);
  
  folder_load(P("./resources/"));
  
  renderable* r_seaplane = asset_get(P("./resources/seaplane.obj"));
  r_seaplane->material = asset_hndl_new(P("./resources/seaplane.mat"));
  
  static_object* s_seaplane = entity_new("seaplane", static_object);
  s_seaplane->renderable = asset_hndl_new_ptr(r_seaplane);
  s_seaplane->scale = vec3_new(3,1,3);
  
  renderable* r_skydome = asset_get(P("./resources/skydome.obj"));
  r_skydome->material = asset_hndl_new_load(P("$CORANGE/shaders/skydome.mat"));
  
  static_object* skydome = entity_new("skydome", static_object);
  skydome->renderable = asset_hndl_new_ptr(r_skydome);
  skydome->position = vec3_new(0, -512, 0);
  skydome->scale = vec3_new(1024, 1024, 1024);
  
  folder_load(P("./resources/corvette/"));
  
  renderable* r_corvette = asset_get(P("./resources/corvette/corvette.obj"));
  r_corvette->material = asset_hndl_new_load(P("./resources/corvette/corvette.mat"));
  
  static_object* s_corvette = entity_new("corvette", static_object);
  s_corvette->renderable = asset_hndl_new_ptr(r_corvette);
  //s_corvette->collision_body = collision_body_new_mesh(asset_get("./resources/corvette/corvette.col"));
  s_corvette->scale = vec3_new(1.5, 1.5, 1.5);
  s_corvette->position = vec3_new(0, 0.5, 0);
  
  static_object* center_sphere = entity_new("center_sphere", static_object);
  center_sphere->position = vec3_new(0, 5, 0);
  //center_sphere->renderable = asset_get("./resources/ball.obj");
  //center_sphere->collision_body = collision_body_new_sphere(sphere_new(v3_zero(), 1.0f));
  
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, vec2_new(10,10));
  ui_button_resize(framerate, vec2_new(30,25));
  ui_button_set_label(framerate, "FRAMERATE");
  ui_button_disable(framerate);
  
}
Esempio n. 27
0
void platformer_init() {
  
  /* Set the viewport title */
  graphics_viewport_set_title("Platformer");
  
  /* Register functions for loading/unloading files with the extension .level */
  asset_handler(level, "level", level_load_file, level_delete);
  
  /* Load Assets */
  folder_load(P("./tiles/"));
  folder_load(P("./backgrounds/"));
  folder_load(P("./sounds/"));
  folder_load(P("./levels/"));
  
  /* Register some handlers for creating and destroying entity types */
  entity_handler(character, character_new, character_delete);
  entity_handler(coin, coin_new, coin_delete);
  
  /* Create our main character */
  character* main_char = entity_new("main_char", character);
  
  /* Add some UI elements */
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, vec2_new(10,10));
  ui_button_resize(framerate, vec2_new(30,25));
  ui_button_set_label(framerate, " ");
  ui_button_disable(framerate);
  
  ui_button* score = ui_elem_new("score", ui_button);
  ui_button_move(score, vec2_new(50, 10));
  ui_button_resize(score, vec2_new(120, 25));
  ui_button_set_label(score, "Score 000000");
  ui_button_disable(score);
  
  ui_button* time = ui_elem_new("time", ui_button);
  ui_button_move(time, vec2_new(180, 10));
  ui_button_resize(time, vec2_new(110, 25));
  ui_button_set_label(time, "Time 000000");
  ui_button_disable(time);
  
  ui_button* victory = ui_elem_new("victory", ui_button);
  ui_button_move(victory, vec2_new(365, 200));
  ui_button_resize(victory, vec2_new(70, 25));
  ui_button_set_label(victory, "Victory!");
  ui_button_disable(victory);
  
  ui_button* new_game_but = ui_elem_new("new_game", ui_button);
  ui_button_move(new_game_but, vec2_new(365, 230));
  ui_button_resize(new_game_but, vec2_new(70, 25));
  ui_button_set_label(new_game_but, "New Game");
  
  
  void on_newgame(ui_button* b, void* unused) {
    reset_game();
  }
  
  ui_button_set_onclick(new_game_but, on_newgame);
  
  /* Reset all the game variables */
  reset_game();
  
}
Esempio n. 28
0
int main_deathmatch()
{
	SDL_Event e;

	SDL_ShowCursor(SDL_DISABLE);

	entity_initialize_list(1024);
	tank_initialize_list(15);

	g_current_level = level_load("leveloneconfig");
	render_set_background(g_current_level->background->image);

	g_music = audio_load_music("sounds/music/backgroundmusic.wav");
	g_sound = audio_load_sound("sounds/digital/digital.wav");
	if(g_music->file.music != NULL)
	{
		slog("Playing Music");
		//audio_play_music(g_music->file.music);
	}
	else
		slog("Could not load music file");

	player = player_spawn("Player", PLAYER);
	v2d_set(player->tank->tracks->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
	v2d_set(player->tank->turret->body->position, SCREEN_WIDTH/2, SCREEN_HEIGHT/2);

	g_now = SDL_GetTicks();

	ui_initialize_deathmatch(rtn_renderer());

	do
	{
		//calculate deltatime
		g_last = g_now;
		g_now = SDL_GetTicks();
		g_deltatime = g_now - g_last;

		render_update(1);
		render_clear();
		entity_all_think();
		entity_all_update();
		player_move(player);
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_KEYDOWN)
			{
				if(e.type == SDL_QUIT)
					SDL_Quit();
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 1;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 1;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 1;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 1;
				if(e.key.keysym.sym == SDLK_e)
				{
					tank_weapon_change(player->tank);
					slog("Current weapon: %s", player->tank->currentweapon->name);
				}
				if(e.key.keysym.sym == SDLK_p)
				{
					audio_play_sound(g_sound->file.sound);
				}
				if(e.key.keysym.sym == SDLK_f)
				{
					Entity *sonar;
					sonar = sonar_new(sonar = entity_new(SONAR, NULL), 3.0, player->tank);
				}
				if(e.key.keysym.sym == SDLK_g)
				{
					tank_weapon_fire(player->tank);
				}
				if(e.key.keysym.sym == SDLK_h)
					player->tank->health -= 5;
				if(e.key.keysym.sym == SDLK_j)
					player->tank->armour -= 5;
				if(e.key.keysym.sym == SDLK_SPACE)
				{
					if(player->tank->is_hidden)
						player->tank->is_hidden = 0;
					else
						player->tank->is_hidden = 1;

					tank_sprite_change(player->tank);
				}
				if(e.key.keysym.sym == SDLK_ESCAPE)
				{
					playclicked = 0;
					entity_close_list();
					tank_close_list();
					player_close_list();
					currentstate = MAINMENU;
				}
			}
			if(e.type == SDL_KEYUP)
			{
				if(e.key.keysym.sym == SDLK_w)
					player->keysHeld.W = 0;
				if(e.key.keysym.sym == SDLK_s)
					player->keysHeld.S = 0;
				if(e.key.keysym.sym == SDLK_a)
					player->keysHeld.A = 0;
				if(e.key.keysym.sym == SDLK_d)
					player->keysHeld.D = 0;
			}
		}
		if(g_deltatime < 32)
			SDL_Delay(32-g_deltatime);
	} while(currentstate == DEATHMATCH);

	return 0;
}
Esempio n. 29
0
int main(int argc, char **argv) {
  
  #ifdef _WIN32
    FILE* ctt = fopen("CON", "w" );
    FILE* fout = freopen( "CON", "w", stdout );
    FILE* ferr = freopen( "CON", "w", stderr );
  #endif
  
  corange_init("../../assets_core");
  
  graphics_viewport_set_title("Teapot");
  graphics_viewport_set_size(1280, 720);
  
  camera* cam = entity_new("camera", camera);
  cam->position = vec3_new(5, 5, 5);
  cam->target =  vec3_new(0, 0, 0);
  
  teapot_shader = asset_hndl_new_load(P("./assets/teapot.mat"));
  teapot_object = asset_hndl_new_load(P("./assets/teapot.obj"));
  
  int running = 1;
  SDL_Event e = {0};
  
  while(running) {
    
    frame_begin();
    
    camera* cam = entity_get("camera");
    
    while(SDL_PollEvent(&e)) {
      switch(e.type){
      case SDL_KEYDOWN:
      case SDL_KEYUP:
        if (e.key.keysym.sym == SDLK_ESCAPE) { running = 0; }
        if (e.key.keysym.sym == SDLK_PRINTSCREEN) { graphics_viewport_screenshot(); }
        if (e.key.keysym.sym == SDLK_r &&
            e.key.keysym.mod == KMOD_LCTRL) {
            asset_reload_all();
        }
        break;
      case SDL_QUIT:
        running = 0;
        break;
      }
      camera_control_orbit(cam, e);
      ui_event(e);
    }
    
    ui_update();
    
    glClearColor(0.25, 0.25, 0.25, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    
    shader_program* shader = material_first_program(asset_hndl_ptr(&teapot_shader));
    shader_program_enable(shader);
    shader_program_set_mat4(shader, "world", mat4_id());
    shader_program_set_mat4(shader, "view", camera_view_matrix(cam));
    shader_program_set_mat4(shader, "proj", camera_proj_matrix(cam));
      
    shader_program_set_texture(shader, "cube_beach", 0, asset_hndl_new_load(P("$CORANGE/water/cube_sea.dds")));
    shader_program_set_vec3(shader, "camera_direction", camera_direction(cam));
    
    renderable* r = asset_hndl_ptr(&teapot_object);
    
    for(int i=0; i < r->num_surfaces; i++) {
      
      renderable_surface* s = r->surfaces[i];
      
      int mentry_id = min(i, ((material*)asset_hndl_ptr(&r->material))->num_entries-1);
      material_entry* me = material_get_entry(asset_hndl_ptr(&r->material), mentry_id);
      
      glBindBuffer(GL_ARRAY_BUFFER, s->vertex_vbo);
      
      shader_program_enable_attribute(shader, "vPosition",  3, 18, (void*)0);
      shader_program_enable_attribute(shader, "vNormal",    3, 18, (void*)(sizeof(float) * 3));
      //shader_program_enable_attribute(shader, "vTangent",   3, 18, (void*)(sizeof(float) * 6));
      //shader_program_enable_attribute(shader, "vBinormal",  3, 18, (void*)(sizeof(float) * 9));
      //shader_program_enable_attribute(shader, "vTexcoord",  2, 18, (void*)(sizeof(float) * 12));
      
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->triangle_vbo);
        glDrawElements(GL_TRIANGLES, s->num_triangles * 3, GL_UNSIGNED_INT, (void*)0);
      
      shader_program_disable_attribute(shader, "vPosition");
      shader_program_disable_attribute(shader, "vNormal");
      //shader_program_disable_attribute(shader, "vTangent");
      //shader_program_disable_attribute(shader, "vBinormal");
      //shader_program_disable_attribute(shader, "vTexcoord");
      
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
      glBindBuffer(GL_ARRAY_BUFFER, 0);

    }
  
    shader_program_disable(shader);
    
    glDisable(GL_DEPTH_TEST);
    ui_render();
    
    graphics_swap();
    
    frame_end();
  }
  
  corange_finish();
  
  return 0;
  
}