// Comments #ifndef SPRITE_H #define SPRITE_H #include #include namespace edu_colorado_main_intro { class Sprite { public: // Constants static const int INVISIBLE_PUT = -1; // Constructors Sprite( ); Sprite( int side_length, std::string filebase, int many_frames, int many_angles ); Sprite(const Sprite& source); // Destructor ~Sprite( ); // Mutator functions void approach(double amount, double x, double y); void approach_mouse(double amount); void approach_sprite(double amount, const Sprite& target) { approach(amount, target._x, target._y); } void change_frame(int frame); void clear( ); void jump( ); // Move to a random spot void move(double horizontal_amount, double vertical_amount) { _x += horizontal_amount; _y += vertical_amount; } void move_horizontal(double amount) { _x += amount; } void move_vertical(double amount) { _y += amount; } void operator --( ) { --_frame; if (_frame < 0) _frame = _images.size( ) - 1; } void operator ++( ) { ++_frame; if (static_cast(_frame) >= _images.size( )) _frame = 0; } void operator =(const Sprite& source); void rotate(double amount_in_radians) { set_angle_in_radians(_angle_in_radians + amount_in_radians); } void set_angle_in_radians(double angle_in_radians); void set_images( int side_length, std::string filebase, int many_frames, int many_angles ); void set_position(double x, double y) { _x = x; _y = y; } void set_drawing_mode(int mode) { _mode = mode; } void set_drawing_transformations (double scalex, double translatex, double scaley, double translatey); void set_x(double x) { _x = x; } void set_y(double y) { _y = y; } // Constant member functions void draw( ) const; // Constant acccessor functions double angle_in_radians( ) const { return _angle_in_radians; } int frame( ) const { return _frame; } int many_angles( ) const { return _many_angles; } int many_frames( ) const { return _images.size( ); } bool mode( ) const { return _mode; } double x( ) const { return _x; } double y( ) const { return _y; } private: // Private member variables to keep track of the current images // as well as the position and orientation of the sprite. std::vector< std::vector > _images; int _many_angles; int _side_length; int _half_length; int _frame; int _angle_number; int _mode; double _x, _y; // Location of center of Sprite double _angle_in_radians; int _bytes_per_image; double _scalex, _translatex, _scaley, _translatey; // Private member functions to carry out helper tasks: void Sprite::compute_coordinates (int newx, int newy, double r, int& x, int& y); }; } #endif