Huge code merge. This reflects the current status of my rewrite/restructuring. A...
[supertux.git] / src / world.c
1 //
2 // C Implementation: world
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include <stdlib.h>
14 #include <string.h>
15 #include "globals.h"
16 #include "scene.h"
17 #include "screen.h"
18 #include "defines.h"
19 #include "world.h"
20
21 void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
22 {
23       if (pbouncy_distro->alive)
24         {
25           pbouncy_distro->y = pbouncy_distro->y + pbouncy_distro->ym;
26
27           pbouncy_distro->ym++;
28
29           if (pbouncy_distro->ym >= 0)
30             pbouncy_distro->alive = NO;
31         }
32 }
33
34 void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro)
35 {
36       if (pbouncy_distro->alive)
37         {
38           texture_draw(&img_distro[0],
39                     pbouncy_distro->x - scroll_x,
40                     pbouncy_distro->y,
41                     NO_UPDATE);
42         }
43 }
44
45 void broken_brick_action(broken_brick_type* pbroken_brick)
46 {
47       if (pbroken_brick->alive)
48         {
49           pbroken_brick->x = pbroken_brick->x + pbroken_brick->xm;
50           pbroken_brick->y = pbroken_brick->y + pbroken_brick->ym;
51
52           pbroken_brick->ym++;
53
54           if (pbroken_brick->ym >= 0)
55             pbroken_brick->alive = NO;
56         }
57 }
58
59 void broken_brick_draw(broken_brick_type* pbroken_brick)
60 {
61       if (pbroken_brick->alive)
62         {
63           src.x = rand() % 16;
64           src.y = rand() % 16;
65           src.w = 16;
66           src.h = 16;
67
68           dest.x = pbroken_brick->x - scroll_x;
69           dest.y = pbroken_brick->y;
70           dest.w = 16;
71           dest.h = 16;
72
73           SDL_BlitSurface(img_brick[0].sdl_surface, &src, screen, &dest);
74         }
75 }
76
77 void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
78 {
79       if (pbouncy_brick->alive)
80         {
81           pbouncy_brick->offset = (pbouncy_brick->offset +
82                                      pbouncy_brick->offset_m);
83
84           /* Go back down? */
85
86           if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET)
87             pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED;
88
89
90           /* Stop bouncing? */
91
92           if (pbouncy_brick->offset == 0)
93             pbouncy_brick->alive = NO;
94         }
95 }
96
97 void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
98 {
99       if (pbouncy_brick->alive)
100         {
101           if (pbouncy_brick->x >= scroll_x - 32 &&
102               pbouncy_brick->x <= scroll_x + screen->w)
103             {
104               dest.x = pbouncy_brick->x - scroll_x;
105               dest.y = pbouncy_brick->y;
106               dest.w = 32;
107               dest.h = 32;
108
109               SDL_FillRect(screen, &dest, SDL_MapRGB(screen->format,
110                                                      current_level.bkgd_red,
111                                                      current_level.bkgd_green,
112                                                      current_level.bkgd_blue));
113
114               drawshape(pbouncy_brick->x - scroll_x,
115                         pbouncy_brick->y + pbouncy_brick->offset,
116                         pbouncy_brick->shape);
117             }
118         }
119 }
120
121 void floating_score_init(floating_score_type* pfloating_score, int x, int y, int s)
122 {
123       pfloating_score->alive = YES;
124       pfloating_score->x = x;
125       pfloating_score->y = y - 16;
126       timer_start(&pfloating_score->timer,1000);
127       pfloating_score->value = s;
128 }
129
130 void floating_score_action(floating_score_type* pfloating_score)
131 {
132       if (pfloating_score->alive)
133         {
134           pfloating_score->y = pfloating_score->y - 2;
135
136       if(!timer_check(&pfloating_score->timer))
137           pfloating_score->alive = NO;
138         }
139 }
140
141 void floating_score_draw(floating_score_type* pfloating_score)
142 {
143       if (pfloating_score->alive)
144         {
145         char str[10];
146           sprintf(str, "%d", pfloating_score->value);
147           drawtext(str,
148                    pfloating_score->x + 16 - strlen(str) * 8,
149                    pfloating_score->y,
150                    letters_gold, NO_UPDATE, 1);
151         }
152 }
153