int main (int argc, char ** argv) { setup_windowing(); int width = wins_globals->server_width; int height = wins_globals->server_height; win_width = width; win_height = height; /* Do something with a window */ window_t * wina = window_create(0,0, width, height); assert(wina); window_reorder (wina, 0); ctx = init_graphics_window_double_buffer(wina); draw_fill(ctx, rgb(127,127,127)); flip(ctx); #if 1 printf("Loading background...\n"); init_sprite(0, "/usr/share/login-background.bmp", NULL); printf("Background loaded.\n"); draw_sprite_scaled(ctx, sprites[0], 0, 0, width, height); #endif #if 0 init_sprite(1, "/usr/share/bs.bmp", "/usr/share/bs-alpha.bmp"); draw_sprite_scaled(sprites[1], center_x(sprites[1]->width), center_y(sprites[1]->height), sprites[1]->width, sprites[1]->height); #endif flip(ctx); while (1) { syscall_yield(); //syscall_wait(wins_globals->server_pid); } #if 0 window_destroy(window); // (will close on exit) teardown_windowing(); #endif return 0; }
void init_entity(Entity* entity) { entity->id = 0; entity->body_id = 0; init_sprite(&entity->sprite); entity->counter = 0; entity->area = NULL; entity->event_on_activate = NULL; entity->event_on_activate_count = 0; }
void load_resources(ALLEGRO_FONT **font, intro_resource_struct *intro_resources, object *objects) { *font = load_packed_font(Arial_ttf, Arial_ttf_size, 36); if (!(*font)) die("couldn't load font\n"); intro_resources->font = load_packed_font(Arial_ttf, Arial_ttf_size, 20); intro_resources->instructions1 = load_packed_bitmap(instructions1_png, instructions1_png_size); intro_resources->instructions2 = load_packed_bitmap(instructions2_png, instructions2_png_size); enum object_ctr i; for (i = 0; i < LAST_MOVER; i++) init_sprite(&objects[i], i); /* not handled above */ init_sprite(&objects[TREE], TREE); init_sprite(&objects[GROUND], GROUND); objects[GROUND].x_pos = 0; objects[GROUND].y_pos = CANVAS_HEIGHT-1 - al_get_bitmap_height(objects[GROUND].sprite1) + 1; }
/*************************************************** エントリ ***************************************************/ int main (void) { // ゲームパックウェイト&キャッシュ *((vu16 *) 0x04000204) = 0x4317; // BG初期化 init_bg (); // スプライト初期化 init_sprite (); // キー初期化 init_key (); // サウンド初期化 DirectSoundInitialize (); // キャラクタ初期化 init_sprite_chr (); // ハイスコア初期化 init_hiscore (); // ゲーム初期化 init_game (); // タイトル init_title (); // 割り込み初期化 irqInit (); // サウンド用ハンドラ MUSIC / SE irqSet (IRQ_TIMER0, IRQ_Music); irqSet (IRQ_TIMER1, IRQ_Sound); irqEnable (IRQ_VBLANK | IRQ_TIMER0 | IRQ_TIMER1); // タイトル PlayMusic (MUSIC_TITLE, PLAY_LOOP_ON); // メインループ while (1) { // キー入力 scanKeys (); // ゲーム本体 game (); // 割り込み待ち VBlankIntrWait (); } }
void main_menu_update() { game_set_scale(2.0f); renderer_start(); Sprite s; init_sprite(&s); s.size = v2(15 * 16, 4 * 16); s.position = v2(16 + s.size.x / 2, game->size.y / 2 - s.size.y / 2); s.texture = Get_Texture_Coordinates( renderer->texture_width - s.size.x, 2 * 16, s.size.x, s.size.y); renderer_push_sprite(&s); if(gui_add_button(v2(40 + 16, s.position.y + s.size.y / 2 + 16), "Start")) { game->state = Game_State_Play; } renderer_draw(); }
EnemyView::EnemyView(sf::RenderWindow* a) : SpriteView(a) { std::string file_name = "enemy.png"; init_sprite(file_name); }
int demo_2() { static struct tmu_td tmu_badclouds, tmu_badfactory, tmu_clearscreen; static struct tmu_vertex badclouds_src_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badclouds_dst_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badfactory_src_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex badfactory_dst_vtx[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static short int black = 0x0000; static struct tmu_vertex src_clr_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; static struct tmu_vertex dst_clr_vertices[TMU_MESH_MAXSIZE][TMU_MESH_MAXSIZE]; int quit = 0 , x = 0; //unsigned int x , y ; //unsigned short int * vga_position; //Initialization sprites_init(); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,0); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,1); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,2); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,3); sprites_load(badclouds_raw,badclouds_raw_len,0x001F,138,100,4); sprites_load(badfactory_raw,badfactory_raw_len,0x001F,100,100,0); /* debug_sprite(&sprite_data[0]); debug_sprite(&sprite_data[1]); debug_sprite(&sprite_data[2]); debug_sprite(&sprite_data[3]); debug_sprite(&sprite_data[4]); */ init_sprite(&badclouds_src_vtx[0][0] , &badclouds_dst_vtx[0][0] , &sprite_data[0]); init_sprite(&badfactory_src_vtx[0][0] , &badfactory_dst_vtx[0][0] , &sprite_data[5]); /* for ( x = 0; x <= HMESHLAST; x++) { for ( y = 0; y <= VMESHLAST; y++) { badclouds_src_vtx[x][y].x = x * 138; badclouds_src_vtx[x][y].y = y * 100; badclouds_src_vtx[x][y].x = x * 138; badclouds_src_vtx[x][y].y = y * 100; } } */ src_clr_vertices[0][0].x = 0; src_clr_vertices[0][0].y = 0; src_clr_vertices[1][0].x = 640; src_clr_vertices[1][0].y = 0; src_clr_vertices[0][1].x = 0; src_clr_vertices[0][1].y = 480; src_clr_vertices[1][1].x = 640; src_clr_vertices[1][1].y = 480; dst_clr_vertices[0][0].x = 0 - 30; dst_clr_vertices[0][0].y = 0 - 23; dst_clr_vertices[1][0].x = 640 + 30 ; dst_clr_vertices[1][0].y = 0 - 23; dst_clr_vertices[0][1].x = 0 - 30; dst_clr_vertices[0][1].y = 480 + 23; dst_clr_vertices[1][1].x = 640 + 30; dst_clr_vertices[1][1].y = 480 + 23; //tmu_clearscreen.flags = 0; tmu_badclouds.flags = TMU_CTL_CHROMAKEY; tmu_clearscreen.hmeshlast = 1; tmu_clearscreen.vmeshlast = 1; tmu_clearscreen.brightness = 60; tmu_clearscreen.chromakey = 0; tmu_clearscreen.srcmesh = &src_clr_vertices[0][0]; tmu_clearscreen.srchres = vga_hres; tmu_clearscreen.srcvres = vga_vres; tmu_clearscreen.dstmesh = &dst_clr_vertices[0][0]; tmu_clearscreen.dsthres = vga_hres; tmu_clearscreen.dstvres = vga_vres; tmu_clearscreen.profile = 0; tmu_clearscreen.callback = tmu_complete; tmu_clearscreen.user = NULL; tmu_badclouds.flags = TMU_CTL_CHROMAKEY; tmu_badclouds.hmeshlast = HMESHLAST; tmu_badclouds.vmeshlast = VMESHLAST; tmu_badclouds.brightness = 62; tmu_badclouds.chromakey = CHROMAKEY; tmu_badclouds.srcmesh = &badclouds_src_vtx[0][0]; tmu_badclouds.srchres = 138; tmu_badclouds.srcvres = 100; tmu_badclouds.dstmesh = &badclouds_dst_vtx[0][0]; tmu_badclouds.dsthres = vga_hres; tmu_badclouds.dstvres = vga_vres; tmu_badclouds.profile = 0; tmu_badclouds.callback = tmu_complete; tmu_badclouds.user = NULL; tmu_badfactory.flags = TMU_CTL_CHROMAKEY; tmu_badfactory.hmeshlast = HMESHLAST; tmu_badfactory.vmeshlast = VMESHLAST; tmu_badfactory.brightness = 62; tmu_badfactory.chromakey = CHROMAKEY; tmu_badfactory.srcmesh = &badclouds_src_vtx[0][0]; tmu_badfactory.srchres = 100; tmu_badfactory.srcvres = 100; tmu_badfactory.dstmesh = &badclouds_dst_vtx[0][0]; tmu_badfactory.dsthres = vga_hres; tmu_badfactory.dstvres = vga_vres; tmu_badfactory.profile = 0; tmu_badfactory.callback = tmu_complete; tmu_badfactory.user = NULL; x = 0; frames = 0; while(quit < 10) { tmu_clearscreen.srcfbuf = vga_lastbuffer; tmu_clearscreen.dstfbuf = vga_backbuffer; tmu_wait = 0; tmu_submit_task(&tmu_clearscreen); while(!tmu_wait); //update_sprite(tmu_badclouds.dstmesh ,&sprite_data[x/20], 320 , 240 , frames); if (x/40 == 5) { init_sprite(tmu_badfactory.srcmesh,tmu_badclouds.dstmesh ,&sprite_data[x/40]); scale_sprite(tmu_badfactory.dstmesh , (100 + COS[frames])/10 , (100 + COS[frames])/10 ); rotate_sprite(tmu_badfactory.dstmesh , frames); move_sprite(tmu_badfactory.dstmesh , 320 , 240); tmu_badfactory.srcfbuf = sprite_data[x/40].data; tmu_badfactory.dstfbuf = vga_backbuffer; } else { init_sprite(tmu_badclouds.srcmesh,tmu_badclouds.dstmesh ,&sprite_data[x/40]); scale_sprite(tmu_badclouds.dstmesh , (100 + COS[frames])/10 , (100 + COS[frames])/10 ); rotate_sprite(tmu_badclouds.dstmesh , frames); move_sprite(tmu_badclouds.dstmesh , 320 , 240); tmu_badclouds.srcfbuf = sprite_data[x/40].data; tmu_badclouds.dstfbuf = vga_backbuffer; } /* tmu_clearscreen.srcfbuf = &black; tmu_clearscreen.dstfbuf = vga_backbuffer; tmu_wait = 0; tmu_submit_task(&tmu_clearscreen); while(!tmu_wait); */ tmu_wait = 0; tmu_submit_task(&tmu_badclouds); while(!tmu_wait); flush_bridge_cache(); vga_swap_buffers(); // demo_sleep(10); x += 1; frames+=5; if (frames > 360) frames = frames - 360; if (x == 240) {x = 0;quit++;} } return 0; }
void update_world_area(World_Area* area) { game_set_scale(2.0); real movespeed = 800; Vec2 move_impulse = v2(0, 0); if(_check(LEFT, A, State_Pressed)) { move_impulse.x -= movespeed; } if(_check(RIGHT, D, State_Pressed)) { move_impulse.x += movespeed; } if(_check(UP, W, State_Pressed)) { move_impulse.y -= movespeed; } if(_check(DOWN, S, State_Pressed)) { move_impulse.y += movespeed; } if(fabsf(move_impulse.x * move_impulse.y) > 0.01f) { move_impulse *= Math_InvSqrt2; } play_state->current_time = SDL_GetTicks(); real dt = (play_state->current_time - play_state->prev_time) / 1000.0; dt = clamp(dt, 0, 1.2f); play_state->accumulator += dt; play_state->prev_time = play_state->current_time; sim_sort_bodies_on_id(&area->sim); Entity* player_entity = world_area_find_entity(area, 0); Sim_Body* player = player_entity->body; Tile_Info* player_tile = area->map.info + tilemap_get_at(&area->map, player->shape.center); move_impulse *= player_tile->movement_modifier; while(play_state->accumulator >= Time_Step) { play_state->accumulator -= Time_Step; player->velocity += move_impulse; sim_update(&area->sim, &area->map, Time_Step); } Direction old_direction = player_entity->direction; if(move_impulse.y < 0) { player_entity->direction = Direction_North; } else if(move_impulse.y > 0) { player_entity->direction = Direction_South; } if(move_impulse.x < 0) { player_entity->facing = -1; player_entity->direction = Direction_West; } else if(move_impulse.x > 0) { player_entity->facing = 1; player_entity->direction = Direction_East; } if(input->scancodes[SDL_SCANCODE_SPACE] == State_Pressed) { player_entity->direction = old_direction; } Sprite* plr_spr = &player_entity->sprite; int32 player_frame = 0; if(v2_dot(move_impulse, move_impulse) > 0){ player_entity->counter++; player_frame = 1; if(player_entity->counter > 15) { player_frame = 0; if(player_entity->counter > 30) { player_entity->counter = 0; } } } else { player_entity->counter = 0; player_frame = 0; } if(player_entity->facing == -1) { plr_spr->texture = Get_Texture_Coordinates(32 + player_frame * 32, 0, -32, 32); } else if(player_entity->facing == 1) { plr_spr->texture = Get_Texture_Coordinates(0 + player_frame * 32, 0, 32, 32); } Vec2 target = player->shape.center; if(target.x < 0) { world_switch_current_area(play_state->world, area->west); play_state->world_xy.x--; } else if(target.x > area->map.w * Tile_Size) { world_switch_current_area(play_state->world, area->east); play_state->world_xy.x++; } else if(target.y < 0) { world_switch_current_area(play_state->world, area->north); play_state->world_xy.y--; } else if(target.y > area->map.h * Tile_Size) { world_switch_current_area(play_state->world, area->south); play_state->world_xy.y++; } area->offset += (target - area->offset) * 0.1f; area->offset -= game->size * 0.5f; if(area->offset.x < 0) area->offset.x = 0; else if((area->offset.x + game->size.x) > area->map.w * Tile_Size) area->offset.x = area->map.w * Tile_Size - game->size.x; if(area->offset.y < 0) area->offset.y = 0; else if((area->offset.y + game->size.y) > area->map.h * Tile_Size) area->offset.y = area->map.h * Tile_Size - game->size.y; //TODO(will) refactor into own function? /* * Player input code * */ if(input->mouse[SDL_BUTTON_LEFT] == State_Just_Pressed) { Entity* ball_entity = world_area_get_next_entity(area); Sim_Body* ball = ball_entity->body; Vec2 dmouse = v2(input->mouse_x / game->scale, input->mouse_y / game->scale) + area->offset; dmouse -= player->shape.center; real angle = atan2f(dmouse.y, dmouse.x); Vec2 normal = v2(cosf(angle), sinf(angle)); entity_add_event_on_activate(ball_entity, delete_on_activate); ball->damping = 0.9999f; ball->shape.hext = v2(8, 16); ball->shape.center = normal * ball->shape.hw * 4 + player->shape.center; ball->velocity += normal * 2000; ball->shape.hext = v2(8, 6); //ball->flags = Body_Flag_No_Friction; ball_entity->sprite.size = v2(16, 32); ball_entity->sprite.center = v2(0, 10); ball_entity->sprite.texture = Get_Texture_Coordinates(0, 96, 32, 64); } if(input->mouse[SDL_BUTTON_RIGHT] == State_Just_Pressed) { Vec2 dmouse = v2( input->mouse_x / game->scale, input->mouse_y / game->scale) + area->offset; AABB mbb = aabb(dmouse, 0, 0); world_area_synchronize_entities_and_bodies(area); for(isize i = 0; i < area->entities_count; ++i) { Entity* e = area->entities + i; if(aabb_intersect(e->body->shape, mbb)) { if(e->id != 0) { for(isize j = 0; j < e->event_on_activate_count; ++j) { e->event_on_activate[j](e, area); } break; } } } } if(input->scancodes[SDL_SCANCODE_F] == State_Just_Pressed) { //tilemap_set_at(&area->map, player->shape.center, Tile_Dug_Earth); Tile_State* state = tilemap_get_state_at(&area->map, player->shape.center); if(state != NULL) { state->damage++; update_tile_state_at(&area->map, player->shape.center); } } Sprite s; if(input->scancodes[SDL_SCANCODE_SPACE] >= State_Pressed) { init_sprite(&s); s.position = player->shape.center; s.size = v2(16, 16); s.texture = Get_Texture_Coordinates(0, renderer->texture_height - 16, 16, 16); s.color = v4(1, 1, 1, 1); switch(player_entity->direction) { case Direction_North: s.position.y -= s.size.y + player->shape.hh; break; case Direction_South: s.position.y += s.size.y + player->shape.hh; break; case Direction_East: s.position.x += s.size.x + player->shape.hw; break; case Direction_West: s.position.x -= s.size.x + player->shape.hh; break; } if(input->scancodes[SDL_SCANCODE_SPACE] == State_Just_Pressed) { //TODO(will) implement good space queries Sim_Body* touching = sim_query_aabb(&area->sim, aabb(s.position, s.size.x / 2, s.size.y / 2)); if(touching != NULL) { if(!Has_Flag(touching->flags, Body_Flag_Static)) player_entity->held_entity_id = touching->entity_id; } } } else { player_entity->held_entity_id = -1; } char debug_str[256]; if(player_entity->held_entity_id > 0) { Entity* e = world_area_find_entity(area, player_entity->held_entity_id); if(e != NULL) { Sim_Body* b = e->body; Vec2 target = player->shape.center; Vec2 diff = b->shape.hext + player->shape.hext + v2(8, 8); switch(player_entity->direction) { case Direction_North: target.y -= diff.y; break; case Direction_South: target.y += diff.y; break; case Direction_East: target.x += diff.x; break; case Direction_West: target.x -= diff.x; break; } Vec2 impulse = (target - b->shape.center); if(v2_dot(impulse, impulse) > (4 * Tile_Size * Tile_Size)) { player_entity->held_entity_id = -1; } impulse *= 60; { snprintf(debug_str, 256, "T(%.2f %.2f) j(%.2f %.2f)", target.x, target.y, impulse.x, impulse.y); } if(v2_dot(impulse, impulse) < (1000 * 1000)) b->velocity += impulse;// * b->inv_mass; } } renderer->offset = area->offset; area->offset += game->size * 0.5f; // throw a ball renderer_start(); Rect2 screen = rect2( area->offset.x - game->size.x / 2, area->offset.y - game->size.y / 2, game->size.x, game->size.y); isize sprite_count_offset = render_tilemap(&area->map, v2(0,0), screen); for(isize i = 0; i < area->entities_count; ++i) { Entity* e = area->entities + i; Sim_Body* b = sim_find_body(&area->sim, e->body_id); if (b == NULL) continue; e->sprite.position = b->shape.center; //e->sprite.size = v2(b->shape.hw * 2, b->shape.hh * 2); //TODO(will) align entity sprites by their bottom center renderer_push_sprite(&e->sprite); } renderer_push_sprite(&s); renderer_sort(sprite_count_offset); renderer_draw(); renderer->offset = v2(0, 0); game_set_scale(1.0); renderer_start(); char str[256]; isize len = snprintf(str, 256, "X:%d Y:%d Tile: %s", play_state->world_xy.x, play_state->world_xy.y, player_tile->name); render_body_text(str, v2(16, game->size.y - (body_font->glyph_height) - 8), true); render_body_text(debug_str, v2(16, 16), true); renderer_draw(); }
/* Initialize the funt system */ void font_init(SDL_Texture* sprite_sheet) { /* Set up letters and digits */ symbols[0].letter = '0'; symbols[0].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6; symbols[1].letter = '1'; symbols[1].segments = SEGMENT2 | SEGMENT3; symbols[2].letter = '2'; symbols[2].segments = SEGMENT1 | SEGMENT2 | SEGMENT4 | SEGMENT5 | SEGMENT7 | SEGMENT9; symbols[3].letter = '3'; symbols[3].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT7 | SEGMENT9; symbols[4].letter = '4'; symbols[4].segments = SEGMENT2 | SEGMENT3 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[5].letter = '5'; symbols[5].segments = SEGMENT1 | SEGMENT3 | SEGMENT4 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[6].letter = '6'; symbols[6].segments = SEGMENT1 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[7].letter = '7'; symbols[7].segments = SEGMENT1 | SEGMENT12 | SEGMENT14; symbols[8].letter = '8'; symbols[8].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[9].letter = '9'; symbols[9].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[10].letter = ' '; symbols[10].segments = SEGMENT0; symbols[11].letter = 'A'; symbols[11].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[12].letter = 'B'; symbols[12].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT8 | SEGMENT9 | SEGMENT10; symbols[13].letter = 'C'; symbols[13].segments = SEGMENT1 | SEGMENT4 | SEGMENT5 | SEGMENT6; symbols[14].letter = 'D'; symbols[14].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT8 | SEGMENT10; symbols[15].letter = 'E'; symbols[15].segments = SEGMENT1 | SEGMENT4 | SEGMENT5 | SEGMENT6 | SEGMENT7; symbols[16].letter = 'F'; symbols[16].segments = SEGMENT1 | SEGMENT5 | SEGMENT6 | SEGMENT7; symbols[17].letter = 'G'; symbols[17].segments = SEGMENT1 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6 | SEGMENT9; symbols[18].letter = 'H'; symbols[18].segments = SEGMENT2 | SEGMENT3 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[19].letter = 'I'; symbols[19].segments = SEGMENT1 | SEGMENT4 | SEGMENT8 | SEGMENT10; symbols[20].letter = 'J'; symbols[20].segments = SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5; symbols[21].letter = 'K'; symbols[21].segments = SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT12 | SEGMENT13; symbols[22].letter = 'L'; symbols[22].segments = SEGMENT4 | SEGMENT5 | SEGMENT6; symbols[23].letter = 'M'; symbols[23].segments = SEGMENT2 | SEGMENT3 | SEGMENT5 | SEGMENT6 | SEGMENT11 | SEGMENT12; symbols[24].letter = 'N'; symbols[24].segments = SEGMENT2 | SEGMENT3 | SEGMENT5 | SEGMENT6 | SEGMENT11 | SEGMENT13; symbols[25].letter = 'O'; symbols[25].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5 |SEGMENT6; symbols[26].letter = 'P'; symbols[26].segments = SEGMENT1 | SEGMENT2 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9; symbols[27].letter = 'Q'; symbols[27].segments = SEGMENT1 | SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6 | SEGMENT13; symbols[28].letter = 'R'; symbols[28].segments = SEGMENT1 | SEGMENT2 | SEGMENT5 | SEGMENT6 | SEGMENT7 | SEGMENT9 | SEGMENT13; symbols[29].letter = 'S'; symbols[29].segments = SEGMENT1 | SEGMENT4 | SEGMENT11 | SEGMENT13; symbols[30].letter = 'T'; symbols[30].segments = SEGMENT1 | SEGMENT8 | SEGMENT10; symbols[31].letter = 'U'; symbols[31].segments = SEGMENT2 | SEGMENT3 | SEGMENT4 | SEGMENT5 | SEGMENT6; symbols[32].letter = 'V'; symbols[32].segments = SEGMENT5 | SEGMENT6 | SEGMENT12 | SEGMENT14; symbols[33].letter = 'W'; symbols[33].segments = SEGMENT2 | SEGMENT3 | SEGMENT5 | SEGMENT6 | SEGMENT13 | SEGMENT14; symbols[34].letter = 'X'; symbols[34].segments = SEGMENT11 | SEGMENT12 | SEGMENT13 | SEGMENT14; symbols[35].letter = 'Y'; symbols[35].segments = SEGMENT10 | SEGMENT11 | SEGMENT12; symbols[36].letter = 'Z'; symbols[36].segments = SEGMENT1 | SEGMENT4 | SEGMENT12 | SEGMENT14; symbols[37].letter = '<'; symbols[37].segments = SEGMENT12 | SEGMENT13; symbols[38].letter = '>'; symbols[38].segments = SEGMENT11 | SEGMENT14; symbols[39].letter = '^'; symbols[39].segments = SEGMENT13 | SEGMENT14; symbols[40].letter = 'v'; symbols[40].segments = SEGMENT11 | SEGMENT12; symbols[41].letter = ':'; symbols[41].segments = SEGMENT8 | SEGMENT10; symbols[42].letter = '-'; symbols[42].segments = SEGMENT7 | SEGMENT9; symbols[43].letter = ','; symbols[43].segments = SEGMENT14; /* Set up the sprites for the segments */ segments[0] = init_sprite(sprite_sheet, 100, 0, 25, 25); segments[1] = init_sprite(sprite_sheet, 125, 0, 25, 25); segments[2] = init_sprite(sprite_sheet, 150, 0, 25, 25); segments[3] = init_sprite(sprite_sheet, 175, 0, 25, 25); segments[4] = init_sprite(sprite_sheet, 200, 0, 25, 25); segments[5] = init_sprite(sprite_sheet, 225, 0, 25, 25); segments[6] = init_sprite(sprite_sheet, 250, 0, 25, 25); segments[7] = init_sprite(sprite_sheet, 275, 0, 25, 25); segments[8] = init_sprite(sprite_sheet, 75, 25, 25, 25); segments[9] = init_sprite(sprite_sheet, 100, 25, 25, 25); segments[10] = init_sprite(sprite_sheet, 125, 25, 25, 25); segments[11] = init_sprite(sprite_sheet, 150, 25, 25, 25); segments[12] = init_sprite(sprite_sheet, 175, 25, 25, 25); segments[13] = init_sprite(sprite_sheet, 200, 25, 25, 25); segments[14] = init_sprite(sprite_sheet, 75, 0, 25, 25); }
//--------- Begin of function Unit::init ---------// // // <int> unitId - the id. of the unit // <int> nationRecno - the recno of nation // [int] rankId - rank id. of the unit (none for non-human unit) // [int] unitLoyalty - loyalty of the unit (none for non-human unit) // [int] startXLoc, startYLoc - the starting location of the unit // (if startXLoc < 0, this is a unit for hire, and is not a unit of the game yet. init_sprite() won't be called for this unit) // (default: -1, -1) // // Note: sprite_recno must be initialized first before calling Unit::init() // void Unit::init(int unitId, int nationRecno, int rankId, int unitLoyalty, int startXLoc, int startYLoc) { //------------ set basic vars -------------// nation_recno = (char) nationRecno; rank_id = rankId; // rank_id must be initialized before init_unit_id() as init_unit_id() may overwrite it if( rank_id == RANK_GENERAL || rank_id == RANK_KING ) { err_when( team_info ); team_info = (TeamInfo*) mem_add( sizeof(TeamInfo) ); memset( team_info, 0, sizeof(TeamInfo) ); } init_unit_id(unitId); race_id = (char) unit_res[unit_id]->race_id; //------- init unit name ---------// if( is_human() && unit_id != UNIT_WAGON ) { name_id = race_res[race_id]->get_new_name_id(); } else if( is_monster() ) { name_id = monster_res.get_new_name_id(); } else //---- init non-human unit series no. ----// { if( nation_recno ) name_id = ++nation_array[nation_recno]->last_unit_name_id_array[unit_id-1]; else name_id = 0; } // ###### begin Gilbert 23/2 ######// unique_id = misc.rand_long(); // ###### end Gilbert 23/2 ######// //---------- init other vars ----------// err_when( unitLoyalty < 0 || unitLoyalty > 100 ); loyalty = unitLoyalty; // ##### begin Gilbert 29/5 ########// if( is_die_after_attack() ) // behavior_mode = UNIT_STAND_GROUND; // bee die after attack, so don't waste his life behavior_mode = UNIT_DEFENSIVE; // bee die after attack, so don't waste his life else behavior_mode = UNIT_AGGRESSIVE; // the default mode is aggressive // ##### end Gilbert 29/5 ########// //--------- init skill, and skill potential ---------// skill.init(unit_id, 100); set_combat_level(-1); hit_points = (float) max_hit_points(); //------ initialize the base Sprite class -------// if( startXLoc >= 0 ) init_sprite( startXLoc, startYLoc ); else cur_x = -1; //-------------- update loyalty -------------// update_loyalty(); //--------------- init AI info -------------// init_ai(); //----------- init derived class ----------// init_derived(); set_combat_level(-1); }