Done?
This commit is contained in:
		
							
								
								
									
										32
									
								
								SQCSim2021/bullet.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								SQCSim2021/bullet.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| #include "bullet.h" | ||||
| #include "world.h" | ||||
|  | ||||
| Bullet::Bullet(Player& player) { | ||||
| 	m_startpos = m_currentpos = player.GetPOV() + player.GetDirection(); | ||||
| 	m_velocity = player.GetDirection(); | ||||
| } | ||||
|  | ||||
| Bullet::~Bullet() {} | ||||
|  | ||||
| bool Bullet::Update(World* world, Transformation& tran, float elapsedtime) { | ||||
| 	for (int x = 0; x < 1000; ++x) { | ||||
| 		m_currentpos += m_velocity * elapsedtime; | ||||
|  | ||||
| 		if (!world->ChunkAt(m_currentpos)) | ||||
| 			return true; | ||||
| 		else if (world->BlockAt(m_currentpos) != BTYPE_AIR) { | ||||
| 			world->ChangeBlockAtPosition(BTYPE_AIR, m_currentpos); | ||||
| 			return true; | ||||
| 		} | ||||
| 		else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true; | ||||
| 	} | ||||
|  | ||||
| 	return false; | ||||
| } | ||||
|  | ||||
| void Bullet::Transpose(int& x, int& z) { | ||||
| 	m_currentpos.x -= x * CHUNK_SIZE_X; | ||||
| 	m_currentpos.z -= z * CHUNK_SIZE_Z; | ||||
| 	m_startpos.x -= x * CHUNK_SIZE_X; | ||||
| 	m_startpos.z -= z * CHUNK_SIZE_Z; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user