true collisions
This commit is contained in:
		
							parent
							
								
									f40fb1727f
								
							
						
					
					
						commit
						afea5f21b2
					
				| @ -63,22 +63,38 @@ bool Game::manageInvaders(){ | |||||||
| 
 | 
 | ||||||
| 	// moving
 | 	// moving
 | ||||||
| 	// TODO fix this lol
 | 	// TODO fix this lol
 | ||||||
|  | 	 | ||||||
| 	if(direction){ // go to the right
 | 	if(direction){ // go to the right
 | ||||||
| 		int end = basePos.getX(); // start Position
 | 		int end = basePos.getX(); // start Position
 | ||||||
| 		end+= grid.size() * confData.invadersSize; // add the invaders
 | 		end+= grid.size() * confData.invadersSize; // add the invaders
 | ||||||
| 		end+= (grid.size()-1) * confData.invadersDistance; // add the invadersDistance between invaders
 | 		end+= (grid.size()-1) * confData.invadersDistance; // add the invadersDistance between invaders
 | ||||||
| 
 | 
 | ||||||
| 		// you got the end position of the invader crowd !
 | 		// you got the end position of the invader crowd !
 | ||||||
|  | 		unsigned relativeScreenWidth = pm->getScreenWidth(); | ||||||
|  | 		size_t i = grid.size()-1; | ||||||
|  | 		while (grid[i].hasNoValid()){ | ||||||
|  | 			relativeScreenWidth += confData.invadersSize + confData.invadersDistance; | ||||||
|  | 			--i; | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		if(end + confData.invadersSpeed < pm->getScreenWidth()){ | 		if(end + confData.invadersSpeed < relativeScreenWidth){ | ||||||
| 			basePos.setX(basePos.getX() + confData.invadersSpeed); | 			basePos.setX(basePos.getX() + confData.invadersSpeed); | ||||||
| 		}else{ | 		} | ||||||
|  | 		else{ | ||||||
| 			basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance); | 			basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance); | ||||||
| 			direction = !direction; | 			direction = !direction; | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 	}else{ | 	} | ||||||
| 		if(basePos.getX() >= confData.invadersSpeed){ | 	else{ | ||||||
|  | 		size_t i = 0; | ||||||
|  | 		unsigned relativeBasePos = basePos.getX(); | ||||||
|  | 		while (grid[i].hasNoValid()){ | ||||||
|  | 			relativeBasePos += confData.invadersSize + confData.invadersDistance; | ||||||
|  | 			++i; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if(relativeBasePos >= confData.invadersSpeed){ | ||||||
| 			basePos.setX(basePos.getX() - confData.invadersSpeed); | 			basePos.setX(basePos.getX() - confData.invadersSpeed); | ||||||
| 		}else{ | 		}else{ | ||||||
| 			basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance); | 			basePos.setY(basePos.getY() + confData.invadersSize + confData.invadersDistance); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user