Click here to Skip to main content
13,197,433 members (31,211 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 22 Oct 2012

Killer Instinct

, 22 Oct 2012
Rate this:
Please Sign up or sign in to vote.
Killer Instinct is physics based shooting game. The objective is to perfectly shoot the enemies.

Sample Game Image


Killer Instinct is physics based shooting game. The objective is to perfectly shoot the enemies. The game consists of a character holding a gun and the enemies standing at their positions. The obstacles can stop the hero's bullets or fall over the hero. This game is written in AS3 using physics game engine called Box2D.

  • Fully playable with mouse, and touch.
  • Bullets are projected from the gun with certain speed and it repels when it hits to any physics bodies or walls.
  • Hero and enemy characters behaves as rag-dolls.


Interest towards shooting games made me think of this. We planned to add physics to make game interesting.

Using the code

The back end of the game is built in AS3, making use of physics based engine Box2D. The main aspect of the game is to move the bullet.

//Bullet Creation:

public function BulletActor(parent,xValue,yValue,rotation,vx,vy)
    skin = new Arrow();
    skin.x = xValue;
    skin.y = yValue;
    skin.rotation = rotation*180/Math.PI;
    prevX = skin.x; 
    prevY = skin.y; 

    var shape:b2PolygonShape = new b2PolygonShape();
    shape.SetAsBox(6 / Phyvalues.RATIO, 1.4 / Phyvalues.RATIO);
    var fixtureDef:b2FixtureDef= new b2FixtureDef();
    fixtureDef.density = 20;
    fixtureDef.restitution = 1;
    fixtureDef.friction = 0;
    fixtureDef.userData = skin;
    fixtureDef.userData.remove = remove;
    fixtureDef.userData.prevX = prevX;
    fixtureDef.userData.prevY = prevY;
    fixtureDef.userData.count = count;
    fixtureDef.shape = shape;
    fixtureDef.filter.groupIndex = -1;            
    var bodyDef:b2BodyDef = new b2BodyDef();
    bodyDef.bullet = true;
    bodyDef.angle = rotation;
    bodyDef.type = b2Body.b2_dynamicBody;
    bodyDef.position.Set(xValue / Phyvalues.RATIO, yValue / Phyvalues.RATIO);
    bodyDef.fixedRotation = true;
    body = Phyvalues._world.CreateBody(bodyDef);

    body.SetLinearVelocity(new b2Vec2(vx, vy));
    body.applyGravity = false;
    super(body, skin);

Bullet Movement:

private function loop(e:Event):void
    if (_costume is Bullet) {
    var dx = _costume.x - _costume.prevX;
    var dy = _costume.y - _costume.prevY;
    var ang = Math.atan2(dy, dx);
    _costume.prevX = _costume.x;
    _costume.prevY = _costume.y;
    var force:b2Vec2 = _body.GetLinearVelocity();
    _body.ApplyForce(force, _body.GetWorldCenter());
    _costume.x = _body.GetPosition().x * Phyvalues.RATIO;
    _costume.y = _body.GetPosition().y * Phyvalues.RATIO;
    _costume.rotation = _body.GetAngle() * 180 / Math.PI;

//When Bullet hits to enemy character ragdolls are created
//and force is applied to them by according to bullet force.

//Rag doll Creation:
    var xpt = Phyvalues._allActors[i].xv;
    var ypt = Phyvalues._allActors[i].yv;
    var vx = Phyvalues._allActors[i].velocity.x;
    var vy = Phyvalues._allActors[i].velocity.y;
    ragDolls = new RagDolls1(xpt, ypt); //ragdolls generating.

    // applying force to ragdoll.
    ragDolls.body.ApplyImpulse(new b2Vec2(vx, vy), ragDolls.body.GetWorldCenter()); 


Points of Interest

Creation of ragdolls and their movement.




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 22 Oct 2012
Article Copyright 2012 by Member 9514741
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid