Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "snake.hpp"
- #include <cstdlib>
- void Snake::move()
- {
- switch(direction_){
- case Direction::North:
- position_.y += 1;
- break;
- case Direction::East:
- position_.x += 1;
- break;
- case Direction::South:
- position_.y -= 1;
- break;
- case Direction::West:
- position_.x -= 1;
- }
- if (position_.x < 6.4) position_.x = 44.8; else if (position_.x > 44.8) position_.x = 6.4;
- if (position_.y < 0) position_.y = 38.4; else if (position_.y > 38.4) position_.y = 0;
- }
- //Snake canot move back on its self
- //Cannot get working
- //bool Snake::MoveValid (Direction move) const
- //{
- // switch (move)
- // {
- // case Direction::North:
- // switch ()
- // {
- // case Direction::North:
- // case Direction::West:
- // case Direction::East:
- // return true;
- //
- // default:
- // return false;
- // }
- //
- // case Direction::West:
- // switch ()
- // {
- // case Direction::West:
- // case Direction::North:
- // case Direction::South:
- // return true;
- //
- // default:
- // return false;
- // }
- //
- // case Direction::East:
- // switch ()
- // {
- // case Direction::East:
- // case Direction::North:
- // case Direction::South:
- // return true;
- //
- // default:
- // return false;
- // }
- //
- // case Direction::South:
- // switch ()
- // {
- // case Direction::South:
- // case Direction::West:
- // case Direction::East:
- // return true;
- //
- // default:
- // return false;
- // }
- //
- // default:
- // return false;
- // }
- //
- // return false;
- //}
- void Snake::render(prg::Canvas& canvas) const
- {
- canvas.drawCircle(getPosition().x * 20, getPosition().y * 20,19.2,prg::Colour::GREEN);
- }
- void Snake::changeDirection(Direction new_direction)
- {
- direction_ = new_direction;
- }
Advertisement
Add Comment
Please, Sign In to add comment