forked from Breeze-del/C-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factory.cpp
139 lines (131 loc) · 2.9 KB
/
Factory.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
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
130
131
132
133
134
135
136
137
138
139
// Factory.cpp: implementation of the CFactory class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Factory.h"
#include"Resource.h"
#include<Windows.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DWORD WINAPI Zombies(LPVOID pM) //背景音乐子线程函数
{
mciSendString("play .\\music\\zombies.mp3 ", NULL, 0, NULL);
return 0;
}
DWORD WINAPI Level(LPVOID pM) //背景音乐子线程函数
{
mciSendString("play .\\music\\level.mp3 ", NULL, 0, NULL);
return 0;
}
CFactory::CFactory()
{
Init();
m_warnimg = CResource::m_warning;
m_prepare = CResource::m_prepare;
m_isp = true;
}
CFactory::~CFactory()
{
}
/*
0.寒冰射手
1.坚果
2.豌豆射手
3.窝瓜
4.向日葵
5.樱桃炸弹
*/
CActiveObj* CFactory::Creat(int num, int i, int j)
{
if (num == 0) {
CActiveObj *it = new CIceShooter();
it->SetPos(i, j);
return it;
}
else if (num == 1) {
CActiveObj *it = new CNut();
it->SetPos(i, j);
return it;
}
else if (num == 2) {
CActiveObj *it = new CPeaShooter();
it->SetPos(i, j);
return it;
}
else if (num == 3) {
CActiveObj *it = new CPumkin();
it->SetPos(i, j);
return it;
}
else if (num == 4) {
CActiveObj *it = new CSunFlower();
it->SetPos(i, j);
return it;
}
else if (num == 5) {
CActiveObj *it = new CCherrybomb();
it->SetPos(i, j);
return it;
}
}
CActiveObj* CFactory::Spawn() //生成怪物的算法.
{
m_spawntime++;
int rate1, rate2;
rate1 = m_spawnrate - m_spawntime / 500;
rate2 = 4000 - m_spawntime / 50;
if (rate2 < 500)rate2 = 500;
if (rate1 < 50)rate1 = 50;
if (m_spawntime % rate1 == 0) {
CreateThread(NULL, 0, Zombies, NULL, 0, NULL);
if (rand() % 20 < (3 + m_spawntime / 5000) && m_spawntime > 10000) {
CActiveObj* it = new CDoorZombie();
return it;
}
else if (rand() % 20 < (5 + m_spawntime / 3000) && m_spawntime > 5000) {
CActiveObj* it = new CDrumZombie();
return it;
}
else if (rand() % 20 < (10 + m_spawntime / 2000) && m_spawntime > 2000) {
CActiveObj* it = new CHatZombie();
return it;
}
else {
CActiveObj* it = new CZombies();
return it;
}
}
if (m_spawntime % rate2 < 10 && m_spawntime >= 4000) {
CreateThread(NULL, 0, Level, NULL, 0, NULL);
if (m_spawntime > 8000 && rand() % 5 < 2) {
CActiveObj* it = new CDoorZombie();
return it;
}
else if (rand() % 5 < 3) {
CActiveObj* it = new CDrumZombie();
return it;
}
else if (rand() % 5 < 4) {
CActiveObj* it = new CHatZombie();
return it;
}
else {
CActiveObj* it = new CZombies();
return it;
}
}
return NULL;
}
void CFactory::Init()
{
m_spawntime = 0;
m_spawnrate = 500;
}
int CFactory::Getm_spawntime()
{
return m_spawntime;
}