Downloads containing meleesword.asc

Downloads
Name Author Game Mode Rating
JJ2+ Only: Threed RealmsFeatured Download Violet CLM Single player 9.7 Download file
Custom Weapons...Featured Download Violet CLM Other 10 Download file

File preview

#pragma require "meleeSword.asc"
#pragma require "sword.j2a"
#include "MLLE-Weapons.asc"

/**Melee sword**/
/**Author: szmol96**/

namespace SzmolWeaponPack {
	namespace MeleeSword {
		class PlayerX {
			int8 fastfireBackup = 0;
			bool swordSelected = false;
			uint8 canStab = 0;
		}
		array<PlayerX> PlayersX(jjLocalPlayerCount);
		
		class Weapon : MLLEWeapons::WeaponInterface {
			Weapon() {
				super(
					regularObjectTemplate: MLLEWeapons::ObjectTemplate(
						xSpeed: 1,
						killAnim: 2,
						curAnim: 1,
						special: -1,
						var: array<int> = {0,0,0,0,0,0, 16},
						doesHurt: 24 //default color
					),
					powerupObjectTemplate: MLLEWeapons::ObjectTemplate(
						xSpeed: 1,
						killAnim: 2,
						curAnim: 1,
						special: -1,
						var: array<int> = {0,0,0,0,0,0, 8 | 16},
						doesHurt: 32
					),
					animSetFilename: "sword.j2a",
					//pickupAnimation: 3,
					poweredUpPickupAnimation: 3,
					style: WEAPON::CAPPED,
					traits: se::weapon_default_traits | se::weapon_increases_mobility | se::weapon_goes_through_thin_walls,
					onPlayer: ManagePlayerX,
					weaponHookRequired: true,
					behavior: function(obj, powerup) {
						if (obj.creatorType == CREATOR::PLAYER) {
							const jjPLAYER@ p = jjPlayers[obj.creatorID];
							obj.doesHurt =
								(jjGameMode != GAME::CTF) ? (p.fur != 0 ? p.fur >> 24 : obj.doesHurt) :
								(p.team == TEAM::BLUE) ? 32 :
								(p.team == TEAM::RED) ? 24 :
								(p.team == TEAM::GREEN) ? 16 :
								40; //yellow
							if (obj.ySpeed == -1) {
								obj.behavior = UpStab;
								return;
							} else if (!jjMaskedHLine(int(p.xPos) - 12, 24, int(p.yPos) + 21)) { //in the air
								if (obj.ySpeed == 1) {
									obj.behavior = DownStab;
									return;
								} else if ((obj.var[7] < -131072 || obj.var[7] > 131072)) {
									obj.behavior = SpinStab;
									return;
								}
							}
						}
						obj.behavior = Stab;
					}
				);
			}
		}

		void ManagePlayerX(jjPLAYER@ p, int number) {
			PlayerX@ px = PlayersX[p.localPlayerID];
			
			if (int(p.currWeapon) == number) {
				if (!px.swordSelected)
					px.fastfireBackup = p.fastfire;
				p.fastfire = 35; //constant
			
				if (p.buttstomp < 41 && p.keyFire && px.canStab == 0) {
					p.buttstomp = 121;
					p.fireBullet(number, true, true, 3.14159265);
					p.keySelect = p.ammo[WEAPON::CURRENT] == 0;
				}
			} else {
				if (px.swordSelected)
					p.fastfire = px.fastfireBackup;
			}
			
			if (px.canStab != 0) --px.canStab;
			px.swordSelected = int(p.currWeapon) == number;
		}
		
		void Stab(jjOBJ@ sword) {
			if (sword.state == STATE::START) {
				jjSample(sword.xPos, sword.yPos, SOUND::COMMON_FOEW3, 63, 12000);
				sword.state = STATE::FLY;
				sword.curAnim -= 1;
				if (sword.creatorType != CREATOR::PLAYER)
					sword.direction = MLLEWeapons::HelpfulBulletFunctions::GetDirection(sword);
			}
			
			if (sword.age > 30)
				sword.delete();
			else {
				sword.frameID = sword.age++ / 2;
				sword.determineCurFrame(true);
				
				if (sword.creatorType == CREATOR::PLAYER) {
					const jjPLAYER@ p = jjPlayers[sword.creatorID];
					sword.xPos = p.xPos + p.direction * (jjSin((sword.age - 12) * 15) * 24 + 8);
					sword.yPos = (p.yPos + 4) - (jjCos((sword.age - 12) * 15) * 24);
					sword.direction = p.direction;
					PlayersX[p.localPlayerID].canStab = 35;
							
					for (int i = 4; i > 0; --i)
						if (sword.age > i)
							jjDrawSpriteFromCurFrame(p.xPos + p.direction * (jjSin((sword.age - 12 - i) * 15) * 24 + 8), (p.yPos + 4) - (jjCos((sword.age - 12 - i) * 15) * 24), sword.curFrame - i, sword.direction, SPRITE::TRANSLUCENTCOLOR, sword.doesHurt + i, 4, 4, -1);
				}
				
				jjDrawSpriteFromCurFrame(sword.xPos, sword.yPos, sword.curFrame, sword.direction, MLLEWeapons::HelpfulBulletFunctions::IsPowerup(sword) ? SPRITE::NORMAL : SPRITE::PALSHIFT, 248);
			}
		}
		//otherwise, can assume CREATOR::PLAYER
		void UpStab(jjOBJ@ sword) {
			jjPLAYER@ p = jjPlayers[sword.creatorID];
			if (sword.state == STATE::START) {
				jjSample(sword.xPos, sword.yPos, SOUND::COMMON_FOEW3, 63, 12000);
				p.doubleJumpCount = 0;
				sword.state = STATE::FLY;
			}
			
			sword.xPos = p.xPos + p.direction * 24;
			sword.yPos = p.yPos - sword.age / 2;
			
			p.xSpeed = sword.xSpeed = sword.direction * 3;
			p.ySpeed = sword.ySpeed = -12 + sword.age / 5;
			PlayersX[p.localPlayerID].canStab = 35;
			
			if (sword.age > 16)
				sword.delete();
			else {
				sword.direction = p.direction;
				sword.frameID = sword.age++ / 2;
				sword.determineCurFrame(true);
				
				for (int i = 4; i > 0; --i)
					if (sword.age > i + 3)
						jjDrawSpriteFromCurFrame(p.xPos + p.direction * 24, p.yPos - (sword.age - i) / 2, sword.curFrame - i, sword.direction, SPRITE::TRANSLUCENTCOLOR, sword.doesHurt + i, 4, 4, -1);
				jjDrawSpriteFromCurFrame(sword.xPos, sword.yPos, sword.curFrame, sword.direction, MLLEWeapons::HelpfulBulletFunctions::IsPowerup(sword) ? SPRITE::NORMAL : SPRITE::PALSHIFT, 248);
			}
		}
		void DownStab(jjOBJ@ sword) {
			if (sword.state == STATE::START) {
				jjSample(sword.xPos, sword.yPos, SOUND::COMMON_FOEW3, 63, 16000);
				sword.ySpeed = 10;
				sword.state = STATE::FLY;
				sword.curFrame -= 22;
			}
			
			jjPLAYER@ p = jjPlayers[sword.creatorID];
			sword.xPos = p.xPos + p.direction * 20;
			sword.yPos = p.yPos;
			p.buttstomp = 115;
			p.ySpeed = 10;
			PlayersX[p.localPlayerID].canStab = 70;
			
			if (sword.age++ > 25)
				sword.delete();
			else if (jjMaskedHLine(int(p.xPos) - 12, 24, int(p.yPos) + 21)) {
				if (MLLEWeapons::HelpfulBulletFunctions::IsPowerup(sword)) {
					const float y = p.yPos + 20 + jjMaskedTopVLine(int(p.xPos), int(p.yPos) + 21, 32) - 16;
					for (int i = -1; i <= 1; i += 2) {
						jjOBJ@ wave = jjObjects[jjAddObject(OBJECT::BLASTERBULLET, p.xPos + i*8, y, sword.creatorID, sword.creatorType, BEHAVIOR::INACTIVE)];
						wave.direction = i;
						wave.xSpeed = i * 4.5;
						wave.curAnim = sword.curAnim + 1;
						wave.doesHurt = sword.doesHurt;
						wave.playerHandling = sword.playerHandling;
						wave.animSpeed = 1;
						wave.var[3] = sword.var[3];
						wave.var[6] = 16;
						wave.age = 0;
						wave.freeze = 0;
						wave.behavior = shockWave;
					}
				}
				sword.delete();
			} else {
				sword.direction = p.direction;
				jjDrawSpriteFromCurFrame(sword.xPos, sword.yPos, sword.curFrame, sword.direction, MLLEWeapons::HelpfulBulletFunctions::IsPowerup(sword) ? SPRITE::NORMAL : SPRITE::PALSHIFT, 248);
			}
		}
		void SpinStab(jjOBJ@ sword) {
			if (sword.state == STATE::START) {
				jjSample(sword.xPos, sword.yPos, SOUND::COMMON_FOEW3, 63, 16000);
				sword.state = STATE::FLY;
				sword.curAnim -= 1;
			}
			
			jjPLAYER@ p = jjPlayers[sword.creatorID];
			sword.xPos = p.xPos + p.direction * (jjSin(sword.frameID * 23) * 15);
			sword.yPos = p.yPos - (jjCos(sword.frameID * 23) * 15);
			p.ballTime = 3;
			PlayersX[p.localPlayerID].canStab = 35;
			
			if (sword.frameID++ > 47 || jjMaskedHLine(int(p.xPos) - 12, 24, int(p.yPos) + 21))
				sword.delete();
			else {
				sword.direction = p.direction;
				sword.determineCurFrame(true);
				
				for (int i = 4; i > 0; --i) {
					if (sword.frameID > i) {
						jjDrawSpriteFromCurFrame(p.xPos + p.direction * (jjSin((sword.frameID - i) * 23) * 15), p.yPos - (jjCos((sword.frameID - i) * 23) * 15), sword.curFrame - i, sword.direction, SPRITE::TRANSLUCENTCOLOR, sword.doesHurt + i);
					}
				}
				jjDrawSpriteFromCurFrame(sword.xPos, sword.yPos, sword.curFrame, sword.direction, MLLEWeapons::HelpfulBulletFunctions::IsPowerup(sword) ? SPRITE::NORMAL : SPRITE::PALSHIFT, 248);
			}
		}
		
		void shockWave(jjOBJ@ wave) {
			if (wave.state == STATE::START) {
				const jjPLAYER@ p = jjPlayers[wave.creatorID];
				if (jjMaskedVLine(int(p.xPos) + wave.direction * 8, int(p.yPos) + 21, 32))
					wave.putOnGround(true);
				wave.state = STATE::FLY;
			}
			
			if (jjMaskedVLine(int(wave.xPos), int(wave.yPos), 16) && wave.age <= 35) {
				wave.yPos += jjMaskedTopVLine(int(wave.xPos), int(wave.yPos) - 16, 32) - 16;
				wave.xPos += wave.xSpeed;
				wave.frameID = wave.age++ / 3;
				wave.determineCurFrame(true);
				jjDrawSpriteFromCurFrame(wave.xPos, wave.yPos, wave.curFrame, wave.direction, SPRITE::SINGLEHUE, wave.doesHurt);
			} else {
				wave.delete();
			}
		}
	}
}