Changeset 657 for abuse/trunk/src/game.cpp
- Timestamp:
- May 15, 2011, 6:22:17 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/game.cpp
r656 r657 260 260 } 261 261 262 view *Game:: view_in(int mousex, int mousey)262 view *Game::GetView(vec2i pos) 263 263 { 264 264 for(view *f = first_view; f; f = f->next) 265 if(f->drawable() && mousex >= f->cx1 && mousey >= f->cy1266 && mousex <= f->cx2 && mousey <= f->cy2)265 if(f->drawable() && pos.x >= f->cx1 && pos.y >= f->cy1 266 && pos.x <= f->cx2 && pos.y <= f->cy2) 267 267 return f; 268 268 return NULL; … … 274 274 } 275 275 276 void Game::ftile_on(int screenx, int screeny, int32_t &x, int32_t &y) 277 { 278 mouse_to_game(screenx, screeny, x, y); 279 x /= ftile_width(); 280 y /= ftile_height(); 281 } 282 283 void Game::btile_on(int screenx, int screeny, int32_t &x, int32_t &y) 284 { 285 view *f = view_in(screenx, screeny); 286 if(f) 287 { 288 x = ((int32_t)screenx - (int32_t)f->cx1 289 + f->xoff() * bg_xmul / bg_xdiv) / (int32_t)b_wid; 290 y = ((int32_t)screeny - (int32_t)f->cy1 291 + f->yoff() * bg_ymul / bg_ydiv) / (int32_t)b_hi; 292 } 276 vec2i Game::GetFgTile(vec2i pos) 277 { 278 return MouseToGame(pos) / vec2i(ftile_width(), ftile_height()); 279 } 280 281 vec2i Game::GetBgTile(vec2i pos) 282 { 283 view *f = GetView(pos); 284 if(!f) 285 return vec2i(-1, -1); 286 287 return vec2i((pos.x - f->cx1 + f->xoff() * bg_xmul / bg_xdiv) / b_wid, 288 (pos.y - f->cy1 + f->yoff() * bg_ymul / bg_ydiv) / b_hi); 289 } 290 291 vec2i Game::MouseToGame(vec2i pos, view *v) 292 { 293 if (!v) 294 v = GetView(pos); 295 if (!v) 296 v = player_list; // if not in a view use the first one 297 if (!v) 298 return vec2i(-1, -1); 299 300 if(dev & MAP_MODE) 301 return vec2i((pos.x - v->cx1) * ftile_width() 302 / AUTOTILE_WIDTH + map_xoff * ftile_width(), 303 (pos.y - v->cy1) * ftile_height() 304 / AUTOTILE_HEIGHT + map_yoff * ftile_height()); 305 306 return pos - vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff()); 307 } 308 309 vec2i Game::GameToMouse(vec2i pos, view *v) 310 { 311 if (!(dev & MAP_MODE)) 312 return pos + vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff()); 313 314 vec2i tmp; 315 316 if (dev & EDIT_MODE) 317 tmp = vec2i(map_xoff, map_yoff); 318 else if(v->focus) 319 tmp = vec2i(v->focus->x / ftile_width() 320 - (v->cx2 - v->cx1) / AUTOTILE_WIDTH / 2, 321 v->focus->y / ftile_height() 322 - (v->cy2 - v->cy1) / AUTOTILE_HEIGHT / 2); 293 323 else 294 { 295 x = -1; 296 y = -1; 297 } 298 } 299 300 void Game::mouse_to_game(int32_t x, int32_t y, 301 int32_t &gamex, int32_t &gamey, view *f) 302 { 303 if(!f) 304 f = view_in(x, y); 305 if(!f) 306 f = player_list; // if not in a view use the first one 307 308 if(f) 309 { 310 if(dev & MAP_MODE) 311 { 312 gamex = (x - (int32_t)f->cx1) * ftile_width() / AUTOTILE_WIDTH + map_xoff * ftile_width(); 313 gamey = (y - (int32_t)f->cy1) * ftile_height() / AUTOTILE_HEIGHT + map_yoff * ftile_height(); 314 } 315 else 316 { 317 gamex = x - (int32_t)f->cx1 + f->xoff(); 318 gamey = y - (int32_t)f->cy1 + f->yoff(); 319 } 320 } 321 } 322 323 void Game::game_to_mouse(int32_t gamex, int32_t gamey, view *which, 324 int32_t &x, int32_t &y) 325 { 326 if(!(dev & MAP_MODE)) 327 { 328 x = gamex - which->xoff() + which->cx1; 329 y = gamey - which->yoff() + which->cy1; 330 return; 331 } 332 333 int32_t x1, y1; 334 335 if(dev & EDIT_MODE) 336 { 337 x1 = map_xoff; 338 y1 = map_yoff; 339 } 340 else 341 { 342 if(which->focus) 343 { 344 x1 = which->focus->x / ftile_width() 345 - (which->cx2 - which->cx1) / AUTOTILE_WIDTH / 2; 346 y1 = which->focus->y / ftile_height() 347 - (which->cy2 - which->cy1) / AUTOTILE_HEIGHT / 2; 348 } 349 else 350 x1 = y1 = 0; 351 } 352 353 if(x1 < 0) 354 x1 = 0; 355 if(y1 < 0) 356 y1 = 0; 357 358 x = gamex * AUTOTILE_WIDTH / ftile_width() 359 - x1 * AUTOTILE_WIDTH + which->cx1; 360 if(x1 > 0) 361 x -= (which->focus->x * AUTOTILE_WIDTH / ftile_width()) 362 % AUTOTILE_WIDTH; 363 364 y = gamey * AUTOTILE_HEIGHT / ftile_height() 365 - y1 * AUTOTILE_HEIGHT + which->cy1; 366 if(y1 > 0) 367 y -= (which->focus->y * AUTOTILE_HEIGHT / ftile_height()) 368 % AUTOTILE_HEIGHT; 324 tmp = vec2i(0, 0); 325 326 tmp.x = Max(tmp.x, 0); 327 tmp.y = Max(tmp.y, 0); 328 329 vec2i ret(pos.x * AUTOTILE_WIDTH / ftile_width() 330 - tmp.x * AUTOTILE_WIDTH + v->cx1, 331 pos.y * AUTOTILE_HEIGHT / ftile_height() 332 - tmp.y * AUTOTILE_HEIGHT + v->cy1); 333 if (tmp.x > 0) 334 ret.x -= (v->focus->x * AUTOTILE_WIDTH / ftile_width()) 335 % AUTOTILE_WIDTH; 336 if(tmp.y > 0) 337 ret.y -= (v->focus->y * AUTOTILE_HEIGHT / ftile_height()) 338 % AUTOTILE_HEIGHT; 339 340 return ret; 369 341 } 370 342
Note: See TracChangeset
for help on using the changeset viewer.