Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/facing.c

Go to the documentation of this file.
00001 /* {{{
00002  * CalcRogue, a roguelike game for PCs, calculators and PDAs
00003  * Copyright (C) 2003 Jim Babcock
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * }}} */
00019 // facing.c
00023 
00024 #include "crogue.h"
00025 
00026 sint facing(sint x, sint y);
00027 sint facing_towards(sint x, sint y);
00028 sint facing_opposite(sint x, sint y);
00029 sint player_facing(void);
00030 uint delta_facing(sint facing_one, sint facing_two);
00031 
00032 //{{{
00033 static sint sign(sint v)
00034 {
00035     if(v<0) return -1;
00036     else if(v>0) return 1;
00037     else return 0;
00038 }
00039 //}}}
00040 //{{{
00041 static schar facings[3][3] =
00042     {
00043         { 3, 2, 1 },
00044         { 4, 8, 0 },
00045         { 5, 6, 7 }
00046     };
00047 //}}}
00048 //{{{
00049 sint facing(sint x, sint y)
00050 {
00051     x = sign(x) + 1;
00052     y = sign(y) + 1;
00053     return facings[y][x];
00054 }
00055 //}}}
00056 //{{{
00057 sint facing_towards(sint x, sint y)
00058 {
00059     return facing((sint)x - w->plr.x, (sint)y - w->plr.y);
00060 }
00061 //}}}
00062 //{{{
00063 sint facing_opposite(sint x, sint y)
00064 {
00065     return (facing_towards(x, y) + 4) % 8;
00066 }
00067 //}}}
00068 //{{{
00069 sint player_facing(void)
00070 {
00071     int xi, yi, n=0, f=0;
00072     
00073     if(w->plr.facing_forced != -1)
00074         return w->plr.facing_forced;
00075     
00076     for(yi=w->plr.y-1; yi<=w->plr.y+1; yi++)
00077     for(xi=w->plr.x-1; xi<=w->plr.x+1; xi++)
00078     {
00079         if(monstbytile(xi, yi) != -1)
00080             n++, f=facing_towards(xi, yi);
00081     }
00082     if(n==1) return f;
00083     else     return w->plr.facing;
00084 }
00085 //}}}
00086 //{{{
00087 uint delta_facing(sint facing_one, sint facing_two)
00088 {
00089     sint df = abs(facing_one - facing_two);
00090     return min(df, 8-df);
00091 }
00092 //}}}

Generated on Thu May 20 13:12:09 2004 for CalcRogue by doxygen 1.3.6