function cBow::onLevelLoaded(%this, %scenegraph) { $pBow = %this; //mount the machine gun onto player pBow.mount(Player1Image, 1.4, 0.5, 0, 1, 1, 0, 0); pBow.setEnabled(0); // for keyboard testing // moveMap.bindCmd(keyboard, "o", "$pBow.createProjectile();", ""); } function cBow::createProjectile(%this) { %this.PlayerArrow = new t2dStaticSprite() { scenegraph = %this.scenegraph; class = PlayerArrow; //CollisionPolyList = "0.071 -0.3140 0.204 0.363 -0.039 0.363" //Layer = "3" //bulletSpeedX = %this.BulSpeed; //bulletSpeedY = %this.BulSpeed; player = %this; }; %this.PlayerArrow.shootProjectile(); } function PlayerArrow::shootProjectile(%this) { // Pick the image and set its size %this.setImageMap(arrowImageMap); %this.setSize(50, 50); %facing_angle_deg = $pBow.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.setCollisionPolyCustom(3, "0.071 -0.3140", "0.204 0.363","-0.039 0.363"); %this.setPositionX(%this.player.getPositionX()); %this.setPositionY(%this.player.getPositionY()); %facing_angle_deg = $pBow.getRotation() - 92; %facing_angle_rad = (%facing_angle_deg / 180) * 3.142; %this.setLinearVelocityX(70 * mCos(%facing_angle_rad)); %this.setLinearVelocityY(70 * 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 PlayerArrow::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) { if (%dstObj.class $= "Player1") { //%srcObj.dealDamage(3, %dstObj); //%srcObj.safeDelete(); //explode(%srcObj); } if (%dstObj.class $= "Player2") { alxStop(ArrowImpact); $ArrowImpactHandle = alxPlay(ArrowImpact); %srcObj.dealDamage(3, %dstObj); %srcObj.safeDelete(); //explode(%srcObj); } } function PlayerArrow ::dealDamage(%this, %amount, %victim) { %takesDamage = %victim.getBehavior("TakesDamageAdvBehavior"); if (!isObject(%takesDamage)) return; %takesDamage.takeDamage(%amount, %this); }