bool Entity::move(long elapsed, float x, float y){ float x_move = (float)(sprite.getPosition().x + (x * elapsed)); float y_move = (float)(sprite.getPosition().y + (y * elapsed)); if (isValidLevelMove((int)x_move, (int)y_move)){ sprite.setPosition(x_move, y_move); entity_type_text.setPosition(x_move, y_move - 32); // Set new animation switch (Action){ case CHAR_MOVE: const sf::Texture* texture = sprite.getTexture(); int width = (int)sprite.getLocalBounds().width;//The Sprites' width int height = (int)sprite.getLocalBounds().height;//The Sprites' height if (source.x > 2){//Have we reached the last frame? //Reset the frame to the first animation source.x = 0; } int frame = (source.x * width) + selected_sprite_set_in_row;//The frame image to show float direction = getDirection(); if (direction >= 1.0 && direction < 2.5) source.y = RIGHT; else if (direction >= 2.5 && direction < 4.0) source.y = UP; else if (direction >= 4.0 && direction < 6) source.y = LEFT; else source.y = DOWN; int direction_image = (source.y*height) + (selected_sprite_set_in_col);//The direction image to show //Display the specified portion (image) from the Entitysheet. sprite.setTextureRect(sf::Rect<int>(frame, direction_image, width, height)); source.x++;//Move to next frame } return true; } return false; }
bool Sprite::move(float x, float y) { int xpos = (int)(pos.x + x); int ypos = (int)(pos.y + y); if(isValidLevelMove(xpos, ypos)) { // erase sprite erase(pos.x, pos.y); pos.x += x; pos.y += y; facingDirection.x = x; facingDirection.y = y; //draw sprite draw(pos.x,pos.y); return true; } return false; }