void QSFcanvas::OnInit(){ setMouseTracking(true); view = sf::View(sf::FloatRect(0,0,600,400)); //*Initialisation des images AM.add("Fly",AnimatedSprite(IM,"graphics/FLYanim",4,7*TAILLE,0,true)); AM.add("Circle",AnimatedSprite(IM,"graphics/blackcircle",1,TAILLE,0,true)); AM.add("caca",AnimatedSprite(IM,"graphics/CACA",1,5*10,0,false)); AM.add("cacador",AnimatedSprite(IM,"graphics/cacador",1,5*12,0,false)); //*/ std::cout << "init!!!!" << std::endl; }
void Shot::die() { bitmap = ResourceManager::GetTextureBitmap("Shot"); MainSprite = AnimatedSprite( ResourceManager::GetTexture("Shot"), 3,1); MainSprite.SetAnimation(0, 0); }
Roller::Roller(jmath::vec2 pos, int length, int direction, jvis::Texture* tex) { _texture = tex; _direction = direction; length--; for (int i = 0; i < length; i++) { sprites.push_back(AnimatedSprite()); sprites.back().SetTexture(&*_texture); sprites.back().SetSize(jmath::vec2(16)); sprites.back().SetDelay(180); sprites.back().GetRigidBody()->SetCollisionType(jphys::BOX_STATIC); sprites.back().GetRigidBody()->SetDimensions(jmath::vec3(12, 16, 0)); sprites.back().SetOrigin(jvis::Sprite::Origin::TopLeft); int startX = direction ? 64 : 32; if (i == 0 || i == length - 1) sprites.back().SetRectangle(jmath::vec4(startX, 80, 16, 16)); else sprites.back().SetRectangle(jmath::vec4(64, 64, 16, 16)); sprites.back().GetRigidBody()->SetFriction(1.f); sprites.back().SetNumColumns(2); sprites.back().SetNumFrames(2); sprites.back().SetPosition(jmath::vec3(pos.x + (i * 16), pos.y, 0)); sprites.back().GetRigidBody()->MoveX(16); sprites.back().GetRigidBody()->MoveY(16); sprites.back().SetOrigin(jvis::Sprite::Origin::TopLeft); } }
pacman::pacman(sf::Texture spr) { //ctor xpos = 250; ypos = 500; xvel = 0; yvel = 0; text = spr; upan.setSpriteSheet(text); upan.addFrame(sf::IntRect(0, 0, 25, 25)); upan.addFrame(sf::IntRect(75, 0, 25, 25)); downan.setSpriteSheet(text); downan.addFrame(sf::IntRect(0, 0, 25, 25)); downan.addFrame(sf::IntRect(25, 0, 25, 25)); leftan.setSpriteSheet(text); leftan.addFrame(sf::IntRect(0, 0, 25, 25)); leftan.addFrame(sf::IntRect(100, 0, 25, 25)); rightan.setSpriteSheet(text); rightan.addFrame(sf::IntRect(0, 0, 25, 25)); rightan.addFrame(sf::IntRect(50, 0, 25, 25)); currentanim = &leftan; anspr = AnimatedSprite(sf::seconds(.2f), false, true); anspr.setPosition(sf::Vector2f(xpos, ypos)); //std::cout << "1 pacman" << std::endl; anspr.play(*currentanim); //sprite.setPosition(xpos, ypos); collision_box = sprite.getGlobalBounds(); dir = 3; }
Bee::Bee(TextureManager &textureManager, b2Body *enemyBody, float moveVelocity, std::vector<sf::Vector2f> waypoints, float steering) : Entity(enemyBody), mMoveVelocity(moveVelocity), mSteering(steering), mSeeking(false) { sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet); Animation animation; animation.setSpriteSheet(spriteSheet); animation.addFrame(sf::IntRect(315, 353, 56, 48)); animation.addFrame(sf::IntRect(140, 23, 61, 42)); mAnimation = animation; mSprite = AnimatedSprite(sf::seconds(0.15f)); mSprite.setAnimation(mAnimation); sf::FloatRect bounds = mSprite.getLocalBounds(); mSprite.setOrigin(bounds.width/2, bounds.height/2); mCurrentFacingDirection = Entity::FacingDirection::Left; if (waypoints.empty()) mSeeking = true; //Position waypoints according to the bee center //Rather than absolute top-left coordinates else { for (auto &waypoint : waypoints) { sf::Vector2f platformWaypoint( waypoint.x + 35.f, waypoint.y + PX_PER_M - bounds.height / 2.f); mWaypoints.push_back(platformWaypoint); } mCurrentWaypoint = mWaypoints.begin(); } }
void Explosion::Initialize( sf::Vector2f pos, std::string texture ) { Pos = pos; MainSprite = AnimatedSprite( ResourceManager::GetTexture(texture), 3, 2); MainSprite.SetAnimation(0, 5); MainSprite.scale(1,1); MainSprite.setColor( sf::Color::Color(255,180,180) ); MainSprite.setOrigin(MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); MainSprite.setPosition(Pos); }
FighterJohn::FighterJohn(int initDirection) { direction = initDirection; width = 100; height = 100; anim = 0; health = 100; maxHealth = 100; energy = 50; maxEnergy = 100; power = 2; defense = 2; attackSpeed = 20; cooldown = 0; moveSpeed = 8; primaryColor = sf::Color(0,135,235); secondaryColor = sf::Color(255,255,0); status = READY; //sprites standingSprite = sf::Sprite(); standingSprite.setTexture(ResourceManager::JohnStand); standingSprite.setTextureRect(sf::IntRect(15,70,265,230)); standingSprite.setOrigin(180,100); jumpingSprite = sf::Sprite(); jumpingSprite.setTexture(ResourceManager::JohnRun); jumpingSprite.setTextureRect(sf::IntRect(41,60,260,230)); jumpingSprite.setOrigin(180,100); runningSprite = AnimatedSprite(sf::seconds(.06f)); runningSprite.setAnimation(ResourceManager::JohnRunAnim); runningSprite.setOrigin(180,100); attackingSprite = AnimatedSprite(sf::seconds(.045f)); attackingSprite.setAnimation(ResourceManager::JohnAttAnim); attackingSprite.setOrigin(180,130); //initialize sounds whoosh.setBuffer(ResourceManager::HeavyWhoosh); whoosh.setLoop(false); thud.setBuffer(ResourceManager::Thud); thud.setLoop(false); }
void CentipedeBodyPart::setAncestor(CentipedeBodyPart* olderSibling) { ancestor = olderSibling; currentState = Enumerators::centipedeMovementMode::Following; hasAncestor = true; bitmap = ResourceManager::GetTextureBitmap("Centipede Body"); MainSprite = AnimatedSprite(ResourceManager::GetTexture("Centipede Body"), 8, 2); MainSprite.setScale(2,2); MainSprite.setOrigin( MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); }
Enemy::Enemy(std::string texture, MushroomField* theField, int horizantalDivisions, int verticalDivisions) { field = theField; strTexture = texture; bitmap = ResourceManager::GetTextureBitmap(texture); MainSprite = AnimatedSprite(ResourceManager::GetTexture(texture), horizantalDivisions, verticalDivisions); MainSprite.setOrigin( MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); MainSprite.setScale(1,1); }
void CentipedeBodyPart::RemoveAncestor() { if(hasAncestor) { hasAncestor = false; bitmap = ResourceManager::GetTextureBitmap("Centipede Head"); MainSprite = AnimatedSprite(ResourceManager::GetTexture("Centipede Head"), 8, 2); MainSprite.setScale(2,2); MainSprite.setOrigin( MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); } }
Spider::Spider(const sf::Vector2f SpawnLocation,const float speed,const sf::Vector2i InitialDirection,Mushroomfield& father){ //set up definition of top border TOPBORDER =WindowManager::MainWindow.getView().getSize().y-(MUSHROOMSEGMENT*11 - MUSHROOMSEGMENT/2); BottomBlasterBorder= WindowManager::MainWindow.getView().getSize().y - (MUSHROOMSEGMENT/2)-MUSHROOMSEGMENT; //sets up time generated seed of rand srand(time(NULL)); //plays spider sound on construction SoundManager::PlaySpiderSound(); //set up bool IsOnBorder=false; //sets up initial location and field Flea Belongs to WorldPosition = SpawnLocation; FatherMushroomfield = &father; //sets up inital speed with initial direction Speed=speed; Direction=InitialDirection; //Sets up the visual Sprite Sprite = AnimatedSprite(ResourceManager::GetTexture("Spider"),4,2); Sprite.SetAnimation(0,5,true,true); Sprite.SetLoopSpeed(24.0f); Sprite.setOrigin(Sprite.getTextureRect().width / 2.0f, Sprite.getTextureRect().height / 2.0f); Sprite.setPosition(WorldPosition); Sprite.setScale(2,2); //Sets up Collider bitmap = ResourceManager::GetTextureBitmap("Spider"); SetCollider(Sprite,bitmap,true); RegisterCollision<Spider>(*this); //Sets Draw Order SetDrawOrder(999); //Set up The precomputed Downward motion with initial speed for(int i =0;i<MUSHROOMSEGMENT/speed;i++){ DownwardQueue.push(PositionAndRotationOffset(sf::Vector2f(0,speed),0,sf::Vector2f(0,1),false)); } //Set up The precomputed Diagonal motion with initial speed for(int i =0;i<MUSHROOMSEGMENT/speed;i++){ DiagonalQueue.push(PositionAndRotationOffset(sf::Vector2f(speed,speed),0,sf::Vector2f(0,1),false)); } }
Player::Player(jframe::Window* window, jvis::Texture* tex, LevelLoader* level, const jmath::vec4& rect, int cols, int frames, int delay) : p_Window(window), m_CanJump(true), m_JumpBtnHeld(false), m_Health(0), // 28 m_TimerJump(0), m_Direction(Mega::Direction::RIGHT), jvis::AnimatedSprite(tex, rect, cols, 1, delay) { p_Level = level; SetDelay(delay); // Physics setup SetSize(jmath::vec2(32, 32)); GetRigidBody()->SetFriction(1.f); GetRigidBody()->SetMass(15.f); GetRigidBody()->SetDimensions(jmath::vec3(18, 28, 0)); GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE); // Collision flags are removed because m_CollisionX and Y will deal with it GetRigidBody()->RemoveCollisionFlags(jphys::CollisionFlags::ResolveX); GetRigidBody()->RemoveCollisionFlags(jphys::CollisionFlags::ResolveY); // Collision resolution setup - these are to resolve X and Y collision separately m_CollisionY.GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE); m_CollisionY.GetRigidBody()->SetCollisionFlags(jphys::CollisionFlags::ResolveY); m_CollisionY.SetSize(jmath::vec2(8, 28)); m_CollisionY.GetRigidBody()->MoveY(-3); m_CollisionX.GetRigidBody()->SetCollisionType(jphys::CollisionType::BOX_REACTIVE); m_CollisionX.GetRigidBody()->SetCollisionFlags(jphys::CollisionFlags::ResolveX); m_CollisionX.SetSize(jmath::vec2(18, 24)); m_CollisionX.GetRigidBody()->MoveY(-3); // The 12 sprites that move outwards upon death for (int i = 0; i < 12; ++i) { m_DeathSprites.push_back(AnimatedSprite()); m_DeathSprites.back().SetRectangle(jmath::vec4(8, 184, 16, 16)); m_DeathSprites.back().SetSize(jmath::vec2(16)); m_DeathSprites.back().SetNumColumns(4); m_DeathSprites.back().SetNumFrames(4); m_DeathSprites.back().SetTexture(GetTexture()); } m_TimerDeath.SetTime(JTime::Milliseconds(DEATH_ANIMATION_TIME)); m_TimerInvincibility.SetTime(JTime::Milliseconds(INVINCIBILITY_TIME)); m_TimerBulletAnimationDelay.SetTime(JTime::Milliseconds(FIRING_ANIMATION_DELAY)); }
void CentipedeBodyPart::Initialize(MushroomField* field, sf::Vector2f position, Centipede* theCreator, int speed, int buildNumber) { //inheirted graphics info bitmap = ResourceManager::GetTextureBitmap("Centipede Head"); MainSprite = AnimatedSprite(ResourceManager::GetTexture("Centipede Head"), 8, 2); MainSprite.setScale(2,2); MainSprite.setOrigin( MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); MainSprite.setPosition(Pos); centipedeBodyPartWidth = MainSprite.getTextureRect().width * 2; centipedeBodyPartHeight = MainSprite.getTextureRect().height * 2; SetCollider(MainSprite, bitmap, true); RegisterCollision<CentipedeBodyPart>(*this); //Set animation and rotation for movement MainSprite.SetAnimation(0, 7); MainSprite.setRotation(180); //private variables mushroomField = field; creator = theCreator; beenToTheEnd = false; hasAncestor = false; hasDescendant = false; turning = false; poisoned = false; SPEED = speed; moveDir = 1; distanceToNextLookAhead = SpriteSize; numberInBuildList = buildNumber; Pos = position; centipedeBodyPartWidth = SpriteSize; centipedeBodyPartHeight = SpriteSize; SpawnOffset = sf::Vector2f(HalfSpriteSize, HalfSpriteSize); currentState = Enumerators::centipedeMovementMode::Right; previousState = currentState; //Adjusted Speed set for the first time directionalSPEED = SPEED * moveDir; SoundManager::StartCentipedeLoop(); }
Shot::Shot(sf::Vector2f p, Blaster* b) { SPEED = 700; bitmap = ResourceManager::GetTextureBitmap("Shot"); MainSprite = AnimatedSprite( ResourceManager::GetTexture("Shot"), 1, 1); MainSprite.SetAnimation(0, 0, false, false); MainSprite.setOrigin(MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); MainSprite.setScale(1,1); SetCollider(MainSprite, bitmap); fired = false; Pos = p; blaster = b; RegisterCollision<Shot>( *this ); }
SnakeSlime::SnakeSlime(TextureManager &textureManager, b2Body *enemyBody) : Entity(enemyBody){ sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet); Animation wiggleAnimation; wiggleAnimation.setSpriteSheet(spriteSheet); wiggleAnimation.addFrame(sf::IntRect(424, 187, 53, 147)); wiggleAnimation.addFrame(sf::IntRect(425, 40, 52, 147)); mAnimation = wiggleAnimation; mSprite = AnimatedSprite(sf::seconds(0.15f)); mSprite.setAnimation(mAnimation); sf::FloatRect bounds = mSprite.getLocalBounds(); mSprite.setOrigin(bounds.width/2, bounds.height/2); }
Scorpion::Scorpion(sf::Vector2f p, float lr) { bitmap = ResourceManager::GetTextureBitmap("Scorpion"); MainSprite = AnimatedSprite( ResourceManager::GetTexture("Scorpion"), 4, 1); MainSprite.SetAnimation(0,3); MainSprite.setOrigin( MainSprite.getTextureRect().width / 2.0f, MainSprite.getTextureRect().height / 2.0f); MainSprite.setScale(1,1); Pos=p; leftRight=lr; MainSprite.setPosition(Pos); SetCollider(MainSprite, bitmap, true); RegisterCollision<Scorpion>(*this); }
VillagerC::VillagerC() { Texture* tex = textureLoader::getTexture("friendly_npcs"); AnimatedSprite sprite = AnimatedSprite(&tex->texture, 0, 0, tex->cellWidth, tex->cellHeight, 0 * tex->uSize, 5 * tex->vSize, 1 * tex->uSize, 1 * tex->vSize); *this = VillagerC((VillagerC&)sprite); type = 1; name = "villagerC"; isAnimated = false; //Setup Collider int xOffset = 18; int yOffset = 15; int width = 28; int height = 45; float uSize = 1; float vSize = 1; colliderXOffset = xOffset; colliderYOffset = yOffset; setCollider(&AABB(x + xOffset, y + yOffset, width, height)); maxSpeed = 50; isColliderDrawn = false; // Walking Animation int numFrames = 1; int timeToNextFrame = 300; std::vector<AnimationFrame> frames; frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 5, uSize, vSize); //frames[1] = AnimationFrame(1, 0, uSize, vSize); Animation animation_walking = Animation("Walking", frames, numFrames); animations[animation_walking.name] = AnimationData(animation_walking, timeToNextFrame, true); // Idle Animation numFrames = 1; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 5, uSize, vSize); Animation animation_idle = Animation("Idle", frames, numFrames); animations[animation_idle.name] = AnimationData(animation_idle, timeToNextFrame, true); //setAnimation("Walking"); }
Chicken::Chicken() { Texture* tex = textureLoader::getTexture("cucco"); AnimatedSprite sprite = AnimatedSprite(&tex->texture, 0, 0, tex->width, tex->height, 0, 0, 0.5, 1); *this = Chicken((Chicken&)sprite); type = 1; name = "cucco"; //Setup Collider int xOffset = 20; int yOffset = 25; int width = 20; int height = 20; float uSize = 0.5; float vSize = 1; colliderXOffset = xOffset; colliderYOffset = yOffset; setCollider(&AABB(x + xOffset, y + yOffset, width, height)); maxSpeed = 50; // Walking Animation int numFrames = 2; int timeToNextFrame = 300; std::vector<AnimationFrame> frames; frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 0, uSize, vSize); frames[1] = AnimationFrame(0.5, 0, uSize, vSize); Animation animation_walking = Animation("Walking", frames, numFrames); animations[animation_walking.name] = AnimationData(animation_walking, timeToNextFrame, true); // Idle Animation numFrames = 1; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 0, uSize, vSize); Animation animation_idle = Animation("Idle", frames, numFrames); animations[animation_idle.name] = AnimationData(animation_idle, timeToNextFrame, true); setAnimation("Walking"); }
Stag::Stag(float x, float y) { m_health = 70; m_position.x = x; m_position.y = y; m_bodyTexture.loadFromFile("Assets/Graphics/NPC/bodyStagNPC.png"); m_bodyTexture.setSmooth(true); m_bodySprite.setTexture(m_bodyTexture); m_bodySprite.setOrigin(m_bodySprite.getLocalBounds().width / 2, m_bodySprite.getLocalBounds().height / 2); m_bodySprite.setRotation(0); m_bodySprite.setPosition(m_position.x, m_position.y); m_headTexture.loadFromFile("Assets/Graphics/NPC/headStagNPC.png"); m_headTexture.setSmooth(true); m_headSprite.setTexture(m_headTexture); m_headSprite.setOrigin(60.0f, 45.0f); m_headSprite.setPosition(m_position.x, m_position.y - DistanceOfNeck); m_tailTexture.loadFromFile("Assets/Graphics/NPC/tailStagNPC.png"); m_tailTexture.setSmooth(true); m_tailSprite.setTexture(m_tailTexture); m_tailSprite.setOrigin(9.0f, 3.0f); m_tailSprite.setPosition(m_position.x, m_position.y - DistanceOfTail); m_selectedTex.loadFromFile("Assets/Graphics/NPC/selectedStag.png"); m_selectedTex.setSmooth(true); m_selectedSprite.setTexture(m_selectedTex); m_selectedSprite.setOrigin(m_selectedSprite.getLocalBounds().width / 2, m_selectedSprite.getLocalBounds().height / 2); m_selectedSprite.setPosition(m_position.x, m_position.y); // Attack animations // texture m_bashTexture.loadFromFile("Assets/Graphics/Actions/bashSheet.png"); m_attackAreaTex.loadFromFile("Assets/Graphics/Actions/attackArea.png"); m_attackArea.setTexture(m_attackAreaTex); // animation m_bashAnimation.setSpriteSheet(m_bashTexture); m_bashAnimation.addFrame(sf::IntRect(0, 144, 64, 35)); m_bashAnimation.addFrame(sf::IntRect(0, 108, 64, 35)); m_bashAnimation.addFrame(sf::IntRect(0, 72, 64, 35)); m_bashAnimation.addFrame(sf::IntRect(0, 36, 64, 35)); m_bashAnimation.addFrame(sf::IntRect(0, 0, 64, 35)); m_currentAnimation = &m_bashAnimation; m_animatedSprite = AnimatedSprite(sf::seconds(0.085), true, false); m_animatedSprite.setOrigin(32, 14); m_animatedSprite.setPosition(m_position.x, m_position.y - DistanceOfAttack); m_speed = 2.5; m_colour = sf::Color(255,162,68,100); m_emitter = Emitter(m_position.x, m_position.y, m_colour); //Sounds //m_injuredBuffer.loadFromFile("Assets/Audio/NPC/Doe/doeSound.wav"); //m_injuredSound.setBuffer(m_injuredBuffer); //m_injuredSound.setRelativeToListener(false); //m_injuredSound.setPosition(200, 200, 0); //m_injuredSound.setAttenuation(5); m_deathBuffer.loadFromFile("Assets/Audio/NPC/Stag/stagDead.wav"); m_deathSound.setBuffer(m_deathBuffer); m_deathSound.setRelativeToListener(false); m_deathSound.setAttenuation(10); }
Player::Player(int WIDTH, int HEIGHT) { //Set up the animations. if (LoadTexture()) { m_pMoveAnimation.setSpriteSheet(texture); m_pMoveAnimation.addFrame(sf::IntRect(0, 0, 71, 40)); m_pMoveAnimation.addFrame(sf::IntRect(142, 0, 71, 40)); m_pMoveAnimation.addFrame(sf::IntRect(213, 0, 71, 40)); m_pStopMoveAnimation.setSpriteSheet(texture); m_pStopMoveAnimation.addFrame(sf::IntRect(213, 0, 71, 40)); m_pStopMoveAnimation.addFrame(sf::IntRect(142, 0, 71, 40)); m_pStopMoveAnimation.addFrame(sf::IntRect(0, 0, 71, 40)); m_playerAnimation = AnimatedSprite(sf::seconds(0.15f)); m_playerAnimation.setAnimation(m_pMoveAnimation); lastframe = 2; firstFrame = 0; m_upPressedOnce = false; playerDecelleration = true; speedPowerUpActive = false; healthPowerUpActive = false; shieldPowerUpActive = false; playerRect.setSize(sf::Vector2f(50, 40)); playerRect.setOrigin(sf::Vector2f(25, 20)); healthRectangle.setSize(sf::Vector2f(200, 50)); healthRectangle.setTexture(&healthTexture); healthRectangle.setPosition(sf::Vector2f(0, 0)); healthRectangle.setTextureRect(sf::IntRect(1800, 0, 200, 50)); shieldRectangle.setSize(sf::Vector2f(200, 50)); shieldRectangle.setTexture(&shieldTexture); shieldRectangle.setPosition(sf::Vector2f(200, 0)); shieldRectangle.setTextureRect(sf::IntRect(0, 0, 200, 50)); //Player and Shield have 10 images each indicating each health shieldHealth = 10; playerHealth = 10; } sprite.setTexture(texture); sprite.setOrigin(35.5f, 20); m_playerAnimation.setOrigin(sf::Vector2f(35.5, 20)); speed = 0; accerationRate = 100; accelertation = 0; max_Speed = 300; friction = -10; rotation = 0; rotationSpeed = 90; m_Direction = sf::Vector2f(cos(VectorMath::GetInstance()->ToRadian(rotation)), sin(VectorMath::GetInstance()->ToRadian(rotation))); SCREEN_WIDTH = WIDTH; SCREEN_HEIGHT = HEIGHT; timeSinceFire = 0; fireDelay = 0.25f; readyToFire = true; noOfHits = 0; m_Radius = texture.getSize().y/2; bulletSpeed = 900; alive = true; //speedPowerUpTime = 0; }