void Element::adjustPosition(Manifold* collidingObjectManifold) { const qreal percent = .5; const qreal slop = .05; qreal correction_x = std::max<qreal>(collidingObjectManifold->penetration, slop) / (this->getInvWeight() + collidingObjectManifold->second_object->getInvWeight()) * percent * collidingObjectManifold->normal_x; qreal correction_y = std::max<qreal>(collidingObjectManifold->penetration, slop) / (this->getInvWeight() + collidingObjectManifold->second_object->getInvWeight()) * percent * collidingObjectManifold->normal_y; setPosX(x() - this->getInvWeight() * correction_x); setPosY(y() - this->getInvWeight() * correction_y); }
Unit::Unit(float pos_x, float pos_y, std::string name) : EntityAction(pos_x, pos_y, UNIT_INV_CAP) { setSprite( new Sprite(pos_x, pos_y, UNIT_CLICK_WIDTH, UNIT_CLICK_HEIGHT, UNIT_CLICK_OFFSET_X, UNIT_CLICK_OFFSET_Y) ); setPosX(pos_x); setPosY(pos_y); setName(name); setDead(false); }
IElement::IElement(unsigned int hp, unsigned int posX ,unsigned int posY, unsigned int sizeX, unsigned int sizeY, int speed, std::string* skin){ setHp(hp); setPosX(posX); setPosY(posY); setSizeX(sizeX); setSizeY(sizeY); setSpeed(speed); setSkin(skin); return ; }
void Settings::readSettings() { setLanguage(value(KEY_LANGUAGE, defaultValue(KEY_LANGUAGE)).toString()); setPlaylist(value(KEY_PLAYLIST, defaultValue(KEY_PLAYLIST)).toString()); setPlaylistUpdate(value(KEY_PLAYLIST_UPDATE, defaultValue(KEY_PLAYLIST_UPDATE)).toBool()); setPlaylistUpdateUrl(value(KEY_PLAYLIST_UPDATE_URL, defaultValue(KEY_PLAYLIST_UPDATE_URL)).toString()); setRadioCategory(value(KEY_RADIO_CATEGORY, defaultValue(KEY_RADIO_CATEGORY)).toString()); setHdCategory(value(KEY_HD_CATEGORY, defaultValue(KEY_HD_CATEGORY)).toString()); setUdpxy(value(KEY_UDPXY, defaultValue(KEY_UDPXY)).toBool()); setUdpxyUrl(value(KEY_UDPXY_URL, defaultValue(KEY_UDPXY_URL)).toString()); setUdpxyPort(value(KEY_UDPXY_PORT, defaultValue(KEY_UDPXY_PORT)).toInt()); setWidth(value(KEY_WIDTH, defaultValue(KEY_WIDTH)).toInt()); setHeight(value(KEY_HEIGHT, defaultValue(KEY_HEIGHT)).toInt()); setPosX(value(KEY_POS_X, defaultValue(KEY_POS_X)).toInt()); setPosY(value(KEY_POS_Y, defaultValue(KEY_POS_Y)).toInt()); setOsd(value(KEY_OSD, defaultValue(KEY_OSD)).toBool()); setTrayEnabled(value(KEY_TRAY_ENABLED, defaultValue(KEY_TRAY_ENABLED)).toBool()); setHideToTray(value(KEY_HIDE_TO_TRAY, defaultValue(KEY_HIDE_TO_TRAY)).toBool()); setMouseWheel(value(KEY_MOUSE_WHEEL, defaultValue(KEY_MOUSE_WHEEL)).toString()); setRememberGuiSession(value(KEY_REMEMBER_GUI_SESSION, defaultValue(KEY_REMEMBER_GUI_SESSION)).toBool()); setIcons(value(KEY_ICONS, defaultValue(KEY_ICONS)).toString()); setVout(value(KEY_VOUT, defaultValue(KEY_VOUT)).toInt()); setAout(value(KEY_AOUT, defaultValue(KEY_AOUT)).toInt()); setYuvToRgb(value(KEY_YUV_TO_RGB, defaultValue(KEY_MUTE_ON_MINIMIZE)).toBool()); setSpdif(value(KEY_SPDIF, defaultValue(KEY_SPDIF)).toBool()); setRememberVideoSettings(value(KEY_REMEMBER_VIDEO_SETTINGS, defaultValue(KEY_REMEMBER_VIDEO_SETTINGS)).toBool()); setRememberVideoPerChannel(value(KEY_REMEMBER_VIDEO_PER_CHANNEL, defaultValue(KEY_REMEMBER_VIDEO_PER_CHANNEL)).toBool()); setAspectRatio(value(KEY_ASPECT_RATIO, defaultValue(KEY_ASPECT_RATIO)).toInt()); setCropRatio(value(KEY_CROP_RATIO, defaultValue(KEY_CROP_RATIO)).toInt()); setDeinterlacing(value(KEY_DEINTERLACING, defaultValue(KEY_DEINTERLACING)).toInt()); setAudioLanguage(value(KEY_AUDIO_LANGUAGE, defaultValue(KEY_AUDIO_LANGUAGE)).toString()); setSubtitleLanguage(value(KEY_SUBTITLE_LANGUAGE, defaultValue(KEY_SUBTITLE_LANGUAGE)).toString()); setMuteOnMinimize(value(KEY_MUTE_ON_MINIMIZE, defaultValue(KEY_MUTE_ON_MINIMIZE)).toBool()); setTeletext(value(KEY_TELETEXT, defaultValue(KEY_TELETEXT)).toBool()); setRecorderDirectory(value(KEY_RECORDER_DIRECTORY, defaultValue(KEY_RECORDER_DIRECTORY)).toString()); setSnapshotsDirectory(value(KEY_SNAPSHOTS_DIRECTORY, defaultValue(KEY_SNAPSHOTS_DIRECTORY)).toString()); setSessionAutoplay(value(KEY_SESSION_AUTOPLAY, defaultValue(KEY_SESSION_AUTOPLAY)).toBool()); setSessionChannel(value(KEY_SESSION_CHANNEL, defaultValue(KEY_SESSION_CHANNEL)).toInt()); setSessionRememberVolume(value(KEY_SESSION_REMEMBER_VOLUME, defaultValue(KEY_SESSION_REMEMBER_VOLUME)).toBool()); setSessionVolume(value(KEY_SESSION_VOLUME, defaultValue(KEY_SESSION_VOLUME)).toInt()); setXmltvUpdate(value(KEY_XMLTV_UPDATE, defaultValue(KEY_XMLTV_UPDATE)).toBool()); setXmltvUpdateLocation(value(KEY_XMLTV_UPDATE_LOCATION, defaultValue(KEY_XMLTV_UPDATE_LOCATION)).toString()); setXmltvUpdateRemote(value(KEY_XMLTV_UPDATE_REMOTE, defaultValue(KEY_XMLTV_UPDATE_REMOTE)).toBool()); }
Sprite::Sprite(float x, float y, float click_w, float click_h, float click_offset_x, float click_offset_y, float scale) { //click w and h define the width and height of click collide rect, offset are pos corrections mFilename = "res/images/iso/map/0.png"; setPosX(x); setPosY(y); mRenderer = nullptr; mWindow = nullptr; setClickHeight(click_h); setClickWidth(click_w); setClickOffsetX(click_offset_x); setClickOffsetY(click_offset_y); setScale(scale); }
Bomb::Bomb(int _X, int _Y): Sprites("Balst.png",3 , 5){ //set fuse animation loop loopMode(true, 0 ,5); setWH(20 ,20); //this is a blastlet setBlast(true); //initialises the objects member variables setPosX(_X); setPosY(_Y); setPos(getPosX(), getPosY()); }
TextLine::TextLine(float x, float y, float w, float h, std::string message, TextMaker * maker) { mTexture = nullptr; setPosX(x); setPosY(y); setWidth(w); setHeight(h); setTextMaker(maker); //loadText(message); setText(message); setActive(false); }
void Entity::load(QXmlStreamReader *xml) { setPosX(xml->attributes().value("x").toString().toInt()); setPosY(xml->attributes().value("y").toString().toInt()); setPosZ(xml->attributes().value("z").toString().toInt()); setTexX(xml->attributes().value("tx").toString().toFloat()); setTexY(xml->attributes().value("ty").toString().toFloat()); setAngle(xml->attributes().value("angle").toString().toInt()); setWidth(xml->attributes().value("width").toString().toInt()); setHeight(xml->attributes().value("height").toString().toInt()); tex = TexturesManager::getInstance()->getTexture(xml->attributes().value("texture").toString()); xml->skipCurrentElement(); xml->readNext(); }
Sprite::Sprite(std::string filename, float x, float y, SDL_Renderer *renderer, SDL_Window *window, float scale) { mTexture = nullptr; mRenderer = nullptr; mWindow = nullptr; mTexture = loadTexture(filename, renderer, true); mRenderer = renderer; mWindow = window; setPosX(x); setPosY(y); setScale(scale); //SDL_Rect * mRect = new SDL_Rect() }
Bomb::Bomb(int _X, int _Y, int _F, int _T): Sprites("Balst.png",3 , 5){ //set fuse animation loop loopMode(true, 10 ,15); //initialises the objects member variables setPosX(_X); setPosY(_Y); setPos(getPosX(), getPosY()); setBombTicks(_T); setFlame(_F); setWH(20 ,20); //not used yet setUsed(false); //not igniting setIgnite(false); //is a bomb not a blast setBlast(false); }
void LVL_Npc::update(float tickTime) { float accelCof=tickTime/1000.0f; if(killed) return; if(wasDeactivated) return; _onGround = !collided_bottom.isEmpty(); if(isGenerator) { updateCollisions(); activationTimeout-=tickTime; updateGenerator(tickTime); return; } event_queue.processEvents(tickTime); if(warpSpawing) { setSpeed(0.0, 0.0); return; } PGE_Phys_Object::update(tickTime); if(deActivatable) activationTimeout-=tickTime; animator.manualTick(tickTime); if(motionSpeed!=0) { if(!collided_left.isEmpty()) setDirection(1); else if(!collided_right.isEmpty()) setDirection(-1); else if(setup->turn_on_cliff_detect && cliffDetected) { setDirection(_direction*-1); cliffDetected=false; } setSpeedX((motionSpeed*accelCof)*_direction); } if(not_movable()) { detector_player_pos.processDetector(); if(detector_player_pos.directedTo()!=0) setDirection(detector_player_pos.directedTo()); } LVL_Section *section=sct(); PGE_RectF sBox = section->sectionRect(); if(section->isWarp()) { if(posX()<sBox.left()-_width-1 ) setPosX(sBox.right()-1); else if(posX()>sBox.right() + 1 ) setPosX(sBox.left()-_width+1); } for(int i=0; i<detectors.size(); i++) detectors[i]->processDetector(); try { lua_onLoop(tickTime); } catch (luabind::error& e) { LvlSceneP::s->getLuaEngine()->postLateShutdownError(e); } }
void LVL_Player::update(float ticks) { if(isLocked) return; if(!_isInited) return; if(!camera) return; LVL_Section* section = sct(); if(!section) return; event_queue.processEvents(ticks); if((isWarping) || (!isAlive)) { animator.tickAnimation(ticks); updateCamera(); return; } _onGround = !foot_contacts_map.isEmpty(); on_slippery_surface = !foot_sl_contacts_map.isEmpty(); bool climbableUp = !climbable_map.isEmpty(); bool climbableDown= climbableUp && !_onGround; climbing = (climbableUp && climbing && !_onGround && (posRect.center().y()>=(climbableHeight-physics_cur.velocity_climb_y_up)) ); if(_onGround) { phys_setup.decelerate_x = (fabs(speedX())<=physics_cur.MaxSpeed_walk)? (on_slippery_surface?physics_cur.decelerate_stop/physics_cur.slippery_c : physics_cur.decelerate_stop): (on_slippery_surface?physics_cur.decelerate_run/physics_cur.slippery_c : physics_cur.decelerate_run); if(physics_cur.strict_max_speed_on_ground) { if((speedX()>0)&&(speedX()>phys_setup.max_vel_x)) setSpeedX(phys_setup.max_vel_x); else if((speedX()<0)&&(speedX()<phys_setup.min_vel_x)) setSpeedX(phys_setup.min_vel_x); } } else phys_setup.decelerate_x = physics_cur.decelerate_air; if(doKill) { doKill=false; isAlive = false; setPaused(true); LvlSceneP::s->checkPlayers(); return; } if(climbing) { PGE_Phys_Object* climbableItem = static_cast<PGE_Phys_Object*>((void*)(intptr_t)climbable_map[climbable_map.keys().first()]); if(climbableItem) { _velocityX_add=climbableItem->speedX(); _velocityY_add=climbableItem->speedY(); } else { _velocityX_add=0.0f; _velocityY_add=0.0f; } if(gscale_Backup != 1) { setGravityScale(0); gscale_Backup = 1; } } else { if(gscale_Backup != 0.f) { setGravityScale(physics_cur.gravity_scale); gscale_Backup = 0.f; } } if(climbing) { setSpeed(0,0); } if(environments_map.isEmpty()) { if(last_environment!=section->getPhysicalEnvironment() ) { environment = section->getPhysicalEnvironment(); } } else { int newEnv = section->getPhysicalEnvironment(); foreach(int x, environments_map) { newEnv = x; } if(last_environment != newEnv) { qDebug()<<"Enter to environment" << newEnv; environment = newEnv; } } refreshEnvironmentState(); if(_onGround) { if(!floating_isworks) { floating_timer=floating_maxtime; } } //Running key if(keys.run) { if(!_isRunning) { phys_setup.max_vel_x = physics_cur.MaxSpeed_run; phys_setup.min_vel_x = -physics_cur.MaxSpeed_run; _isRunning=true; } } else { if(_isRunning) { phys_setup.max_vel_x = physics_cur.MaxSpeed_walk; phys_setup.min_vel_x = -physics_cur.MaxSpeed_walk; _isRunning=false; } } if((physics_cur.ground_c_max!=1.0f)) { phys_setup.max_vel_x = fabs(_isRunning ? physics_cur.MaxSpeed_run : physics_cur.MaxSpeed_walk) *(_onGround?physics_cur.ground_c_max:1.0f); phys_setup.min_vel_x = -fabs(_isRunning ? physics_cur.MaxSpeed_run : physics_cur.MaxSpeed_walk) *(_onGround?physics_cur.ground_c_max:1.0f); } if(keys.alt_run) { if(attack_enabled && !attack_pressed && !climbing) { attack_pressed=true; if(keys.up) attack(Attack_Up); else if(keys.down) attack(Attack_Down); else { attack(Attack_Forward); PGE_Audio::playSoundByRole(obj_sound_role::PlayerTail); animator.playOnce(MatrixAnimator::RacoonTail, _direction, 75, true, true, 1); } } } else { if(attack_pressed) attack_pressed=false; } //if if(!keys.up && !keys.down && !keys.left && !keys.right) { if(wasEntered) { wasEntered = false; wasEnteredTimeout=0; } } //Reset state if(wasEntered) { wasEnteredTimeout-=ticks; if(wasEnteredTimeout<0) { wasEnteredTimeout=0; wasEntered=false; } } if(keys.up) { if(climbableUp&&(jumpTime<=0)) { setDuck(false); climbing=true; floating_isworks=false;//!< Reset floating on climbing start } if(climbing) { if(posRect.center().y() >= climbableHeight) setSpeedY(-physics_cur.velocity_climb_y_up); } } if(keys.down) { if( climbableDown && (jumpTime<=0) ) { setDuck(false); climbing=true; floating_isworks=false;//!< Reset floating on climbing start } else { if((duck_allow & !ducking)&&( (animator.curAnimation()!=MatrixAnimator::RacoonTail) ) ) { setDuck(true); } } if(climbing) { setSpeedY(physics_cur.velocity_climb_y_down); } } else { if(ducking) setDuck(false); } if( (!keys.left) || (!keys.right) ) { bool turning=(((speedX()>0)&&(_direction<0))||((speedX()<0)&&(_direction>0))); float force = turning? physics_cur.decelerate_turn : (fabs(speedX())>physics_cur.MaxSpeed_walk)?physics_cur.run_force : physics_cur.walk_force; if(on_slippery_surface) force=force/physics_cur.slippery_c; else if((_onGround)&&(physics_cur.ground_c!=1.0f)) force=force*physics_cur.ground_c; if(keys.left) _direction=-1; if(keys.right) _direction=1; if(!ducking || !_onGround) { //If left key is pressed if(keys.right && collided_right.isEmpty()) { if(climbing) setSpeedX(physics_cur.velocity_climb_x); else applyAccel(force, 0); } //If right key is pressed if(keys.left && collided_left.isEmpty()) { if(climbing) setSpeedX(-physics_cur.velocity_climb_x); else applyAccel(-force, 0); } } } if( keys.alt_jump ) { //Temporary it is ability to fly up! if(!bumpDown && !bumpUp) { setSpeedY(-physics_cur.velocity_jump); } } if( keys.jump ) { if(!JumpPressed) { if(environment!=LVL_PhysEnv::Env_Water) { if(climbing || _onGround || (environment==LVL_PhysEnv::Env_Quicksand)) PGE_Audio::playSoundByRole(obj_sound_role::PlayerJump); } else PGE_Audio::playSoundByRole(obj_sound_role::PlayerWaterSwim); } if((environment==LVL_PhysEnv::Env_Water)||(environment==LVL_PhysEnv::Env_Quicksand)) { if(!JumpPressed) { if(environment==LVL_PhysEnv::Env_Water) { if(!ducking) animator.playOnce(MatrixAnimator::SwimUp, _direction, 75); } else if(environment==LVL_PhysEnv::Env_Quicksand) { if(!ducking) animator.playOnce(MatrixAnimator::JumpFloat, _direction, 64); } JumpPressed=true; jumpTime = physics_cur.jump_time; jumpVelocity=physics_cur.velocity_jump; floating_timer = floating_maxtime; setSpeedY(speedY()-jumpVelocity); } } else if(!JumpPressed) { JumpPressed=true; if(_onGround || climbing) { climbing=false; jumpTime=physics_cur.jump_time; jumpVelocity=physics_cur.velocity_jump; floating_timer = floating_maxtime; setSpeedY(-jumpVelocity-fabs(speedX()/physics_cur.velocity_jump_c)); } else if((floating_allow)&&(floating_timer>0)) { floating_isworks=true; //if true - do floating with sin, if false - do with cos. floating_start_type=(speedY()<0); setSpeedY(0); setGravityScale(0); } } else { if(jumpTime>0) { jumpTime -= ticks; setSpeedY(-jumpVelocity-fabs(speedX()/physics_cur.velocity_jump_c)); } if(floating_isworks) { floating_timer -= ticks; if(floating_start_type) setSpeedY( state_cur.floating_amplitude*(-cos(floating_timer/80.0)) ); else setSpeedY( state_cur.floating_amplitude*(cos(floating_timer/80.0)) ); if(floating_timer<=0) { floating_timer=0; floating_isworks=false; setGravityScale(climbing?0:physics_cur.gravity_scale); } } } } else { jumpTime=0; if(JumpPressed) { JumpPressed=false; if(floating_allow) { if(floating_isworks) { floating_timer=0; floating_isworks=false; setGravityScale(climbing?0:physics_cur.gravity_scale); } } } } refreshAnimation(); animator.tickAnimation(ticks); PGE_RectF sBox = section->sectionLimitBox(); //Return player to start position on fall down if( posY() > sBox.bottom()+_height ) { kill(DEAD_fall); } if(bumpDown) { bumpDown=false; jumpTime=0; setSpeedY(bumpVelocity); } else if(bumpUp) { bumpUp=false; if(keys.jump) { jumpTime=bumpJumpTime; jumpVelocity=bumpJumpVelocity; } setSpeedY( (keys.jump ? (-fabs(bumpJumpVelocity)-fabs(speedX()/physics_cur.velocity_jump_c)): -fabs(bumpJumpVelocity)) ); } //Connection of section opposite sides if(isExiting) // Allow walk offscreen if exiting { if((posX() < sBox.left()-_width-1 )||(posX() > sBox.right() + 1 )) { setGravityScale(0.0);//Prevent falling [we anyway exited from this level, isn't it?] setSpeedY(0.0); } if(keys.left||keys.right) { if((environment==LVL_PhysEnv::Env_Water)||(environment==LVL_PhysEnv::Env_Quicksand)) { keys.run=true; if(_exiting_swimTimer<0 && !keys.jump) keys.jump=true; else if(_exiting_swimTimer<0 && keys.jump) { keys.jump=false; _exiting_swimTimer=(environment==LVL_PhysEnv::Env_Quicksand)? 1 : 500; } _exiting_swimTimer-= ticks; } else keys.run=false; } } else if(section->isWarp()) { if(posX() < sBox.left()-_width-1 ) setPosX( sBox.right()+1 ); else if(posX() > sBox.right() + 1 ) setPosX( sBox.left()-_width-1 ); } else { if(section->ExitOffscreen()) { if(section->RightOnly()) { if( posX() < sBox.left()) { setPosX( sBox.left() ); setSpeedX(0.0); } } if((posX() < sBox.left()-_width-1 ) || (posX() > sBox.right() + 1 )) { setLocked(true); _no_render=true; LvlSceneP::s->setExiting(1000, LvlExit::EXIT_OffScreen); return; } } else { //Prevent moving of player away from screen if( posX() < sBox.left()) { setPosX(sBox.left()); setSpeedX(0.0); } else if( posX()+_width > sBox.right()) { setPosX(sBox.right()-_width); setSpeedX(0.0); } } } if(_stucked) { posRect.setX(posRect.x()-_direction*2); applyAccel(0, 0); } processWarpChecking(); if(_doSafeSwitchCharacter) setCharacter(characterID, stateID); try { lua_onLoop(); } catch (luabind::error& e) { LvlSceneP::s->getLuaEngine()->postLateShutdownError(e); } updateCamera(); }
void Ball::reset() { setPosX(4); setPosY(3); drop(); }
void Element::updateStateX(void) { //accelerationX += 0; this->setVelocityX(this->getVelocityX() + this->getAccelerationX() / 100); setPosX(scenePos().x() + this->getVelocityX() * 10 / 100); }
void Drawable::setPosition(float x, float y) // Set position. Two coordinates. { setPosX(x); setPosY(y); }