-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerUp.cpp
More file actions
129 lines (93 loc) · 2.54 KB
/
PowerUp.cpp
File metadata and controls
129 lines (93 loc) · 2.54 KB
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
125
126
127
128
129
/*
* PowerUp.cpp - part of 32Blox (revised edition!)
*
* Copyright (C) 2020 Pete Favelle <32blit@ahnlak.com>
*
* This file is released under the MIT License; see LICENSE for details
*
* The PowerUp object defines the pills that randomly drop from broken bricks,
* that provide (usually!) beneficial powerups to the player.
*/
/* System headers. */
/* Local headers. */
#include "32blit.hpp"
#include "32blox.hpp"
#include "PowerUp.hpp"
/* Functions. */
/*
* constructor - Spawns a power up at the specified location.
*/
PowerUp::PowerUp( blit::Point p_origin )
{
/* Save the origin and pick a type. */
location = blit::Vec2( p_origin.x, p_origin.y );
powerup_type = (powerup_type_t)( blit::random() % POWERUP_MAX );
/* And set a default gravity. */
vector = blit::Vec2( 0, 0.75f );
/* All done. */
return;
}
/*
* get_render_location - returns the render location of the powerup, taking into
* account the dimensions of the thing
*/
blit::Point PowerUp::get_render_location( void )
{
/* The inner location represents the middle of the powerup; powerups will */
/* always be two sprites wide, so similar to the bat logic. */
return location - blit::Vec2( 8, 4 );
}
/*
* get_bounds - returns a rectangle describing the bounding box around the
* powerup; simpler than the ball, in that powerups are always
* a full two sprites big.
*/
blit::Rect PowerUp::get_bounds( void )
{
return blit::Rect(
location - blit::Vec2( 8, 4 ),
location + blit::Vec2( 8, 4 )
);
}
/*
* get_type - accessor for the powerup type
*/
powerup_type_t PowerUp::get_type( void )
{
return powerup_type;
}
/*
* update - updates the location of the powerup.
*/
void PowerUp::update( void )
{
/* This is relatively painless, actually. */
location += vector;
/* All done. */
return;
}
/*
* render - draws the powerup on the screem.
*/
void PowerUp::render( void )
{
/* This is a relatively simple sprite blit, with some positionsl alpha. */
uint8_t l_oldalpha = blit::screen.alpha;
blit::screen.alpha = 255 - ( (int)location.y % 10 ) * 10;
blit::screen.sprite(
blit::Rect( powerup_type * 2, SPRITE_ROW_POWERUP, 2, 1 ),
get_render_location()
);
blit::screen.alpha = l_oldalpha;
/* All done. */
return;
}
/*
* remove - drops the powerup off the bottom of the screen; this flags it
* for removal from the internal lists later.
*/
void PowerUp::remove( void )
{
location.y = blit::screen.bounds.h + 10;
}
/* End of PowerUp.cpp */