Fix for the problem that SDL applications exited
[AROS-Contrib.git] / Games / lbreakout2 / client / shine.c
blobcd7be14939554083dbbdcb21db20290d7a126e1a
1 /***************************************************************************
2 shine.c - description
3 -------------------
4 begin : Thu Sep 13 2001
5 copyright : (C) 2001 by Michael Speck
6 email : kulkanie@gmx.net
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "lbreakout.h"
19 #include "config.h"
21 extern SDL_Surface *stk_display;
22 extern Config config;
23 extern SDL_Surface *offscreen;
24 extern SDL_Surface *shine_pic;
25 extern Game *game;
26 float shine_change = 0.020; /* per ms */
27 int shine_frame = 6; /* maximum frame */
28 float shine_cur = 0; /* current frame */
29 int shine_x, shine_y; /* position where current shine is drawn */
30 int shine_recreate = 1;
31 Delay shine_delay; /* delay between shines */
34 ====================================================================
35 Load/delete resources
36 ====================================================================
38 void shine_load()
40 delay_set( &shine_delay, 200 );
42 void shine_delete()
46 ====================================================================
47 Recreate shine on a random but valid brick
48 ====================================================================
50 void shine_create()
52 int x_add, y_add, x, y;
53 shine_cur = 0;
54 shine_x = 0; shine_y = 0;
56 if ( !config.anim ) return;
58 x = (rand() % (BRICK_WIDTH - 2)) + 1;
59 y = (rand() % (BRICK_HEIGHT - 2)) + 1;
60 x_add = rand() % 2 == 0 ? 1 : -1;
61 y_add = rand() % 2 == 0 ? 1 : -1;
63 while (x > 0 && x < MAP_WIDTH - 1 && y > 0 && y < MAP_HEIGHT - 1) {
64 if (game->bricks[x][y].type != MAP_EMPTY && game->bricks[x][y].id != INVIS_BRICK_ID ) {
65 shine_x = x * BRICK_WIDTH;
66 shine_y = y * BRICK_HEIGHT;
67 break;
69 x += x_add; y += y_add;
71 /* if creation succeeded don't create any more shines */
72 if ( shine_x != 0 && shine_y != 0 ) shine_recreate = 0;
75 ====================================================================
76 Reset (delete( shine
77 ====================================================================
79 void shine_reset()
81 shine_x = shine_y = 0;
82 shine_recreate = 1;
83 delay_reset( &shine_delay );
86 ====================================================================
87 Show/hide current shine
88 ====================================================================
90 void shine_hide()
92 if (shine_x == 0 && shine_y == 0) return;
93 stk_surface_blit( offscreen, shine_x, shine_y,
94 BRICK_WIDTH, BRICK_HEIGHT,
95 stk_display, shine_x, shine_y );
96 stk_display_store_drect();
98 void shine_show()
100 if (shine_x == 0 && shine_y == 0) return;
101 stk_surface_blit( shine_pic, (int)shine_cur * BRICK_WIDTH, 0,
102 BRICK_WIDTH, BRICK_HEIGHT,
103 stk_display, shine_x, shine_y );
106 ====================================================================
107 Update shine
108 ====================================================================
110 void shine_update( int ms )
112 /* recreate shine? */
113 if ( shine_recreate ) {
114 shine_x = shine_y = 0; /* if recreation is demanded delete old shine */
115 if ( delay_timed_out( &shine_delay, ms ) ) shine_create();
117 else {
118 shine_cur += shine_change * ms;
119 if (shine_cur > shine_frame) {
120 shine_recreate = 1;
121 delay_reset( &shine_delay );