File: shine.c

package info (click to toggle)
lbreakout2 2.5.2-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 6,040 kB
  • ctags: 2,374
  • sloc: ansic: 20,911; sh: 2,891; makefile: 374
file content (124 lines) | stat: -rw-r--r-- 3,915 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***************************************************************************
                          shine.c  -  description
                             -------------------
    begin                : Thu Sep 13 2001
    copyright            : (C) 2001 by Michael Speck
    email                : kulkanie@gmx.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "lbreakout.h"
#include "config.h"

extern 	SDL_Surface *stk_display;
extern 	Config config;
extern 	SDL_Surface *offscreen;
extern 	SDL_Surface *shine_pic;
extern  Game *game;
float   shine_change = 0.020; /* per ms */
int     shine_frame = 6; /* maximum frame */
float   shine_cur = 0; /* current frame */
int     shine_x, shine_y; /* position where current shine is drawn */
int     shine_recreate = 1;
Delay   shine_delay; /* delay between shines */

/*
====================================================================
Load/delete resources
====================================================================
*/
void shine_load()
{
	delay_set( &shine_delay, 200 );
}
void shine_delete()
{
}
/*
====================================================================
Recreate shine on a random but valid brick
====================================================================
*/
void shine_create()
{
	int x_add, y_add, x, y;
	shine_cur = 0;
	shine_x = 0; shine_y = 0;

	if ( !config.anim ) return;

	x = (rand() % (BRICK_WIDTH - 2)) + 1;
	y = (rand() % (BRICK_HEIGHT - 2)) + 1;
	x_add = rand() % 2 == 0 ? 1 : -1;
	y_add = rand() % 2 == 0 ? 1 : -1;

	while (x > 0 && x < MAP_WIDTH - 1 && y > 0 && y < MAP_HEIGHT - 1) {
		if (game->bricks[x][y].type != MAP_EMPTY && game->bricks[x][y].id != INVIS_BRICK_ID ) {
			shine_x = x * BRICK_WIDTH;
			shine_y = y * BRICK_HEIGHT;
			break;
		}
		x += x_add; y += y_add;
	}
	/* if creation succeeded don't create any more shines */
	if ( shine_x != 0 && shine_y != 0 ) shine_recreate = 0;
}
/*
====================================================================
Reset (delete( shine
====================================================================
*/
void shine_reset()
{
	shine_x = shine_y = 0;
	shine_recreate = 1;
	delay_reset( &shine_delay );
}
/*
====================================================================
Show/hide current shine
====================================================================
*/
void shine_hide()
{
	if (shine_x == 0 && shine_y == 0) return;
	stk_surface_blit( offscreen, shine_x, shine_y,
			BRICK_WIDTH, BRICK_HEIGHT,
			stk_display, shine_x, shine_y );
	stk_display_store_drect();
}
void shine_show()
{
	if (shine_x == 0 && shine_y == 0) return;
	stk_surface_blit( shine_pic, (int)shine_cur * BRICK_WIDTH, 0,
			BRICK_WIDTH, BRICK_HEIGHT,
			stk_display, shine_x, shine_y );
}
/*
   ====================================================================
   Update shine
   ====================================================================
   */
void shine_update( int ms )
{
	/* recreate shine? */
	if ( shine_recreate ) {
		shine_x = shine_y = 0; /* if recreation is demanded delete old shine */
		if ( delay_timed_out( &shine_delay, ms ) ) shine_create();
	}
	else {
		shine_cur += shine_change * ms;
		if (shine_cur > shine_frame) {
			shine_recreate = 1;
			delay_reset( &shine_delay );
		}
	}
}