Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////
- //ANIMATE
- /////////////
- void Character::Animate(sf::RenderWindow& App, Game& Game)
- {
- float offset = 128 * App.GetFrameTime();
- if(PosX < MapX * 64)
- {
- PosX += offset;
- Game.View.Move(offset, 0);
- }
- else if(PosX > MapX * 64)
- {
- PosX -= offset;
- Game.View.Move(-offset, 0);
- }
- else if(PosY < MapY * 64)
- {
- PosY += offset;
- Game.View.Move(0, offset);
- }
- else if(PosY > MapY * 64)
- {
- PosY -= offset;
- Game.View.Move(0, -offset);
- }
- else if(PosX == MapX * 64 && PosY == MapY * 64)
- {
- Moving = false;
- //PosX ++;
- //MapX++;
- //PosY++;
- //MapY++;
- //cout << "Moving == false";
- }
- Timer++;
- if(Timer == 1 && Moving)
- Direction++;
- else if(Timer == 8 && Moving)
- Direction--;
- else if(Timer == 16 && Moving)
- Direction += 2;
- else if (Timer == 24 && Moving)
- Direction -= 2;
- if(Moving)
- cout << Timer << " ";
- //else if (Timer == 64)
- //cout << PosX << " " << PosY << " " << MapX << " " << MapY << "\n";
- return;
- }
- //////////////
- //DISPLAY
- //////////////
- void Character::Display(sf::RenderWindow& App, Game& Game)
- {
- const sf::Input& Input = App.GetInput();
- if(!Moving)
- {
- if(Input.IsKeyDown(sf::Key::W) || Input.IsKeyDown(sf::Key::Up))
- {
- if(Game.CollisionData[MapX + (MapY-1) * Game.MapWidth] != 1)
- MapY--;
- Moving = true;
- Timer = 0;
- Direction = 3;
- }
- else if(Input.IsKeyDown(sf::Key::A) || Input.IsKeyDown(sf::Key::Left))
- {
- if(Game.CollisionData[(MapX-1) + MapY * Game.MapWidth] != 1)
- MapX--;
- Moving = true;
- Timer = 0;
- Direction = 6;
- }
- else if(Input.IsKeyDown(sf::Key::S) || Input.IsKeyDown(sf::Key::Down))
- {
- if(Game.CollisionData[MapX + (MapY+1) * Game.MapWidth] != 1)
- MapY++;
- Moving = true;
- Timer = 0;
- Direction = 0;
- }
- else if(Input.IsKeyDown(sf::Key::D) || Input.IsKeyDown(sf::Key::Right))
- {
- if(Game.CollisionData[(MapX+1) + MapY * Game.MapWidth] != 1)
- MapX++;
- Moving = true;
- Timer = 0;
- Direction = 9;
- }
- }
- Animate(App, Game);
- CharacterSprite[Direction].SetPosition(PosX, PosY);
- App.Draw(CharacterSprite[Direction]);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement