00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "game.h"
00024 #include "Jawbone_gump.h"
00025 #include "contain.h"
00026 #include "gamewin.h"
00027 #include "objiter.h"
00028 #include "misc_buttons.h"
00029 #include "jawbone.h"
00030
00031 const int toothx[19] = { 34, 32, 31, 31, 28, 31, 27, 31, 40, 50,
00032 57, 63, 72, 70, 75, 82, 83, 87, 0 };
00033
00034 const int toothy[19] = { 19, 30, 37, 44, 52, 57, 66, 77, 82, 84,
00035 80, 71, 69, 61, 50, 42, 36, 32, 0 };
00036
00037 Jawbone_gump::Jawbone_gump
00038 (
00039 Jawbone_object *cont,
00040 int initx, int inity
00041 ) : Gump(cont, initx, inity, game->get_shape("gumps/jawbone")),
00042 jawbone(cont)
00043 {
00044 set_object_area(Rectangle(0, 0, 138, 116), 10, 109);
00045 }
00046
00047
00048 int Jawbone_gump::add(Game_object *obj, int mx, int my, int sx, int sy,
00049 bool dont_check, bool combine)
00050 {
00051
00052 return jawbone->add(obj, dont_check, combine);
00053 }
00054
00055 void Jawbone_gump::paint()
00056 {
00057
00058 paint_shape(x, y);
00059
00060
00061 check_button->paint();
00062
00063 jawbone->find_teeth();
00064
00065 int i;
00066 for (i=0; i<9; i++)
00067 if (jawbone->teeth[i])
00068 paint_tooth(i);
00069 for (i=17; i>8; i--)
00070 if (jawbone->teeth[i])
00071 paint_tooth(i);
00072 }
00073
00074 void Jawbone_gump::paint_tooth(int index)
00075 {
00076 ShapeID shape(game->get_shape("gumps/tooth"), index, SF_GUMPS_VGA);
00077
00078 int objx = toothx[index];
00079 int objy = toothy[index];
00080
00081 shape.paint_shape(x + objx, y + objy);
00082 }
00083
00084 Game_object *Jawbone_gump::find_object(int mx, int my)
00085 {
00086 jawbone->find_teeth();
00087
00088
00089 mx -= x;
00090 my -= y;
00091
00092 int i;
00093
00094
00095 for (i=9; i<18; i++)
00096 if (jawbone->teeth[i] && on_tooth(mx, my, i)) {
00097
00098 set_to_spot(jawbone->teeth[i], mx, my);
00099 return jawbone->teeth[i];
00100 }
00101 for (i=8; i>=0; i--)
00102 if (jawbone->teeth[i] && on_tooth(mx, my, i)) {
00103
00104 set_to_spot(jawbone->teeth[i], mx, my);
00105 return jawbone->teeth[i];
00106 }
00107
00108 return 0;
00109 }
00110
00111 bool Jawbone_gump::on_tooth(int sx, int sy, int index)
00112 {
00113 ShapeID sid(game->get_shape("gumps/tooth"), index, SF_GUMPS_VGA);
00114 Shape_frame *shape = sid.get_shape();
00115
00116 int objx = toothx[index];
00117 int objy = toothy[index];
00118
00119 Rectangle r = gwin->get_shape_rect (shape, 0, 0);
00120
00121 if (r.has_point (sx - objx, sy - objy) &&
00122 shape->has_point (sx - objx, sy - objy))
00123 return true;
00124
00125 return false;
00126 }
00127
00128 void Jawbone_gump::set_to_spot(Game_object *obj, int sx, int sy)
00129 {
00130 if (obj->get_shapenum() != 559)
00131 return;
00132
00133 int fr = obj->get_framenum();
00134
00135
00136 Shape_frame *shape = obj->get_shape();
00137
00138
00139 int w = shape->get_width(), h = shape->get_height();
00140
00141
00142 obj->set_chunk(sx + shape->get_xleft() - w/2,
00143 sy + shape->get_yabove() - h/2);
00144 }
00145