-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGnat.cpp
More file actions
99 lines (82 loc) · 1.75 KB
/
Copy pathGnat.cpp
File metadata and controls
99 lines (82 loc) · 1.75 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
// Gnat.cpp: implementation of the CGnat class.
//
//////////////////////////////////////////////////////////////////////
#include "Gnat.h"
#include <time.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGnat::CGnat()
{
Sprite = NULL;
Tile = NULL;
Screen = NULL;
x = rand() % 600 + 1;
y = rand() % 400 + 1;
Speed = 3;
iTicker = 0;
}
CGnat::~CGnat()
{
SAFEDELETE(Sprite);
SAFEDELETE(Tile);
}
void CGnat::Load(CDXScreen *screen)
{
// Loads a random 1-3 Gnat.
Screen = screen;
char filename[256];
strcpy(filename, (char*)"graphics/gnats.bmp");
Tile = new CDXTile();
if( Tile->Create(Screen, filename, 40, 40, 0) == FALSE )
CDXError( Screen , (char*)"could not load tiles from file Gnat file" );
// set the top left pixel in tiles bitmap as transparent color
Tile->SetColorKey(0);
Sprite = new CDXSprite();
Sprite->Create(Tile);
Sprite->SetAlphaValue(150);
Sprite->SetShadowOffset(15, -15);
Sprite->SetShadowValue(150);
Sprite->SetFrame(1);
x = 0;
y = rand() % 280;
Speed = 3; // max speed
iTicker = 0;
}
void CGnat::Move(int iDirection)
{
int r = rand() % Speed;
x += r;
r = rand() % 3;
if (r == 2)
{
r = rand() % Speed;
y += r;
}
/* if (iDirection == -1)
x -= rand() % 5 + 1;
else if (iDirection == 0)
{}
else if (iDirection == 1)
x += rand() % 5 + 1;
*/
if (x >= 640 || y >= 480)
{
// Reset coordinates.
x = 0;
y = rand() % 280;
}
}
void CGnat::Draw()
{
if (iTicker++ > 30)
{
int iFrame = Sprite->GetFrame();
if (iFrame++ >= 4)
iFrame = 1;
Sprite->SetFrame(iFrame);
iTicker = 0;
}
Sprite->SetPos(x, y);
Sprite->Draw(Screen->GetBack() , 0 , 0 , CDXBLT_TRANSALPHA);
}