private void updateParticle2(float step_time, Particle p, cWorld world) { p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); // p.Vel.X *= p.SlowDown; // p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed); //world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
public override void Update(float step_time) { cWorld world = particleManager.Scene.World; for (int i = 0; i < pool.CountActive; ++i) { Particle p = pool.get(i); if (!p.Intersects) { /* * p.Dims.Y += p.ScaleSpeed * step_time; //+= * p.Dims.y += p.ScaleSpeed * step_time; //+= */ AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); } p.Opacity -= p.Fade * step_time; if (p.Opacity <= 0.0f) { p.Opacity = 0.0f; pool.deactivate(i); } p.Color.A = (byte)p.Opacity; } }
private void init(Vector2f pos, Vector2f emit_direction) { this.pickedUp = pulling = false; this.heading = emit_direction; this.renderer = pickup.Renderer.DeepCopy(); this.Bounds = new AABB(); this.Bounds.SetDims(this.pickup.HitRectSize); this.Bounds.SetPosByCenter(pos); this.HitCollisionRect = Bounds.ShallowCopy(); this.MaxSpeed = EMIT_SPEED * 2; //*2 this.mass = 100.0f; this.velocity.X = this.heading.X * EMIT_SPEED; this.velocity.Y = this.heading.Y * EMIT_SPEED; orientation = AppMath.GetAngleOfVector(heading); }
/// <summary> /// /// </summary> /// <param name="scene"></param> /// <param name="pos">position</param> /// <param name="owner">owner gameobject ex. cCharacter</param> /// <param name="direction">normalized vector of direction</param> public cBullet(cGameObject owner, BulletBreed breed, Vector2f pos, Vector2f direction) : base(owner.Scene, pos) { this.owner = owner; this.breed = breed; this.alive = true; this.alpha = 255.0f; // proci határozza meg, hogy milyen alaplap foglalat és milyen RAM!! this.heading = direction; this.Bounds = new AABB(); this.Bounds.SetDims(new Vector2f(1.0f, 1.0f)); this.oppositeDir = new Vector2f(-this.heading.X * breed.slugLength, -this.heading.Y * breed.slugLength); this.intersection = new Vector2f(0.0f, 0.0f); this.Bounds.SetPosByTopLeft(pos); this.velocity.X = this.heading.X * breed.startSpeed; this.velocity.Y = this.heading.Y * breed.startSpeed; orientation = AppMath.GetAngleOfVector(heading); this.sprite = new Sprite(this.breed.sprite); // bullet_yellow_sm; bullet_light_gree this.sprite.Rotation = (float)AppMath.RadianToDegress(this.orientation); }
/// <summary> /// Main update protocol. /// </summary> /// <param name="step_time"></param> /// <param name="p"></param> /// <param name="world"></param> private void updateParticle1(float step_time, Particle p, cWorld world) { // Particle's update code comes here. p.Dims.X += p.ScaleSpeed * step_time; //+= p.Dims.Y += p.ScaleSpeed * step_time; //+= if (AppMath.Vec2Length(p.Dims) < 0.5f) { p.Dims.X = 0.0f; p.Dims.Y = 0.0f; } p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); // world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
public override bool Fire(Vector2f target) { if (this.isReadForNextShot()) { Vector2f dir = AppMath.Vec2NormalizeReturn(target - owner.Bounds.center); float dirAngle = (float)AppMath.GetAngleOfVector(dir); float unitAngle = spread / bulletsPerShot; float tangle = dirAngle - ((bulletsPerShot / 2.0f) * unitAngle); for (int i = 0; i < bulletsPerShot; ++i) { tangle += i * unitAngle; //Vector2f toSpreadTarget = cAppMath.GetRandomVecBySpread(dir, spread); Vector2f toSpreadTarget = new Vector2f((float)Math.Cos(tangle), (float)Math.Sin(tangle)); this.Shot(toSpreadTarget); } owner.Scene.Assets.PlaySound("shotgun", 3); return(true); } return(false); }
public override void Update(float step_time) { this.renderer.Update(step_time); cPlayer player = Scene.Player; if (this.pulling) { Vector2f predicted = AppMath.Vec2NormalizeReturn((player.Bounds.center + (player.Velocity * step_time)) - this.Bounds.center); // pull pickup //Vector2f toPlayer = cAppMath.Vec2NormalizeReturn(player.Bounds.center - this.Bounds.center); // G * ((m1*m2) / (d*d)) float f = PULL_FORCE * 150f; // * (100000.0f / ( d*d) ); this.AddForce(predicted * f); } /* * else * { * this.pulling = false; * } */ // applying some gravity force.Y += (false == pulling) ? (Constants.GRAVITY * 40.0f * step_time) : 0.0f; velocity.X += force.X * step_time; velocity.Y += force.Y * step_time; //velocity.X = Math.Abs(velocity.X) < 0.05f ? 0.0f : velocity.X; //velocity.Y = Math.Abs(velocity.Y) < 0.05f ? 0.0f : velocity.Y; double len = AppMath.Vec2Length(velocity); if (len < 0.1) { velocity = new Vector2f(0.0f, 0.0f); } AppMath.Vec2Truncate(ref velocity, MaxSpeed); // get more precise result calling it here (because of the updated velocity) // instead of calling at the beginning of this update method checkCollisionWithWorld(step_time); lastPosition = position; position.X += velocity.X * step_time; position.Y += velocity.Y * step_time; Bounds.SetPosByCenter(position); this.hitCollisionRect = Bounds; if (!AppMath.Vec2IsZero(velocity)) { heading = AppMath.Vec2NormalizeReturn(velocity); orientation = AppMath.GetAngleOfVector(heading); } force = new Vector2f(0.0f, 0.0f); }
public static void DrawDirLightByDVec(RenderTarget destination, Vector2f light_pos, double light_radius, Vector2f light_dir, double light_spread_angle, Color Color, BlendMode blend_mode, Shader shader) { double lightSubdivisionSize = AppMath.PI / 24.0; VertexArray va = new VertexArray(PrimitiveType.TriangleFan); Transform t = Transform.Identity; RenderStates states = new RenderStates(blend_mode, t, null, shader); double light_dir_angle = AppMath.GetAngleOfVector(light_dir); //Math->GetAngleBetwenVecs(light_pos, light_dir) - Math->PI/2.0; va.Append(new Vertex(light_pos, Color, new Vector2f())); // Set the edge color for rest of shape int numSubdivisions = (int)(light_spread_angle / lightSubdivisionSize); double startAngle = light_dir_angle - light_spread_angle / 2.0f; for (int currentSubDivision = 0; currentSubDivision <= numSubdivisions; currentSubDivision++) { double angle = startAngle + currentSubDivision * lightSubdivisionSize; va.Append(new Vertex(new Vector2f((float)(light_radius * Math.Cos(angle) + light_pos.X), (float)(light_radius * Math.Sin(angle) + light_pos.Y)), Color)); } destination.Draw(va, states); //========================================================================================= //soft portion----------------------------------------------------------------------------- // sf::VertexArray finVA; // sf::RenderStates finStates; // finStates.blendMode = sf::BlendMultiply; // finStates.shader = shader; // finStates.texture = &myLightFinTexture; // // sf::Color color(120, 120, 120, 0); // // double softSpreadAngle = Math->PI / 35.0; // // double umbraAngle1 = light_dir_angle - light_spread_angle / 2.0f; // double penumbraAngle1 = umbraAngle1 + softSpreadAngle; // sf::Vector2f penumbra_pos = sf::Vector2f(light_radius * cosf(penumbraAngle1), light_radius * sinf(penumbraAngle1)); // sf::Vector2f umbra_pos = sf::Vector2f(light_radius * cosf(umbraAngle1), light_radius * sinf(umbraAngle1)); // sf::Vector2f rootPos = light_pos; ///* // sf::Vector2f tc1 = sf::Vector2f(myLightFinTexture.getSize().x, 0); // sf::Vector2f tc2 = sf::Vector2f(myLightFinTexture.getSize().x, myLightFinTexture.getSize().y); // sf::Vector2f tc3 = sf::Vector2f(0 , myLightFinTexture.getSize().y); //*/ // sf::Vector2f tc1 = sf::Vector2f(0, 0); // sf::Vector2f tc2 = sf::Vector2f(myLightFinTexture.getSize().x, 0); // sf::Vector2f tc3 = sf::Vector2f(0 , myLightFinTexture.getSize().y); // // sf::Vector2f p1 = sf::Vector2f(rootPos.x, rootPos.y); // sf::Vector2f p2 = sf::Vector2f(rootPos.x + penumbra_pos.x, rootPos.y + penumbra_pos.y); // sf::Vector2f p3 = sf::Vector2f(rootPos.x + umbra_pos.x, rootPos.y + umbra_pos.y); // // finVA.append(sf::Vertex(p1, color, tc1)); // finVA.append(sf::Vertex(p2, color, tc2)); // finVA.append(sf::Vertex(p3, color, tc3)); // // destination.draw(&finVA[0], finVA.getVertexCount(), sf::PrimitiveType::Triangles, finStates); //===================================================================================================== //finVA.clear(); //double umbraAngle2 = light_dir_angle + light_spread_angle / 2.0f; //double penumbraAngle2 = umbraAngle2 - softSpreadAngle; //sf::Vector2f penumbra_pos_2 = sf::Vector2f(light_radius * cosf(penumbraAngle2), light_radius * sinf(penumbraAngle2)); //sf::Vector2f umbra_pos_2 = sf::Vector2f(light_radius * cosf(umbraAngle2), light_radius * sinf(umbraAngle2)); //sf::Vector2f rootPos_2 = light_pos; //tc1 = sf::Vector2f(0, 0); //tc2 = sf::Vector2f(myLightFinTexture.getSize().x, 0); //tc3 = sf::Vector2f(0 , myLightFinTexture.getSize().y); //p1 = sf::Vector2f(rootPos_2.x, rootPos_2.y); //p2 = sf::Vector2f(rootPos_2.x + penumbra_pos_2.x, rootPos_2.y + penumbra_pos_2.y); //p3 = sf::Vector2f(rootPos_2.x + umbra_pos_2.x, rootPos_2.y + umbra_pos_2.y); //finVA.append(sf::Vertex(p1, color, tc1)); //finVA.append(sf::Vertex(p2, color, tc2)); //finVA.append(sf::Vertex(p3, color, tc3)); //destination.draw(&finVA[0], finVA.getVertexCount(), sf::PrimitiveType::Triangles, finStates); //=================================================================================================== //==================================================================================================== }