Downloads containing ezcrayon.j2as

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Crayon ValleyFeatured Download FawFul Capture the flag 9 Download file

File preview

const bool MLLESetupSuccessful = MLLE::Setup(); ///@MLLE-Generated
#include "MLLE-Include-1.5.asc" ///@MLLE-Generated
#pragma require "ezcrayon-MLLE-Data-3.j2l" ///@MLLE-Generated
#pragma require "ezcrayon-MLLE-Data-2.j2l" ///@MLLE-Generated
#pragma require "ezcrayon-MLLE-Data-1.j2l" ///@MLLE-Generated
#pragma require "ezcrayon.j2l" ///@MLLE-Generated
#pragma require "crayonbridge.j2a"

void onLevelBegin() {
	jjTexturedBGFadePositionY = 0.43;
}
	
void onLevelLoad() {
	jjAnimSets[ANIM::BRIDGE].load(0, "crayonbridge.j2a");

	generateCustomSpringSprites(jjAnimSets[ANIM::CUSTOM[0]], array<uint> = {64, 32});
	turnIntoCustomSpring(jjObjectPresets[OBJECT::FROZENSPRING], 0, 36.4f, false);
	turnIntoCustomSpring(jjObjectPresets[OBJECT::HORREDSPRING], 1, 28.5f, false);
	
	for (int i = 1; i < 255; i++) {
		if (jjObjectPresets[i].playerHandling == HANDLING::PICKUP && i != 73) {
			jjObjectPresets[i].behavior = CannotBeShotDown;
		}
	}
	
	jjObjectPresets[OBJECT::FULLENERGY].behavior = CantBeBuried;
	jjObjectPresets[OBJECT::FULLENERGY].behavior = CannotBeBuriedByTNT();
	jjObjectPresets[OBJECT::BOUNCERBULLET].behavior = bouncer;
}

void onMain() {
	jjTexturedBGUsed = jjColorDepth == 16;

	array<jjLAYER@> layers = jjLayerOrderGet();
	layers[15].xOffset += 6.0f;
	layers[16].xOffset += 4.0f;
	layers[24].xOffset += 0.05f;
	if (layers[15].xOffset % (layers[15].widthReal*32) == 0) layers[15].xOffset = 0;
	if (layers[16].xOffset % (layers[16].widthReal*32) == 0) layers[16].xOffset = 0;
	if (layers[24].xOffset % (layers[24].widthReal*32) == 0) layers[24].xOffset = 0;
	}

void onPlayer(jjPLAYER@ play) {
	handleFastCustomSpringSpeeds(play);
		for (int i = 1; i < jjObjectCount; i++) {
			if (jjObjects[i].isActive && jjObjects[i].eventID == OBJECT::COPTER && jjObjects[i].state == STATE::FLY) {
			//Only set the counter if it's available to take
			jjObjects[i].counter = 10;
			if (jjObjects[i].var[4] == 0)
				jjObjects[i].state = STATE::DONE;
			}
		}
}

jjANIMSET@ customSpringSprite;
array<int> fastCustomSpringSpeeds(jjLocalPlayerCount);
bool generateCustomSpringSprites(jjANIMSET@ anim, const array<uint> &in colors) {
	int length = colors.length();
	bool success = (@customSpringSprite = anim).allocate(array<uint>(length * 3, 5)) !is null;
	if (success) {
		uint srcSet = jjAnimSets[ANIM::SPRING];
		for (int i = 0; i < length; i++) {
			uint color = colors[i];
			uint destAnimOffset = anim + i * 3;
			for (int j = 0; j < 3; j++) {
				uint srcAnim = jjAnimations[srcSet + j];
				uint destAnim = jjAnimations[destAnimOffset + j];
				for (int k = 0; k < 5; k++) {
					jjPIXELMAP image(jjAnimFrames[destAnim + k] = jjAnimFrames[srcAnim + k]);
					int width = image.width;
					int height = image.height;
					for (int l = 0; l < height; l++) {
						for (int m = 0; m < width; m++) {
							int pixel = image[m, l];
							if (pixel >= 32 && pixel < 40)
								image[m, l] = color + (pixel & 7);
						}
					}
					if (!image.save(jjAnimFrames[destAnim + k]))
						return false;
				}
			}
		}
	}
	return success;
}

void initializeCustomSpring(jjOBJ@ obj) {
	int anim = obj.curAnim;
	obj.behave(obj.behavior = BEHAVIOR::SPRING, false);
	if (obj.curAnim != anim) {
		obj.curAnim = anim + 2;
		obj.determineCurFrame();
	}
	obj.draw();
}

void turnIntoCustomSpring(jjOBJ@ obj, uint color, float power, bool horizontal) {
	if (horizontal) {
		obj.xSpeed = power;
		obj.ySpeed = 0.f;
	} else {
		obj.xSpeed = 0.f;
		obj.ySpeed = -power;
		if (obj.state == STATE::START && obj.creatorType == CREATOR::LEVEL) {
			int x = int(obj.xPos) >> 5;
			int y = int(obj.yPos) >> 5;
			if (jjParameterGet(x, y, 0, 1) != 0) {
				jjParameterSet(x, y, 0, 1, 0);
				obj.yPos -= 4.f;
				obj.ySpeed = power;
			}
		}
	}
	obj.behavior = initializeCustomSpring;
	obj.curAnim = customSpringSprite + color * 3 + (horizontal ? 1 : 0);
	obj.energy = obj.frameID = obj.freeze = obj.justHit = obj.light = obj.points = 0;
	obj.causesRicochet = obj.isTarget = obj.scriptedCollisions = obj.triggersTNT = false;
	obj.isBlastable = false;
	obj.deactivates = true;
	obj.isFreezable = true;
	obj.bulletHandling = HANDLING::IGNOREBULLET;
	obj.playerHandling = HANDLING::SPECIAL;
	obj.lightType = LIGHT::NORMAL;
	obj.determineCurFrame();
}

void handleFastCustomSpringSpeeds(jjPLAYER@ play) {
	if (play.ySpeed < -32.f) {
		fastCustomSpringSpeeds[play.localPlayerID] = int(ceil((play.ySpeed + 32.f) / -0.125f));
	} else if (fastCustomSpringSpeeds[play.localPlayerID] != 0) {
		if (play.ySpeed < -31.f) {
			fastCustomSpringSpeeds[play.localPlayerID]--;
			play.ySpeed = -32.f;
		} else {
			fastCustomSpringSpeeds[play.localPlayerID] = 0;
		}
	}
}

void CannotBeShotDown(jjOBJ@ obj) {
	obj.behave(BEHAVIOR::PICKUP);
	if (obj.state == STATE::FLOATFALL) obj.state = STATE::FLOAT;
}

void CantBeBuried(jjOBJ@ obj) {
	obj.behave(BEHAVIOR::PICKUP);
	if (jjMaskedPixel(int(obj.xPos), int(obj.yPos) + 8) && obj.xPos > 50*32 && obj.xPos < 57*32) {
		obj.state = STATE::FLOAT;
	}
}

class CannotBeBuriedByTNT : jjBEHAVIORINTERFACE {
    void onBehave(jjOBJ@ obj) {
        obj.behave(BEHAVIOR::PICKUP);
        obj.isBlastable = obj.state == STATE::FLOAT;
    }
}

void bouncer(jjOBJ@ obj) {
    float xSpeed = obj.xSpeed;
    float ySpeed = obj.ySpeed;
    obj.behave(BEHAVIOR::BOUNCERBULLET);
    if (xSpeed * obj.xSpeed < 0.f && ySpeed * obj.ySpeed < 0.f) {
        if (!jjMaskedPixel(int(obj.xPos + obj.xSpeed), int(obj.yPos + ySpeed))) {
            obj.var[0] = obj.var[0] - 1;
            obj.ySpeed = ySpeed;
            if (ySpeed > 0.f)
                obj.yPos += ySpeed;
        }
    }
}