53 |
{ return ITEM_DROP; } |
{ return ITEM_DROP; } |
54 |
|
|
55 |
|
|
56 |
px::V3 Item::get_force(Actor *a) |
px::V2 Item::get_force(Actor *a) |
57 |
{ return px::V3(); } |
{ return px::V2(); } |
58 |
|
|
59 |
bool |
bool |
60 |
Item::actor_hit(Actor *actor) |
Item::actor_hit(Actor *actor) |
61 |
{ |
{ |
62 |
const double ITEM_RADIUS = 0.3; |
const double ITEM_RADIUS = 0.3; |
63 |
px::V3 item_center(get_pos().x + 0.5, |
px::V2 item_center(get_pos().x + 0.5, get_pos().y + 0.5); |
|
get_pos().y + 0.5, |
|
|
0); |
|
64 |
double dist = length(actor->get_pos()-item_center); |
double dist = length(actor->get_pos()-item_center); |
65 |
return (dist < ITEM_RADIUS); |
return (dist < ITEM_RADIUS); |
66 |
} |
} |
211 |
HillHollow(const char *name, Type t); |
HillHollow(const char *name, Type t); |
212 |
|
|
213 |
void transmute(Type newtype); |
void transmute(Type newtype); |
214 |
V3 vec_to_center (V3 v); |
V2 vec_to_center (V2 v); |
215 |
double get_radius() const { return m_radius[m_type]; } |
double get_radius() const { return m_radius[m_type]; } |
216 |
|
|
217 |
private: |
private: |
219 |
void shovel(); |
void shovel(); |
220 |
|
|
221 |
// Item interface |
// Item interface |
222 |
px::V3 get_force(Actor *a); |
px::V2 get_force(Actor *a); |
223 |
bool actor_hit(Actor *a) { return false; } |
bool actor_hit(Actor *a) { return false; } |
224 |
void on_stonehit(Stone *st); |
void on_stonehit(Stone *st); |
225 |
|
|
266 |
shovel(); |
shovel(); |
267 |
} |
} |
268 |
|
|
269 |
V3 HillHollow::vec_to_center (V3 v) |
V2 HillHollow::vec_to_center (V2 v) |
270 |
{ |
{ |
271 |
GridPos p = get_pos(); |
GridPos p = get_pos(); |
272 |
return v - V3(p.x+0.5, p.y+0.5,0); |
return v - V2(p.x+0.5, p.y+0.5); |
273 |
} |
} |
274 |
|
|
275 |
V3 HillHollow::get_force(Actor *a) |
V2 HillHollow::get_force(Actor *a) |
276 |
{ |
{ |
277 |
V3 v = vec_to_center(a->get_pos()); |
V2 v = vec_to_center(a->get_pos()); |
278 |
if (length(v) <= get_radius()) |
if (length(v) <= get_radius()) |
279 |
return get_forcefac()*v; |
return get_forcefac()*v; |
280 |
else |
else |
281 |
return px::V3(); |
return px::V2(); |
282 |
} |
} |
283 |
|
|
284 |
void HillHollow::transmute(Type newtype) |
void HillHollow::transmute(Type newtype) |
822 |
public: |
public: |
823 |
Magnet_FF() : m_active(false), strength(30) {} |
Magnet_FF() : m_active(false), strength(30) {} |
824 |
|
|
825 |
void set_pos(GridPos p) { center = to_vec(p) + V3(0.5,0.5,0); } |
void set_pos(GridPos p) { center = to_vec(p) + V2(0.5,0.5); } |
826 |
|
|
827 |
V3 get_force(Actor *a, V3 x, V3 v, double time) |
V2 get_force(Actor *a, V2 x, V2 v, double time) |
828 |
{ |
{ |
829 |
if (!m_active) |
if (!m_active) |
830 |
return V3(); |
return V2(); |
831 |
V3 dv = center - x; |
V2 dv = center - x; |
832 |
double dist = length(dv); |
double dist = length(dv); |
833 |
if (dist < 0.1) |
if (dist < 0.1) |
834 |
return V3(); |
return V2(); |
835 |
else |
else |
836 |
return strength * dv/(dist*dist); |
return strength * dv/(dist*dist); |
837 |
} |
} |
838 |
|
|
839 |
bool m_active; |
bool m_active; |
840 |
V3 center; |
V2 center; |
841 |
double strength; |
double strength; |
842 |
}; |
}; |
843 |
|
|
902 |
public: |
public: |
903 |
WormHole_FF() : strength(50), range(1000) {} |
WormHole_FF() : strength(50), range(1000) {} |
904 |
|
|
905 |
void set_pos(GridPos p) { center = to_vec(p) + V3(0.5,0.5,0); } |
void set_pos(GridPos p) { center = to_vec(p) + V2(0.5,0.5); } |
906 |
|
|
907 |
V3 get_force(Actor *a, V3 x, V3 v, double time) |
V2 get_force(Actor *a, V2 x, V2 v, double time) |
908 |
{ |
{ |
909 |
V3 b = center - x; |
V2 b = center - x; |
910 |
double bb = length(b); |
double bb = length(b); |
911 |
if (bb>0 && bb < range) { |
if (bb>0 && bb < range) { |
912 |
return strength*b/(bb*bb); |
return strength*b/(bb*bb); |
913 |
} |
} |
914 |
return V3(); |
return V2(); |
915 |
} |
} |
916 |
|
|
917 |
V3 center; // Center of the force field |
V2 center; // Center of the force field |
918 |
double strength; // Strength of the force |
double strength; // Strength of the force |
919 |
double range; // Range of the force |
double range; // Range of the force |
920 |
}; |
}; |
944 |
|
|
945 |
bool actor_hit(Actor *a); |
bool actor_hit(Actor *a); |
946 |
|
|
947 |
V3 get_center() const { |
V2 get_center() const { |
948 |
GridPos p = get_pos(); |
GridPos p = get_pos(); |
949 |
return V3(p.x+0.5, p.y+0.5,0); |
return V2(p.x+0.5, p.y+0.5); |
950 |
} |
} |
951 |
V3 vec_to_center (V3 v) {return v-get_center();} |
V2 vec_to_center (V2 v) {return v-get_center();} |
952 |
|
|
953 |
bool near_center_p (Actor *a) { |
bool near_center_p (Actor *a) { |
954 |
return (length(vec_to_center(a->get_pos())) < 0.5/4); |
return (length(vec_to_center(a->get_pos())) < 0.5/4); |