-
Notifications
You must be signed in to change notification settings - Fork 1
/
gameitem.cpp
92 lines (79 loc) · 1.24 KB
/
gameitem.cpp
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
#include "gameitem.h"
GameItem::GameItem(quint8 id) :
myId(id),
myState(IdleState),
myXoff(0), myYoff(0),
myDx(0), myDy(0),
myOpacity(1)
{
}
void GameItem::idle()
{
myState = IdleState;
setOpacity(1);
myXoff = myYoff = 0;
myDx = myDy = 0;
}
void GameItem::die()
{
myState = DyingState;
setOpacity(1);
myCount = 5;
}
void GameItem::scheduleDeath()
{
myState = NotAliveState;
}
void GameItem::born()
{
myState = BornState;
setOpacity(0);
myCount = 5;
}
void GameItem::fall(int dx, int dy)
{
myState = FallingState;
setOpacity(1);
myDx = dx;
myDy = dy;
myXoff = myYoff = 0;
myCount = 5;
}
void GameItem::select()
{
myState = SelectedState;
setOpacity(1);
myCount = 10;
}
void GameItem::advance()
{
switch (myState)
{
case DyingState:
myOpacity -= 0.2;
break;
case FallingState:
if (!--myCount)
idle();
else
{
myXoff = -11*myDx*myCount;
myYoff = -11*myDy*myCount;
}
break;
case BornState:
myOpacity += 0.2;
if (!--myCount)
idle();
break;
case SelectedState:
myOpacity -= 0.05;
if (!--myCount)
{
myOpacity = 1;
myCount = 10;
}
break;
default: ;
}
}