void engine_init_player ( Context* context , Engine* engine , Player* player , int centre_x , int centre_y , Bitmap** anims ) { vertex* v; player->anims = anims; v = vertex_create( centre_x - anims[0]->w / 2 , centre_y - anims[0]->h / 2 , anims[0] ); engine->player_tbl[engine->tbl_count] = player; v->id = engine->tbl_count; engine->tbl_count++; context->video[2] = vertex_buffer_push(context->video[2], v); player->v_buf = context->video[2]->prev; player->flashing = 0; player->hp = ENEMY_HP; player->x = &v->x; player->y = &v->y; player->target_x = -1; player->target_y = -1; player->real_x = FIXED_FROM_INT(v->x); player->real_y = FIXED_FROM_INT(v->y); player->vector_x = FIXED_FROM_INT(0); player->vector_y = FIXED_FROM_INT(0); player->anim = 0; player->recalculate = 1; player->ticks_seen = -1; player->shot_field = 0; player->shot_ticks = 0; player->shot_bufs = (vertex_buffer**) malloc(ENEMY_MAX_SHOTS * sizeof(vertex_buffer*)); int i = 0; for (; i < ENEMY_MAX_SHOTS; i++) { v = vertex_create(0, 0, NULL); context->video[1] = vertex_buffer_push(context->video[1], v); player->shot_bufs[i] = context->video[1]->prev; } }
void process_mouse_events(int button, int state, int x, int y) { if (_polygone_closed) return; float mouse_x; float mouse_y; vertex* clicked_vertex; if((state == GLUT_UP) && (button == GLUT_LEFT_BUTTON)) { windowpos_to_glpos(WINDOW_WIDTH, WINDOW_HEIGHT, x, y, &mouse_x, &mouse_y); //cherche un point déjà saisie proche de l'emplacement de la souris clicked_vertex = vertexring_findbycoord(_vring, mouse_x, mouse_y, CLIC_SENSITIVITY); //s'il n'est pas trop proche d'un ancien point: if (!clicked_vertex) { _vring = vertexring_enqueue(_vring, vertex_create(mouse_x, mouse_y), VR_FORWARD); printf("Nouveau point ajouté\r\n"); printf("--- Points courants ---\r\n"); vertexring_print(_vring, VR_FORWARD); printf("-----------------------\r\n"); } else if (clicked_vertex == _vring->v) { _polygone_closed = 1; printf("Polygone saisi\r\n"); vertexring_save(_vring, _optex_filename); printf("Polygone sauvegardé dans le fichier '%s'\r\n", _optex_filename); } } }
vertex_buffer* engine_gen_tilemap ( Context* context , Bitmap* bmp , Bitmap* tile , int h , int w ) { int bmp_h, bmp_w, x, y; vertex* v; bmp_h = h + (tile->h - (h % tile->h)); bmp_w = w + (tile->w - (w % tile->w)); bmp = (Bitmap*) malloc(sizeof(Bitmap)); bmp->w = bmp_w; bmp->h = bmp_h; bmp->bits = (uint16_t*) malloc(bmp_h * bmp_w * sizeof(uint16_t)); // Stitch the tiles together for (y = 0; y < bmp_h; y++) { for (x = 0; x < bmp_w; x+= tile->w) { memmove( bmp->bits + x + y * bmp_w , tile->bits + (y % tile->h) * tile->w , tile->w * sizeof(uint16_t) ); } } v = vertex_create(0, 0, bmp); context->video[0] = vertex_buffer_push(context->video[0], v); return context->video[0]->prev; }
void engine_player_hit (Engine* engine) { Player* player = engine->player; Context* context = (Context*) engine->context; vertex* v; char* game_over = "GAME OVER"; int tmp = *engine->shield; int i = 0; tmp -= 10; if (tmp <= 0) { tmp = 0; engine_create_explosion( *player->x + player->v_buf->v->bitmap->w / 2 , *player->y + player->v_buf->v->bitmap->h / 2 , engine ); player->v_buf->v = NULL; for (; i < strlen(game_over); i++) { v = vertex_create( (engine->max_w / 2 - (strlen(game_over) / 2) * GLYPH_SIZE) + (i * GLYPH_SIZE) , SCREEN_TOP + engine->max_h / 2 - GLYPH_SIZE / 2 , context->glyphs->map[char2index(game_over[i])] ); context->video[1] = vertex_buffer_push(context->video[1], v); } } *engine->shield = tmp; }
Vector * cross_product(Vector vectorA, Vector vectorB) { /* FIRST DRAFT - SOMEWHAT TEMPORARY */ float i = vectorA.Y * vectorB.Z - vectorA.Z * vectorB.Y; float j = vectorA.X * vectorB.Z - vectorA.Z * vectorB.X; float k = vectorA.X * vectorB.Y - vectorA.Y * vectorB.X; Vector * cross_product = vertex_create( i, j, k); return(cross_product); }
vertex *vertex_pool_get(vertex_pool *pool) { if(vertex_stack_empty(pool->stack)) { return vertex_create(); } else { return vertex_stack_pop(pool->stack); } }
vertex_s *vertex_copy(vertex_s *v) { vertex_s *nv; // Sanity check parameters. assert(v); nv = vertex_create(); memcpy(nv, v, sizeof(vertex_s)); if (v->tag) nv->tag = strdup(v->tag); // Return "vertex_s *" return nv; }
vertex_s *str2vertex(char *s) { vertex_s *v; // Sanity check parameters. assert(s); v = vertex_create(); if (!v) return NULL; vertex_set_tag(v, "AUTO"); sscanf(s, "[%lf,%lf,%lf]", &v->x, &v->y, &v->z); // Return "vertex_s *" return v; }
void calculateVertsFromVector(Quad *q, int x1, int y1, int z1, int x3, int y3, int z3) { int nPlanes = 0; int plane = 0; if (x1 == x3) { plane = PLANE_X; nPlanes++; } if (y1 == y3) { plane = PLANE_Y; nPlanes++; } if (z1 == z3) { plane = PLANE_Z; nPlanes++; } int swapY = 0; int swapX = 0; int swapZ = 0; if (plane == PLANE_X) { if (y1 < y3) swapY = 1; if (z1 < z3) swapZ = 1; } if (plane == PLANE_Y) { if (x1 < x3) swapX = 1; if (z1 < z3) swapZ = 1; } if (plane == PLANE_Z) { if (x1 < x3) swapX = 1; if (y1 < y3) swapY = 1; } if (swapX) { int tx = x1; x1 = x3; x3 = tx; } if (swapY) { int ty = y1; y1 = y3; y3 = ty; } if (swapZ) { int tz = z1; z1 = z3; z3 = tz; } // calculate remaining points Vertex **p = q->tmpVerts; p[0] = vertex_create(x1, y1, z1); p[2] = vertex_create(x3, y3, z3); if (plane == PLANE_X) { p[1] = vertex_create(x1, y1, z3); p[3] = vertex_create(x1, y3, z1); } if (plane == PLANE_Y) { p[1] = vertex_create(x1, y1, z3); p[3] = vertex_create(x3, y1, z1); } if (plane == PLANE_Z) { p[1] = vertex_create(x3, y1, z1); p[3] = vertex_create(x1, y3, z1); } }
Engine* engine_init_level (Context* context) { Engine* engine = (Engine*) malloc(sizeof(Engine)); engine->context = context; engine->tiles = load_tiles(context); int h, w, i; h = context->video[0]->head->v->bitmap->h; w = context->video[0]->head->v->bitmap->w; engine->partition_len = ceil((((double) w) / BOX_SIZE)) * ceil((((double) h) / BOX_SIZE)); engine->partitions = (Node**) malloc(engine->partition_len * sizeof(Node*)); memset(engine->partitions, 0, engine->partition_len * sizeof(Node*)); engine->flash_anims = linked_list_init(); for (i = 0; i < engine->partition_len; i++) { engine->partitions[i] = linked_list_init(); } engine->max_h = h; engine->max_w = w; // Clear any and all vertexes left on the screen (including the background) clear_buffers(context); engine->loading_bufs = engine_create_loading(context, h, w); engine_init_bg(engine, h, w); engine_inc_loading(engine); engine->explosion = engine_load_explosion(context, engine); engine->explosions = linked_list_init(); engine->explo_field = 0; engine->tbl_count = 0; engine->player_tbl = (Player**) malloc(TBL_MAX * sizeof(Player*)); engine->player = engine_load_player( context , engine , "ship" , w / 2 , h - SCREEN_TOP ); engine_inc_loading(engine); engine->shot_bufs = engine_init_shots(context, engine, h); engine->shot_field = 0ULL; engine->enemy_sprites = engine_load_enemies(context, engine); engine->shield_bufs = engine_init_shield(context, engine); engine->score_bufs = engine_init_score(context, h); engine->enemies = (Player**) malloc(MAX_ENEMIES * sizeof(Player*)); memset(engine->enemies, 0, MAX_ENEMIES * sizeof(Player*)); engine->enemy_field = 0; context->game_state = TYRIAN_GAME_LEVEL; engine_clear_loading(context, engine); #if DEBUG vertex* v; fps = (vertex_buffer**) malloc(6 * sizeof(vertex_buffer*)); char str[7] = "FPS 00"; for (i = 0; i < 6; i++) { v = vertex_create( w - GLYPH_SIZE * (6 - i) , SCREEN_TOP , context->glyphs->map[char2index(str[i])] ); context->video[1] = vertex_buffer_push(context->video[1], v); fps[i] = context->video[1]->prev; } #endif return engine; }
int main() { Vertex* vertex = vertex_create(8); vertex_destroy(vertex); return 0; }