function c1MacG::onLevelLoaded(%this, %scenegraph) { $p1MacG = %this; //mount the machine gun onto player p1MacG.mount(Player1Image, 1.7, 0.8, 0, 1, 1, 0, 0); p1MacG.setEnabled(0); // for keyboard testing // moveMap.bindCmd(keyboard, "o", "$pMacG.createProjectile();", ""); } function c1MacG::createProjectile(%this) { %this.Player1Bullet = new t2dStaticSprite() { scenegraph = %this.scenegraph; class = Player1Bullet; //bulletSpeedX = %this.BulSpeed; //bulletSpeedY = %this.BulSpeed; player = %this; }; %this.Player1Bullet.shootProjectile(); } function Player1Bullet::shootProjectile(%this) { // Pick the image and set its size %this.setImageMap(mgBulletImageMap); %this.setSize(2, 2); //%this.setRotation(90); %facing_angle_deg = $p1MacG.getRotation(); %this.setRotation(%facing_angle_deg); %this.setLayer(3); // Turn on collision, but turn off physics %this.setCollisionActive( true, true ); %this.setCollisionPhysics(false, false); %this.setCollisionCallback(true); %this.setPositionX(%this.player.getPositionX()); %this.setPositionY(%this.player.getPositionY()); %facing_angle_deg = $p1MacG.getRotation() - 92; %facing_angle_rad = (%facing_angle_deg / 180) * 3.142; %this.setLinearVelocityX(100 * mCos(%facing_angle_rad)); %this.setLinearVelocityY(100 * mSin(%facing_angle_rad)); %cameraViewBounds = sceneWindow2D.getCurrentCameraArea(); %this.setWorldLimit( kill, getword(%cameraViewBounds, 0) - (%this.getWidth() / 2), getword(%cameraViewBounds, 1) - (%this.getHeight() / 2), getword(%cameraViewBounds, 2) + (%this.getWidth() / 2), getword(%cameraViewBounds, 3) + (%this.getHeight() / 2) ); } function Player1Bullet::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) { if (%dstObj.class $= "Player1") { //%srcObj.dealDamage(3, %dstObj); //%srcObj.safeDelete(); //explode(%srcObj); } if(%dstObj.class $= "trees") { %srcObj.safeDelete(); } if (%dstObj.class $= "Player2") { %srcObj.dealDamage(3, %dstObj); %srcObj.safeDelete(); //explode(%srcObj); } } function Player1Bullet ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }