make every moving sprite warp
Erik Auerswald
auerswal at unix-ag.uni-kl.de
Fri Feb 17 11:47:41 EST 2006
Hi,
I'd like to have every moving sprite sprite warp when horizontally
leaving the level. Especially bullets and to a lesser degree cannonballs
should warp IMHO.
I don't know how you think about it, so I just created a patch, but did
not commit the changes. Please tell me what you think about it.
Erik
-------------- next part --------------
Index: src/engine/sprite.c
===================================================================
--- src/engine/sprite.c (revision 77)
+++ src/engine/sprite.c (working copy)
@@ -84,6 +84,7 @@
s->pos.y += s->vel.y;
s->base.x = (int)(s->pos.x + 0.5);
s->base.y = (int)(s->pos.y + 0.5);
+ sprite_boundary(s);
}
int sprite_pgrad(sprite_t *s1, coresprite_t *s2)
@@ -390,3 +391,24 @@
}
+void sprite_boundary(sprite_t *s)
+{
+ if (s->base.x < 0) {
+ sprite_set_pos(s,s->base.x + current_level->width,s->base.y);
+ sprite_msg(s,msg_short(MSG_WARP));
+ } else if (s->base.x > current_level->width) {
+ sprite_set_pos(s,s->base.x - current_level->width, s->base.y);
+ sprite_msg(s,msg_short(MSG_WARP));
+ }
+ if (s->base.y < 0) {
+ /*fprintf(stderr, "Sprite got ABOVE TOP\n");*/
+ if (s->vel.y < 0)
+ s->vel.y = 0.1;
+ sprite_msg(s,msg_short(MSG_OUTOFBOUNDS));
+ } else if (s->base.y > current_level->height) {
+ /*fprintf(stderr, "Sprite got UNDER BOTTOM\n");*/
+ if (s->vel.y > 0)
+ s->vel.y = -0.1;
+ sprite_msg(s,msg_short(MSG_OUTOFBOUNDS));
+ }
+}
Index: src/engine/sprite.h
===================================================================
--- src/engine/sprite.h (revision 77)
+++ src/engine/sprite.h (working copy)
@@ -147,6 +147,7 @@
void sprite_start_frame(void); /* Call at start of frame */
unsigned int sprite_end_frame(void); /* Returns the number of ms slept */
+void sprite_boundary(sprite_t *s); /* keep sprites inside level boundaries */
#endif
Index: src/engine/mech.c
===================================================================
--- src/engine/mech.c (revision 78)
+++ src/engine/mech.c (working copy)
@@ -48,7 +48,7 @@
{
if (!(s->sprite.flags & SPRITE_IMMOBILE))
{
- mech_boundary(s);
+ //mech_boundary(s);
mech_air(s);
((sprite_t *)s)->vel = vmadd(((sprite_t *)s)->vel,s->lin_impulse,s->rmass);
s->lin_impulse.x = 0;
@@ -392,7 +392,9 @@
void mech_boundary(mech_sprite_t *ms)
{
sprite_t *s = (sprite_t *)ms;
+ sprite_boundary(s);
+#if 0
if (s->base.x < 0)
{
sprite_set_pos(s,s->base.x + current_level->width,s->base.y);
@@ -417,6 +419,7 @@
s->vel.y = -0.1;
sprite_msg(s,msg_short(MSG_OUTOFBOUNDS));
}
+#endif
}
/* Make s follow "it" at a distance dist, using a maximum force to accelerate
Index: src/sprites/cannon.c
===================================================================
--- src/sprites/cannon.c (revision 77)
+++ src/sprites/cannon.c (working copy)
@@ -109,8 +109,9 @@
create_effect(&explosion,s->pos);
sprite_kill(s);
break;
+ //case MSG_WARP: // let cannonballs warp
case MSG_OUTOFBOUNDS:
- case MSG_WARP:
+ create_effect(&explosion,s->pos); // fall through to MSG_KILL
case MSG_KILL:
sprite_kill(s);
break;
More information about the airstrike
mailing list