| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2022-07-29 15:53:59 -05:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  | #include <SFML\Graphics.hpp>
 | 
					
						
							|  |  |  | #include <SFML\System.hpp>
 | 
					
						
							| 
									
										
										
										
											2022-07-29 15:53:59 -05:00
										 |  |  | #include "GameState.h"
 | 
					
						
							| 
									
										
										
										
											2022-07-25 15:40:45 -05:00
										 |  |  | #include "Snake.h"
 | 
					
						
							| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | int main() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-07-29 15:53:59 -05:00
										 |  |  |     // int videoSizeHorizontal, videoSizeVertical;
 | 
					
						
							|  |  |  |     // videoSizeHorizontal = 1024;
 | 
					
						
							|  |  |  |     // videoSizeVertical = 725;
 | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |     gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
 | 
					
						
							|  |  |  |     gameGridVertical = (videoSizeVertical // 25) * 25;
 | 
					
						
							|  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2022-07-29 15:53:59 -05:00
										 |  |  |     // GameState newGame(1200, 1000);
 | 
					
						
							|  |  |  |     GameState newGame; | 
					
						
							|  |  |  |     sf::RenderWindow window(sf::VideoMode(newGame.videoSizeHorizontal, newGame.videoSizeVertical), "SnakePlusPlus"); | 
					
						
							|  |  |  |     // window = newGame.window;
 | 
					
						
							|  |  |  |     sf::Time delay = sf::milliseconds(25); | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |     int snakeDirection = 0; | 
					
						
							| 
									
										
										
										
											2022-07-26 16:56:26 -05:00
										 |  |  |     Snake Player(sf::Vector2f(25,25)); | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |     sf::RectangleShape snakeHead(sf::Vector2f(25,25)); | 
					
						
							| 
									
										
										
										
											2022-06-10 14:40:12 -05:00
										 |  |  |     sf::RectangleShape snakeFood(sf::Vector2f(25,25)); | 
					
						
							|  |  |  |     snakeFood.setFillColor(sf::Color::Red); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     snakeFood.setPosition(25,25); | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  |     while (window.isOpen()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         sf::Event event; | 
					
						
							| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  |         while (window.pollEvent(event)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) | 
					
						
							|  |  |  |                 window.close(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |             snakeDirection = 1; | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |             snakeDirection = 2; | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |             snakeDirection = 3; | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |             snakeDirection = 4; | 
					
						
							| 
									
										
										
										
											2022-07-27 15:07:28 -05:00
										 |  |  |         Player.MoveSnake(snakeFood); | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         window.clear(); | 
					
						
							| 
									
										
										
										
											2022-06-10 14:40:12 -05:00
										 |  |  |         window.draw(snakeFood); | 
					
						
							| 
									
										
										
										
											2022-07-26 19:03:55 -05:00
										 |  |  |         Player.DisplaySnake(window); | 
					
						
							| 
									
										
										
										
											2022-05-06 01:26:17 -05:00
										 |  |  |         window.display(); | 
					
						
							| 
									
										
										
										
											2022-07-27 15:07:28 -05:00
										 |  |  |         sf::sleep(delay); | 
					
						
							| 
									
										
										
										
											2022-05-06 00:40:36 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | } |