Mercurial > MadButterfly
annotate src/shift.c @ 160:147c93163ef0
Fix bug of tank that bullet is not hidden when go out the map.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 08 Oct 2008 03:57:56 +0800 |
parents | 6ce68c1f7405 |
children | c7e5b8779bb5 |
rev | line source |
---|---|
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <stdlib.h> |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <string.h> |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #include "animate.h" |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 static float comp_mb_timeval_ratio(const mb_timeval_t *a, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 const mb_timeval_t *b) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 float ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 return ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 typedef struct _mb_shift mb_shift_t; |
117 | 16 /*! \brief Animation action for relative shift a coordination. */ |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 struct _mb_shift { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 mb_action_t action; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 co_aix x, y; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 coord_t *coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 mb_timeval_t start_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 co_aix saved_matrix[6]; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 const mb_timeval_t *playing_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 }; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 static void mb_shift_start(mb_action_t *act, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 const mb_timeval_t *playing_time, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 mb_shift_t *shift = (mb_shift_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 coord_t *coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 MB_TIMEVAL_CP(&shift->start_time, now); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 coord = shift->coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 memcpy(&shift->saved_matrix, coord->matrix, sizeof(co_aix[6])); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 shift->playing_time = playing_time; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 static void mb_shift_step(mb_action_t *act, const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 mb_shift_t *shift = (mb_shift_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 mb_timeval_t diff; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 coord_t *coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 float ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 MB_TIMEVAL_CP(&diff, now); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 MB_TIMEVAL_DIFF(&diff, &shift->start_time); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 ratio = comp_mb_timeval_ratio(&diff, shift->playing_time); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 coord = shift->coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 coord->matrix[2] = shift->saved_matrix[2] + shift->x * ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 coord->matrix[5] = shift->saved_matrix[5] + shift->y * ratio; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 rdman_coord_changed(rdman, coord); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 static void mb_shift_stop(mb_action_t *act, const mb_timeval_t *now, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 redraw_man_t *rdman) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 mb_shift_t *shift = (mb_shift_t *)act; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 coord_t *coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 coord = shift->coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 coord->matrix[2] = shift->saved_matrix[2] + shift->x; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 coord->matrix[5] = shift->saved_matrix[5] + shift->y; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 rdman_coord_changed(rdman, coord); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 static void mb_shift_free(mb_action_t *act) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 free(act); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 } |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 mb_action_t *mb_shift_new(co_aix x, co_aix y, coord_t *coord, |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 mb_word_t *word) { |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 mb_shift_t *shift; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 shift = (mb_shift_t *)malloc(sizeof(mb_shift_t)); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 if(shift == NULL) |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 return (mb_action_t *)shift; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 shift->x = x; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 shift->y = y; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 shift->coord = coord; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 shift->action.start = mb_shift_start; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 shift->action.step = mb_shift_step; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 shift->action.stop = mb_shift_stop; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 shift->action.free = mb_shift_free; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 |
154 | 94 /*! \note mb_shift_new() will add itself to the specified word. */ |
116
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 mb_word_add_action(word, (mb_action_t *)shift); |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 return (mb_action_t *)shift; |
1d74eb3861b7
move animation actions from animate.c to files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
98 } |