-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.cpp
More file actions
134 lines (122 loc) · 3.44 KB
/
Copy pathblock.cpp
File metadata and controls
134 lines (122 loc) · 3.44 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
130
131
132
133
134
#include "share.hpp"
#include "gameWorld.hpp"
#include "game.hpp"
#include "math.hpp"
#include <cstdlib>
CCell* CWorld::getCellInArray(int x, int y)
{
//i don't know why -1 but it fixes the fucking bug
if(x > m_width-1)return NULL;
if(y > m_height-1)return NULL;
if(x < 0)return NULL;
if(y < 0)return NULL;
return &ma_pCells[(x*m_height)+y];
}
CSmallBlock::CSmallBlock()
{
}
CCell::CCell()
{
}
CCell* CWorld::getCell(int x, int y)
{
if (x < 0)x += -1 * CELL_SIZE;
if (y < 0)y += -1 * CELL_SIZE;
return getCellInArray((int)x/CELL_SIZE, (int)y/CELL_SIZE);
}
CCell* CWorld::getCell(sf::Vector2f &pos)
{
return getCell((int)pos.x, (int)pos.y);
}
CCell* CWorld::getCell(sf::Vector2f pos)
{
return getCell((int)pos.x, (int)pos.y);
}
CBlock* CWorld::createBlock(int x, int y, Ginfo::Block::Type type, bool force)
{
//not handling mixed yet ??
if (type == Ginfo::Block::MIXED)return NULL;
//check the cell
CCell* pCell = getCell(x,y);
if (pCell == NULL)return NULL;
if (!pCell->m_BlockContent.m_deleted)return NULL;
CBlock* pBlock = &pCell->m_BlockContent;
pBlock->m_deleted = false;
pBlock->m_type = type;
//assiegn small blocks
if (type != Ginfo::Block::MIXED)
{
for (int x = 0; x < BLOCK_SUBDIVISION; x++)
{
for (int y = 0; y < BLOCK_SUBDIVISION; y++)
{
pBlock->ma_SmallBlocks[x][y].m_deleted = false;
pBlock->ma_SmallBlocks[x][y].m_type = type;
}
}
}
return pBlock;
}
CSmallBlock* CWorld::createSmallBlock(int x, int y, Ginfo::Block::Type type, bool force)
{
//check the cell
CCell* pCell = getCell(x,y);
if (pCell == NULL)return NULL;
CBlock* pBlock = &pCell->m_BlockContent;
CSmallBlock *pSmallBlock = getSmallBlock(x, y);
if (force == false && !pSmallBlock->m_deleted)return NULL;
pBlock->m_deleted = false;
pBlock->m_type = Ginfo::Block::MIXED;
// printf("pos:%d %d\n", xSmall, ySmall);
pSmallBlock->m_deleted = false;
pSmallBlock->m_type = type;
return pSmallBlock;
}
bool CWorld::distroyBlock(int x, int y)
{
long type;
sf::Vector2f dropPos;
CCell* pCell = getCell(x,y);
if (pCell == NULL)return false;
if (pCell->m_BlockContent.m_deleted)return false;
CBlock* pBlock = &pCell->m_BlockContent;
type = pBlock->m_type;
dropPos = pBlock->m_pos;
pBlock->m_deleted = true;
for (int x = 0; x < BLOCK_SUBDIVISION; x++)
{
for (int y = 0; y < BLOCK_SUBDIVISION; y++)
{
pBlock->ma_SmallBlocks[x][y].m_deleted = true;
}
}
createDropItem(
sf::Vector2f(dropPos.x + (float)rand()/((float)RAND_MAX/80),
dropPos.y + (float)rand()/((float)RAND_MAX/80)),
Ginfo::Entity::BLOCK,
type);
return true;
}
bool CWorld::distroySmallBlock(int x, int y)
{
}
void CBlock::tick()
{
if (m_type == Ginfo::Block::ENEMY_SPAWN)
{
pworld->createDropItem(
sf::Vector2f(m_pos.x,m_pos.y + BLOCK_SIZE + 10),
Ginfo::Entity::BLOCK,
Ginfo::Block::ENEMY_SPAWN);
}
}
CSmallBlock* CWorld::getSmallBlock(int x, int y)
{
CCell* pCell = getCell(x,y);
if (pCell == NULL)return NULL;
CBlock* pBlock = &pCell->m_BlockContent;
int xArray = (x - pBlock->m_pos.x) / (int)SMALL_BLOCK_SIZE;
int yArray = (y - pBlock->m_pos.y) / (int)SMALL_BLOCK_SIZE;
CSmallBlock* pSmallBlock = &pBlock->ma_SmallBlocks[xArray][yArray];
return pSmallBlock;
}