void move_to_dest (piece_info_t *obj, long dest) { path_map_t path_map[MAP_SIZE]; int fterrain; const char *mterrain; long new_loc; switch (obj->type) { case ARMY: fterrain = T_LAND; mterrain = "+"; break; case FIGHTER: fterrain = T_AIR; mterrain = "+.O"; break; default: fterrain = T_WATER; mterrain = ".O"; break; } new_loc = vmap_find_dest (path_map, user_map, obj->loc, dest, USER, fterrain); if (new_loc == obj->loc) return; /* can't get there */ vmap_mark_path (path_map, user_map, dest); new_loc = vmap_find_dir (path_map, user_map, obj->loc, mterrain, " ."); if (new_loc == obj->loc) return; /* can't move ahead */ assert (good_loc (obj, new_loc)); move_obj (obj, new_loc); /* everything looks good */ }
void move_armyload (piece_info_t *obj) { long loc; piece_info_t *p; int i; panic("move_armyload() is not implemented"); /* why? */ /* look for an adjacent transport */ loc = find_transport (USER, obj->loc); if (loc != obj->loc) { move_obj (obj, loc); obj->func = NOFUNC; } else { /* look for nearest non-full transport */ memcpy (amap, user_map, sizeof (view_map_t) * MAP_SIZE); /* mark loading transports or cities building transports */ for (p = user_obj[TRANSPORT]; p; p = p->piece_link.next) if (p->count < obj_capacity (p)) /* not full? */ amap[p->loc].contents = '$'; for (i = 0; i < NUM_CITY; i++) if (city[i].owner == USER && city[i].prod == TRANSPORT) amap[city[i].loc].contents = '$'; } }
void move_explore (piece_info_t *obj) { path_map_t path_map[MAP_SIZE]; long loc; const char *terrain; switch (obj->type) { case ARMY: loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army); terrain = "+"; break; case FIGHTER: loc = vmap_find_aobj (path_map, user_map, obj->loc, &user_fighter); terrain = "+.O"; break; default: loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship); terrain = ".O"; break; } if (loc == obj->loc) return; /* nothing to explore */ if (user_map[loc].contents == ' ' && path_map[loc].cost == 2) vmap_mark_adjacent (path_map, obj->loc); else vmap_mark_path (path_map, user_map, loc); loc = vmap_find_dir (path_map, user_map, obj->loc, terrain, " "); if (loc != obj->loc) move_obj (obj, loc); }
int msg_explode4 (int n, int msg, int z) { int sh; switch (msg) { case msg_update: objs[n].count = (objs[n].count + 1)&7; if (objs[n].count3==0) { switch (random(6)) { case 0: objs[n].count3 = 1; break; case 1: objs[n].count3 = 2; break; case 2: objs[n].count3 = 3; break; case 3: objs[n].count3 = 4; break; case 4: objs[n].count3 = 5; break; case 5: objs[n].count3 = 6; }; }; if (++objs[n].count2 >= 30) killobj (n); if (++objs[n].yd > 6) objs[n].yd = 6; move_obj (n, objs[n].x+objs[n].xd, objs[n].y+objs[n].yd); if (objs[n].y+objs[n].yl>=scrn_y) objs[n].yd=-objs[n].yd; return (1); case msg_draw: if (objs[n].count3==1) sh = 0x1000 + objs[n].count/2; if (objs[n].count3==2) sh = 0x1004 + objs[n].count/2; if (objs[n].count3==3) sh = 0x1008 + objs[n].count/2; if (objs[n].count3==4) sh = 0x100c + objs[n].count/2; if (objs[n].count3==5) sh = 0x1010 + objs[n].count/2; if (objs[n].count3==6) sh = 0x1014 + objs[n].count/2; drawshape (&gamevp, sh, objs[n].x, objs[n].y); }; return (0); };
void move_repair (piece_info_t *obj) { path_map_t path_map[MAP_SIZE]; long loc; assert (obj->type > FIGHTER); if (obj->hits == piece_attr[obj->type].max_hits) { obj->func = NOFUNC; return; } if (user_map[obj->loc].contents == 'O') { /* it is in port? */ obj->moved += 1; return; } loc = vmap_find_wobj (path_map, user_map, obj->loc, &user_ship_repair); if (loc == obj->loc) return; /* no reachable city */ vmap_mark_path (path_map, user_map, loc); /* try to be next to ocean to avoid enemy pieces */ loc = vmap_find_dir (path_map, user_map, obj->loc, ".O", "."); if (loc != obj->loc) move_obj (obj, loc); }
int move_player( char map[MAP_HSIZE][MAP_WSIZE], gps* player, int move, LSDB* lsdb ){ int iy = player->y + dy[ move ]; int ix = player->x + dx[ move ]; if( ix < 0 || iy < 0 || ix >= MAP_WSIZE || iy >= MAP_HSIZE ) return 0; char obj = map[ iy ][ ix ]; if( obj == MONSTER ){ return -1; } if( obj == STONE || obj == BOMB ){ if( move_obj( map, obj, iy, ix, move ) ){ map[ player->y ][ player->x ] = EMPTY; player->y += dy[ move ]; player->x += dx[ move ]; map[ player->y ][ player->x ] = PLAYER; return 1; } else return 0; } if( obj == EMPTY || obj == DIRT || obj == DIAMOND || obj == MONEY || obj == BOMBPK ){ map[ player->y ][ player->x ] = EMPTY; player->y += dy[ move ]; player->x += dx[ move ]; map[ player->y ][ player->x ] = PLAYER; if( obj == MONEY ) lsdb->score += POINTS_MONEY ; if( obj == DIAMOND ){ lsdb->score += POINTS_DIAMOND; (lsdb->diamonds)--; } if( obj == BOMBPK ) lsdb->bombs += NUM_BOMBPK ; return 1; } else return 0; }
static void *scan_obj(obj_t *obj) { mem_ops_t *ops = OBJ_MEM_OPS(obj); assert(is_known_ops(ops)); size_t size = aligned_size(ops->mo_size(obj)); size_t i, n_ptrs = ops->mo_ptr_count(obj); for (i = 0; i < n_ptrs; i++) { ops->mo_set_ptr(obj, i, move_obj(ops->mo_get_ptr(obj, i))); } return (void *)obj + size; }
void move_dir (piece_info_t *obj) { long loc; int dir; dir = MOVE_DIR (obj->func); loc = obj->loc + dir_offset[dir]; if (good_loc (obj, loc)) move_obj (obj, loc); }
void move_army_to_city (piece_info_t *obj, long city_loc) { piece_info_t *tt; tt = find_nfull (TRANSPORT, city_loc); if (tt != NULL) move_obj (obj, city_loc); else fatal (obj, city_loc, "That's our city, sir! Do you really want to attack the garrison? ", "Your rebel army was liquidated."); }
int msg_ejected (int n, int msg, int z) { int sh; switch (msg) { case msg_update: objs[n].count = (objs[n].count + 1)&3; if (++objs[n].count2 >= 20) killobj (n); if (++objs[n].yd > 12) objs[n].yd = 12; move_obj (n,objs[n].x+objs[n].xd,objs[n].y+objs[n].yd); return (1); case msg_draw: sh = 0x1403 + objs[n].count/2; drawshape (&gamevp, sh, objs[n].x, objs[n].y); }; return (0); };
int msg_shield (int n, int msg, int z) { int sh; switch (msg) { case msg_update: if (objs[n].count2 >= 240) objs[n].count = (objs[n].count + 1)&3; move_obj (n, objs[0].x-2, objs[0].y-2); if (++objs[n].count2==340) killobj (n); return (1); case msg_draw: sh = 0x804 + objs[n].count/2; drawshape (&gamevp, sh, objs[n].x, objs[n].y); break; case msg_touch: switch (objs[z].kind) { case obj_enemy1: case obj_enemy2: case obj_enemy3: case obj_enemy4: case obj_enemy5: case obj_enemy6: case obj_enemy7: case obj_enemy8: case obj_enemy9: case obj_enemya: case obj_enemyb: case obj_enemyc: case obj_enemyd: case obj_enemye: case obj_enemyf: case obj_enemyg: case obj_enemyh: case obj_enemyi: case obj_enemyj: case obj_enemyk: snd_play (1,7); if (objs[z].count3 < 1) { killobj (z); } else { objs[z].xd = -objs[z].xd; objs[z].yd = -objs[z].yd; }; break; case obj_bullet2: case obj_spinner: case obj_laser: snd_play (1,7); explosion (objs[z].x, objs[z].y, 5); killobj (z); }; }; return (0); };
void move_transport (piece_info_t *obj) { long loc; /* look for an adjacent transport */ loc = find_transport (USER, obj->loc); if (loc != obj->loc) { move_obj (obj, loc); obj->func = NOFUNC; } else obj->moved = piece_attr[obj->type].speed; }
void move_armyattack (piece_info_t *obj) { path_map_t path_map[MAP_SIZE]; long loc; assert (obj->type == ARMY); loc = vmap_find_lobj (path_map, user_map, obj->loc, &user_army_attack); if (loc == obj->loc) return; /* nothing to attack */ vmap_mark_path (path_map, user_map, loc); loc = vmap_find_dir (path_map, user_map, obj->loc, "+", "X*a"); if (loc != obj->loc) move_obj (obj, loc); }
void move_random (piece_info_t *obj) { long loc_list[8]; int i, nloc; long loc; nloc = 0; for (i = 0; i < 8; i++) { loc = obj->loc + dir_offset[i]; if (good_loc (obj, loc)) { loc_list[nloc] = loc; /* remember this location */ nloc++; /* count locations we can move to */ } } if (nloc == 0) return; /* no legal move */ i = rand_long ((long)nloc-1); /* choose random direction */ move_obj (obj, loc_list[i]); /* move the piece */ }
void user_dir (piece_info_t *obj, direction_t dir) { long loc; loc = obj->loc + dir_offset[dir]; if (good_loc (obj, loc)) { move_obj (obj, loc); return; } if (!map[loc].on_board) { error ("You cannot move to the edge of the world."); return; } switch (obj->type) { case ARMY: user_dir_army (obj, loc); break; case FIGHTER: user_dir_fighter (obj, loc); break; default: user_dir_ship (obj, loc); break; } }
static void copy_heap() { /* with lock */ { verify_heap(); flip(); verify_heap(); root_descriptor_t *desc; for (desc = get_thread_roots(); desc; desc = desc->rd_next) { *desc->rd_root = move_obj(*desc->rd_root); verify_heap(); } while (next_scan < next_alloc) { next_scan = scan_obj(next_scan); verify_heap(); } assert(next_scan == next_alloc); if (debug_heap) alloc_end = next_alloc; else if (alloc_end - next_alloc < (tospace_end - tospace) / 2) fprintf(stderr, "increase heap size\n"); } }
void gameobj::move_point_obj(int x, int y) { if(this->point->type == -1) { puts("Point is root"); } else move_obj(point, x, y); }
int main() { SDL_Surface* background, *background2, *background3, *background4; SDL_Rect src, dest; int frames; Uint32 colorkey; SDL_AudioSpec desired, obtained; sound_t bus_sound; /*initialize video and sound subsystem*/ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0){ printf("Unable to initialize video: %s\n.", SDL_GetError()); return 1; } /*ensure all subsystems exit safely*/ atexit(SDL_Quit); atexit(SDL_CloseAudio); /*set video mode*/ screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_HWSURFACE); if (screen == NULL) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } /*load background images*/ background = SDL_LoadBMP("img/src.bmp"); if (background == NULL) { printf("Unable to load image."); return 1; } background2 = SDL_LoadBMP("img/background2.bmp"); if (background2 == NULL) { printf("Unable to load background2."); return 1; } background3 = SDL_LoadBMP("img/background3.bmp"); if (background3 == NULL) { printf("Unable to load background3."); return 1; } background4 = SDL_LoadBMP("img/background4.bmp"); if (background4 == NULL) { printf("Unable to load background4."); return 1; } /*load bus*/ bus = SDL_LoadBMP("img/bus.bmp"); if (bus == NULL) { printf("Unable to load image."); return 1; } colorkey = SDL_MapRGB(bus->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(bus, SDL_SRCCOLORKEY, colorkey); /*load man*/ man = SDL_LoadBMP("img/man.bmp"); if (man == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(man->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(man, SDL_SRCCOLORKEY, colorkey); man2 = SDL_LoadBMP("img/man2.bmp"); if (man2 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(man2->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(man2, SDL_SRCCOLORKEY, colorkey); car1 = SDL_LoadBMP("img/car1.bmp"); if (car1 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(car1->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(car1, SDL_SRCCOLORKEY, colorkey); car2 = SDL_LoadBMP("img/car2.bmp"); if (car2 == NULL) { printf("Unable to load image"); return 1; } colorkey = SDL_MapRGB(car2->format, 255, 255, 255); /*set color key*/ SDL_SetColorKey(car2, SDL_SRCCOLORKEY, colorkey); //open audio device desired.freq = 44100; desired.format = AUDIO_S16; desired.samples = 4096; desired.channels = 2; desired.callback = AudioCallback; desired.userdata = NULL; if (SDL_OpenAudio(&desired, &obtained) < 0) { printf("Unable to open audio device: %s\n", SDL_GetError()); return 1; } //load sound files and convert them to sound card's format if (LoadAndConvertSound("audio/bus-pass.wav", &obtained, &bus_sound) != 0) { printf("Unable to load sound.\n"); return 1; } ClearPlayingSounds(); SDL_PauseAudio(0); init_bus(); init_man(); int passenger_in = 0; PlaySound(&bus_sound); while (psv.x > 0) { src.x = 0; src.y = 0; src.w = background->w; src.h = background->h; dest = src; SDL_BlitSurface(background, &src, screen, &dest); draw_obj(&psv, bus); if (psv.x < screen->w/2 && !passenger_in) { /*pause bus for passenger to enter*/ SDL_PauseAudio(1); if (passenger.x > psv.x + 40){ /*check if passenger has got in*/ passenger_in = 1; SDL_PauseAudio(0); } draw_man(); SDL_Flip(screen); move_obj(&passenger); } else { SDL_Flip(screen); move_obj(&psv); } } psv.x = 639; psv.y = 320; init_cars(); PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background2, &src, screen, &dest); draw_obj(&priv1, car1); draw_obj(&priv2, car2); draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); move_obj(&priv1); move_obj(&priv2); } psv.x = 639; psv.y = 350; PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background3, &src, screen, &dest); draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); } psv.x = 639; psv.y = 267; passenger.y = 270; passenger_in = 1; int has_paused = 0; PlaySound(&bus_sound); while (psv.x + bus->w/2 > 0) { SDL_BlitSurface(background4, &src, screen, &dest); if (screen->w/2 > psv.x && passenger_in == 1) { SDL_PauseAudio(1); if (has_paused == 0) { SDL_Delay(1000); has_paused = 1;} if (passenger.x > 639) {passenger_in = 0; SDL_PauseAudio(0);} draw_obj(&psv, bus); draw_man(); SDL_Flip(screen); move_obj(&passenger); } else { draw_obj(&psv, bus); SDL_Flip(screen); move_obj(&psv); } } //pause and lock sound system SDL_PauseAudio(1); SDL_LockAudio(); free(bus_sound.samples); SDL_UnlockAudio(); SDL_FreeSurface(background4); SDL_FreeSurface(background3); SDL_FreeSurface(background2); SDL_FreeSurface(background); SDL_FreeSurface(man); SDL_FreeSurface(bus); return 0; }