Commits

Pedro Ferreira  committed dc3946b

- fire the bullets with impulses on the body (instead of having to move them 'manually')
- reduce sniper bullets width

  • Participants
  • Parent commits 4cf7cfd

Comments (0)

Files changed (11)

File images/weapon2_sniper.png

Old
Old image
New
New image

File images/weapon2_sniper.svg

Old
Old image
New
New image

File js/endless_mode.js

 {
 
     // from how many ticks, until next enemy
-var NEXT_ENEMY_TICKS = 50;
+var NEXT_ENEMY_TICKS = 100;
 
 var COUNT_TICKS_NEXT_ENEMY = 0;
 
 
     // number of ticks until we increase the difficulty 
-var INCREASE_DIFFICULTY_TICKS = 200;
+var INCREASE_DIFFICULTY_TICKS = 500;
 var COUNT_INCREASE_DIFFICULTY_TICKS = 0;
 
 
     to doo:
     
         - mines should go away after some time
+
+        collisions:
+
+            - remove bullets when out of bounds and hit stuff
+            - cant shoot bullets to all directions
     
  */
 
 
 var bodyDef = new b2BodyDef;
 
-bodyDef.type = b2Body.b2_dynamicBody;
+//bodyDef.type = b2Body.b2_dynamicBody;
+bodyDef.type = b2Body.b2_staticBody;
 
 bodyDef.position.x = 0;
 bodyDef.position.y = 0;
 
 fixDef.shape = new b2CircleShape( width / 2 / SCALE );
 
-//fixDef.shape.SetAsOrientedBox( width/2 / SCALE, height/2 / SCALE, new b2Vec2( width/2 / SCALE , height/2 / SCALE ) );
-
 var body = WORLD.CreateBody( bodyDef );
 
 body.CreateFixture( fixDef );

File js/utilities.js

 
 function applyImpulse( body, degrees, power )
 {
-var impulse = new b2Vec2( Math.cos(degrees * (Math.PI / 180)) * power,
-    Math.sin(degrees * (Math.PI / 180)) * power );
+var rads = degrees * Math.PI / 180;
+
+//console.log(degrees);
+
+var impulse = new b2Vec2( Math.cos( rads ) * power,
+    Math.sin( rads ) * power );
 
 var point = body.GetWorldCenter();
 
-body.ApplyImpulse(impulse, point );
+body.ApplyImpulse( impulse, point );
 }
 
 

File js/weapon1_laser.js

 this.width = 4;
 this.height = 2;
 
+
+if ( !$.isNumeric( angleRotation ) )
+    {
+    angleRotation = shipObject.getRotation();
+    }
+
+
     // inherit from the Weapons class
 Weapons.call( this, shipObject, angleRotation );
 
-this.speed = 8; //HERE pode dar problemas se houver inimigos + pequenos que o speed (pq o speed eh o step... ter k verificar antes do salto)
+applyImpulse( this.body, angleRotation, 0.2 );
 }
 
 
     // origin in the middle of the image
 laser.regY = this.height / 2;
 
-
 laser.gotoAndPlay( "main" );
     
-    
-var shipObject = this.shipObject;
 
-
-laser.x = shipObject.getX();
-laser.y = shipObject.getY();
-
-if ( $.isNumeric( angleRotation ) )
-    {
-    laser.rotation = angleRotation;
-    }
-
-else
-    {
-    laser.rotation = shipObject.getRotation();
-    }
-
+laser.rotation = angleRotation;
 
 this.shape = laser;
 };

File js/weapon2_sniper.js

 
 function Weapon2_sniper( shipObject )
 {
-this.width = 1000;
+this.width = 10;
 this.height = 2;
 
     // inherit from the Weapons class
 Weapons.call( this, shipObject );
 
-this.speed = 0; //HERE ser instantaneo?...
+//this.countTicks = Weapon2_sniper.numberTicksAnimation;
 
-this.countTicks = Weapon2_sniper.numberTicksAnimation;
+//Weapon2_sniper.findIfIntercept( shipObject );
 
-Weapon2_sniper.findIfIntercept( shipObject );
-} 
+applyImpulse( this.body, shipObject.getRotation(), 2 );
+}
 
     // number of ticks of the duration of the bullet animation, before removing it from the stage
 Weapon2_sniper.numberTicksAnimation = 30;
         },
         
     frames: {
-        width: 1000,
+        width: 10,
         height: 2
         },
         
     
 var shipObject = this.shipObject;
 
-sniper.x = shipObject.getX();
-sniper.y = shipObject.getY();
 sniper.rotation = shipObject.getRotation();
 
 

File js/weapon3_rocket.js

     // inherit from the Weapons class
 Weapons.call( this, shipObject );
 
-this.speed = 4;
+applyImpulse( this.body, shipObject.getRotation(), 0.6 );
 }
 
 

File js/weapon4_mines.js

 
     // inherit from the Weapons class
 Weapons.call( this, shipObject );
-
-this.speed = 0;
 }
 
 
 var mine = new createjs.BitmapAnimation( sprite );
 
     // origin in the middle of the image
+mine.regX = this.height / 2;
 mine.regY = this.height / 2;
 
 mine.gotoAndPlay( "main" );

File js/weapons.js

         .setupPhysics()         (optional -- the default is a rectangle from the width/height properties)
 
     Properties:
-    
-        .speed
+
         .width
         .height
         
         angleRotation : of the bullet
  */
 
-function Weapons( shipObject, angleRotation )
+function Weapons( shipObject, angleRotation, x, y )
 {
 this.shape = null;
 
 this.shipObject = shipObject;
 
+if ( !$.isNumeric( angleRotation ) )
+    {
+    angleRotation = shipObject.getRotation();
+    }
+
 
     // draw the bullet
 this.drawBullet( angleRotation );
     {
     Weapons.allyBullets.push( this );
     }
+
+
+
+if ( typeof x == 'undefined')
+    {
+    x = shipObject.getX();
+    y = shipObject.getY();
+    }
+
+this.moveTo( x, y );
 }
 
     // all the bullets from the enemies
 
 
 
-Weapons.prototype.moveForwardBullet = function()
-{
-var shape = this.shape;
-
-
-    //HERE
-var rotation = shape.rotation - 90;
-
-var currentX = shape.x;
-var currentY = shape.y;
-
-var x = currentX + Math.sin( rotation * (Math.PI/-180) ) * this.speed;
-var y = currentY + Math.cos( rotation * (Math.PI/-180) ) * this.speed;
-
-
-this.moveTo( x, y );
-
-
-    // remove the bullets that are out of the canvas
-if ( this.reachedLimits() )
-    {
-    this.remove();
-    }
-};
-
-
 Weapons.prototype.getX = function()
 {
 return this.shape.x;
 
 Weapons.prototype.tick = function()
 {
-this.moveForwardBullet();
-
 this.updateShape();
 
 if (typeof this.tick_function !== "undefined" && this.tick_function !== null)