-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranch.cpp
More file actions
103 lines (86 loc) · 1.68 KB
/
Branch.cpp
File metadata and controls
103 lines (86 loc) · 1.68 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
// Branch.cpp: implementation of the CBranch class.
//
//////////////////////////////////////////////////////////////////////
#include "Branch.h"
#include <time.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBranch::CBranch()
{
Sprite = NULL;
Tile = NULL;
Screen = NULL;
x = rand() % 600 + 1;
y = rand() % 400 + 1;
Speed = 3;
iTicker = 0;
}
CBranch::~CBranch()
{
SAFEDELETE(Sprite);
SAFEDELETE(Tile);
}
void CBranch::Load(CDXScreen *screen)
{
// Loads a random 1-3 Branch.
Screen = screen;
char filename[256];
strcpy(filename, (char*)"graphics/treebranch.bmp");
Tile = new CDXTile();
if( Tile->Create(Screen, filename, 60, 60, 0) == FALSE )
CDXError( Screen , (char*)"could not load tiles from file Branch 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(0);
Sprite->SetScale(8);
x = 400;
y = rand() % 280;
Speed = 1; // max speed
iTicker = 0;
}
void CBranch::Move(int iDirection)
{
if (y >= 450)
{
y = 0;
}
if (x >= 620)
{
x = 0;
}
if (x <= 0)
{
x = 619;
}
if (y <= 0)
{
y = 449;
}
if (iDirection == LEFT)
{
x -= Speed;
}
else if (iDirection == RIGHT)
{
x += Speed;
}
else if (iDirection == UP)
{
y -= Speed;
}
else if (iDirection == DOWN)
{
y += Speed;
}
}
void CBranch::Draw()
{
Sprite->SetPos(x, y);
Sprite->Draw(Screen->GetBack() , 0 , 0 , CDXBLT_TRANSALPHA | CDXBLT_TRANSSCALED);
}