| 254 ); |
254 ); |
| 255 |
255 |
| 256 game.field->tile_data[x][y] = GAME_FIELD_TILE_EXISTS_FLAG; |
256 game.field->tile_data[x][y] = GAME_FIELD_TILE_EXISTS_FLAG; |
| 257 game.field->nodes[x][y] = tile; |
257 game.field->nodes[x][y] = tile; |
| 258 |
258 |
| 259 asc_scene_node_link(node, tile); |
259 asc_scene_node_add(node, tile); |
| 260 } |
260 } |
| 261 } |
261 } |
| 262 asc_scene_node_set_zindex(node, -2); |
262 asc_scene_node_set_zindex(node, -2); |
| 263 asc_scene_add_node(MAIN_SCENE, node); |
263 asc_scene_add_node(MAIN_SCENE, node); |
| 264 } |
264 } |
| 272 asc_uniform_loc map_albedo; |
272 asc_uniform_loc map_albedo; |
| 273 asc_uniform_loc map_color; |
273 asc_uniform_loc map_color; |
| 274 asc_uniform_loc color; |
274 asc_uniform_loc color; |
| 275 } PlayerShader; |
275 } PlayerShader; |
| 276 |
276 |
| 277 static void player_shader_init(AscShaderProgram *p, cx_attr_unused int flags) { |
277 static void player_shader_init(AscShaderProgram *p, CX_UNUSED int flags) { |
| 278 asc_shader_set_uniform_loc_by_name(p, PlayerShader, map_albedo); |
278 asc_shader_set_uniform_loc_by_name(p, PlayerShader, map_albedo); |
| 279 asc_shader_set_uniform_loc_by_name(p, PlayerShader, map_color); |
279 asc_shader_set_uniform_loc_by_name(p, PlayerShader, map_color); |
| 280 asc_shader_set_uniform_loc_by_name(p, PlayerShader, color); |
280 asc_shader_set_uniform_loc_by_name(p, PlayerShader, color); |
| 281 } |
281 } |
| 282 |
282 |
| 283 static AscShaderProgram *player_shader_create(cx_attr_unused int unused) { |
283 static AscShaderProgram *player_shader_create(CX_UNUSED int unused) { |
| 284 return asc_shader_create((AscShaderCodes) { |
284 return asc_shader_create((AscShaderCodes) { |
| 285 .vtx = {.source_file = "sprite_vtx.glsl"}, |
285 .vtx = {.source_file = "sprite_vtx.glsl"}, |
| 286 .frag = {.source_file = "player.glsl",}, |
286 .frag = {.source_file = "player.glsl",}, |
| 287 }, sizeof(PlayerShader), player_shader_init, 0); |
287 }, sizeof(PlayerShader), player_shader_init, 0); |
| 288 } |
288 } |
| 482 player->view_distance = 7.f; // start with 7 tiles |
482 player->view_distance = 7.f; // start with 7 tiles |
| 483 player->speed = 3.f; // start with 3 tiles/sec |
483 player->speed = 3.f; // start with 3 tiles/sec |
| 484 player->number = 1; |
484 player->number = 1; |
| 485 player->health = 100; |
485 player->health = 100; |
| 486 player->color = ASC_RGB(1, 0, 0); |
486 player->color = ASC_RGB(1, 0, 0); |
| 487 player->trace = cxLinkedListCreateSimple(sizeof(asc_vec2u)); |
487 player->trace = cxLinkedListCreate(NULL, sizeof(asc_vec2u)); |
| 488 cxDefineDestructor(player->trace, player_trace_release_tile); |
488 cxSetDestructor(player->trace, player_trace_release_tile); |
| 489 node->draw_func = player_draw; |
489 node->draw_func = player_draw; |
| 490 node->user_data_free_func = (cx_destructor_func2)player_destroy; |
490 node->user_data_free_func = (cx_destructor_func2)player_destroy; |
| 491 |
491 |
| 492 // add behaviors |
492 // add behaviors |
| 493 asc_behavior_add(node, player_main_behavior, .always_enabled = true); |
493 asc_behavior_add(node, player_main_behavior, .always_enabled = true); |