#pragma require "SwitchTestV2.j2a" #pragma offer "STV2-Switch.wav" #pragma offer "STV2-Dash.wav" #pragma offer "STV2-Build.wav" #pragma offer "STV2-Ghost.wav" #pragma offer "STV2-Fall.wav" #pragma offer "SUCCESSF.WAV" int WarpTargetID = 0; int AssignWarpTargetID(int assign) { WarpTargetID = assign; @SwitchBlocks = @Incidents[assign].SwitchBlocks; return assign; } const uint LEVELWIDTH = jjLayerWidth[4]; const uint LEVELHEIGHT = jjLayerHeight[4]; const uint16 FIRSTWALLTILE = 1; const uint16 LASTCAVETILE = 268; jjPLAYER@ Player = jjLocalPlayers[0]; jjTEXTAPPEARANCE ColoredBounce(STRING::BOUNCE); array Palettes; const int UNFINISHEDINCIDENTTIME = 70 * 10000; string StringifyTime(int timeInTicks, int par = 0) { string prefix = "$"; if (par != 0) { const int timeDifference = timeInTicks / 70 - par; if (timeDifference < 0) prefix = "'"; else if (timeDifference < 3) prefix = "&"; else if (timeDifference < 6) prefix = "%"; } return prefix + formatInt(timeInTicks / (70*60), "0", 2) + ":" + formatInt((timeInTicks % (70*60)) / 70, "0", 2) + "." + formatInt(((timeInTicks % (70*60)) % 70) * 100 / 70, "0", 2); } class Point { int x; int y; Point(){} Point(int xx, int yy) { x = xx;// * 32.f + 16; y = yy;// * 32.f + 16; } } class PerIncident { array ammoCount(4); bool initiallyBlue; CHAR::Char character; Point warpTargetLocation; string incidentNumberAsString; int recordNumberOfDeaths = 10000; //arbitarily large int recordTimeElapsed = UNFINISHEDINCIDENTTIME; string recordTimeElapsedAsString = "$|||||||--:--"; int parTime; int LeftP, LeftT = -1, RightP, RightT, TopP, TopT, BottomP, BottomT, WidthP, HeightP, CenterXP, CenterYP, LeftOuterBoundP, TopOuterBoundP, RightOuterBoundP; array SwitchBlocks; array AmmoPickupLocations; PerIncident(){} void stringifyRecordTime() { if (recordTimeElapsed != UNFINISHEDINCIDENTTIME) recordTimeElapsedAsString = StringifyTime(recordTimeElapsed, parTime); } void setup(int x, int y) { warpTargetLocation = Point(x * 32, y * 32); const int params = jjParameterGet(x, y, 8, 12); ///@Event 240=Warp Target |+|Area |Warp |Target |WarpID:8|Character:{Any,Jazz,Spaz,Lori}2|Color:{Yellow,Blue}1|Par:5 switch (params & 3) { case 0: character = CHAR::Char(-1); break; case 1: character = CHAR::JAZZ; break; case 2: character = CHAR::SPAZ; break; case 3: character = AllowLori ? CHAR::LORI : CHAR::JAZZ; break; } initiallyBlue = params & 4 == 4; parTime = (params >> 3) & 31; //jjDebug(incidentNumberAsString + ": " + parTime); ///@Event 14=Starting Ammo |+|Area |Start |Ammo |Ammo:6|Weapon:{Switcher,Dasher,Builder,Ghoster}2 int otherX = x + 1; while (true) { if (jjEventGet(otherX, y) != 14) { if (otherX == x + 1) //none specified ammoCount[0] = 63; //infinite break; } else { ammoCount[jjParameterGet(otherX, y, 6, 2)] = jjParameterGet(otherX, y, 0, 6); ++otherX; } } } } array Incidents; int NumberOfDeathsThisIncident; int TimeStartedThisIncident; string TimeElapsedStringThisIncident = ""; bool DeathsRecordSet = false; bool TimeElapsedRecordSet = false; uint LastIncidentCompleted = 0; int CurrentMenuOption = 0; int PreviousMenuOption = 0; uint8 ThumbnailFadeTimer = 0; bool ViewingLevelSelect = false; bool PressedMenuKeyLastTick = false; uint8 PaletteID = 0; array IncidentNames; class SwitchBlock { Point location; uint8 triggerID; //uint16 tileOff; //uint16 tileOn; uint16 originalTileID; void doSwitch() const { jjTileSet(4, location.x, location.y, jjTileGet(4, location.x, location.y) ^ 1); } SwitchBlock(){} SwitchBlock(int xx, int yy, uint16 tileID, uint16 newTriggerID = CurrentTriggerID) { location = Point(xx, yy); //tileOff = tileID; //tileOn = tileOff ^ 1; originalTileID = tileID; if (tileID >= 36 && tileID <= 39) { triggerID = ((tileID - 36) >> 1) ^ 1; } else { triggerID = newTriggerID; //jjTileSet(4, xx, yy, 37 + (triggerID << 1)); } } } array@ SwitchBlocks; uint8 tileIDIsWallTile(uint16 tileID) { if (tileID == FIRSTWALLTILE) return 3; else if (tileID == LASTCAVETILE) return 1; else if (tileID == 0 || tileID == 105) return 0; return 2; } void applyOutlinesToTile(uint8 t, uint h, uint v, uint8 l) { uint16 newTileID = FIRSTWALLTILE; if (tilesAreWalls[h][v-1] < t) newTileID += 1; //top if (tilesAreWalls[h+1][v] < t) newTileID += 2; //right if (tilesAreWalls[h][v+1] < t) newTileID += 4; //bottom if (tilesAreWalls[h-1][v] < t) newTileID += 8; //left if (tilesAreWalls[h+1][v] >= t && tilesAreWalls[h][v-1] >= t && tilesAreWalls[h+1][v-1] < t) newTileID += 16; //top right if (tilesAreWalls[h+1][v] >= t && tilesAreWalls[h][v+1] >= t && tilesAreWalls[h+1][v+1] < t) newTileID += 32; //bottom right if (tilesAreWalls[h-1][v] >= t && tilesAreWalls[h][v+1] >= t && tilesAreWalls[h-1][v+1] < t) newTileID += 64; //bottom left if (tilesAreWalls[h-1][v] >= t && tilesAreWalls[h][v-1] >= t && tilesAreWalls[h-1][v-1] < t) newTileID += 128; //top left if (t == 1) newTileID = LASTCAVETILE - (newTileID - FIRSTWALLTILE); //cave jjTileSet(l, h-1, v-1, newTileID); } array> tilesAreWalls(LEVELWIDTH + 2, array(LEVELHEIGHT + 2, 0)); void onLevelLoad() { jjGenerateSettableTileArea(4, 0, 0, LEVELWIDTH, LEVELHEIGHT); { //redo walls for (uint h = 0; h < LEVELWIDTH; ++h) tilesAreWalls[h][0] = tilesAreWalls[h][LEVELHEIGHT] = 2; //wall for (uint v = 0; v < LEVELHEIGHT; ++v) tilesAreWalls[0][v] = tilesAreWalls[LEVELWIDTH][v] = 2; for (uint h = 1; h <= LEVELWIDTH; ++h) for (uint v = 1; v <= LEVELHEIGHT; ++v) tilesAreWalls[h][v] = tileIDIsWallTile(jjTileGet(4, h-1, v-1)); } { jjTexturedBGTexture = TEXTURE::NORMAL; jjSetFadeColors(255,255,255); ColoredBounce.pipe = STRING::SPECIALSIGN; } { //jjSampleLoad(SOUND::COMMON_HARP1, "SUCCESSF.WAV"); const array SampleFilenames = {"STV2-Switch.wav", "STV2-Dash.wav", "STV2-Build.wav", "STV2-Ghost.wav", "STV2-Fall.wav"}; for (uint i = 0; i < SampleFilenames.length; ++i) jjSampleLoad(SOUND::Sample(SOUND::FROG_FROG + i), SampleFilenames[i]); } { jjAnimSets[ANIM::CUSTOM[0]].allocate(array = {3}); jjPIXELMAP verticalGradient(2, 80); for (uint i = 0; i < verticalGradient.height; ++i) verticalGradient[0,i] = i*256/160; verticalGradient.save(jjAnimFrames[jjAnimations[jjAnimSets[ANIM::CUSTOM[0]]]]); jjPIXELMAP asteroid(0, 0, 64, 64, 5); AsteroidCurFrame = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]]]+1; jjANIMFRAME@ asteroidFrame = jjAnimFrames[AsteroidCurFrame]; asteroid.save(asteroidFrame); asteroidFrame.hotSpotX = -asteroidFrame.width / 2; asteroidFrame.hotSpotY = -asteroidFrame.height / 2; jjPIXELMAP ghostcord(0, 64, 32, 96, 5); GhostCordCurFrame = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]]]+2; jjANIMFRAME@ ghostCordFrame = jjAnimFrames[GhostCordCurFrame]; ghostcord.save(ghostCordFrame); ghostCordFrame.hotSpotX = -ghostCordFrame.width / 2; ghostCordFrame.hotSpotY = 0; jjAnimSets[ANIM::CUSTOM[1]].load(0, "SwitchTestV2.j2a"); jjAnimSets[ANIM::CUSTOM[2]].load(1, "SwitchTestV2.j2a"); for (int i = 4; i <= 8; ++i) jjAnimFrames[jjAnimations[jjAnimSets[ANIM::FONT]] + i] = jjAnimFrames[jjAnimations[jjAnimSets[ANIM::CUSTOM[1]]] + i]; //par stars //jjAnimations[jjAnimSets[ANIM::FONT] + 2] = jjAnimations[jjAnimSets[ANIM::CUSTOM[1]]]; //large font } { string incidentNameList; for (uint i = 0; i < 10; ++i) incidentNameList += jjHelpStrings[i]; IncidentNames = incidentNameList.split('|'); } { for (int x = LEVELWIDTH - 1; x >= 0; --x) for (int y = LEVELHEIGHT - 1; y >= 0; --y) { const uint8 eventID = jjEventGet(x, y); ///@Event 242=Corner|+|Area|Corner||WarpID:8 if (eventID == AREA::WARPTARGET || eventID == AREA::AREAID) { const uint8 warpID = jjParameterGet(x, y, 0, 8); if (warpID >= Incidents.length) Incidents.resize(warpID + 1); PerIncident@ incident = Incidents[warpID]; if (eventID == AREA::WARPTARGET) { incident.incidentNumberAsString = formatInt(warpID + 1, "0", 2); incident.setup(x,y); } else { //int LeftP, LeftT, RightP = -1, RightT, TopP, TopT, BottomP, BottomT; if (incident.LeftT == -1) { //first corner found incident.LeftT = x; incident.TopT = y; } else { if (x >= incident.LeftT) incident.RightT = x; else { incident.RightT = incident.LeftT; incident.LeftT = x; } if (y >= incident.TopT) incident.BottomT = y; else { incident.BottomT = incident.TopT; incident.TopT = y; } incident.RightT += 1; incident.BottomT += 1; incident.LeftP = incident.LeftT << 5; incident.RightP = incident.RightT << 5; incident.TopP = incident.TopT << 5; incident.BottomP = incident.BottomT << 5; incident.WidthP = incident.RightP - incident.LeftP; incident.HeightP = incident.BottomP - incident.TopP; incident.CenterXP = incident.LeftP + incident.WidthP / 2; incident.CenterYP = incident.TopP + incident.HeightP / 2; incident.LeftOuterBoundP = incident.LeftP - 12*32; incident.RightOuterBoundP = incident.RightP + 12*32; incident.TopOuterBoundP = incident.TopP - 8*32; //jjDebug(warpID + ": " + incident.WidthP + ", " + incident.HeightP); for (int h = incident.LeftT; h <= incident.RightT; ++h) for (int v = incident.TopT; v <= incident.BottomT; ++v) { const uint16 tileID = jjTileGet(4, h-1, v-1); if (tileID >= 36 && tileID <= 39) //switch block! incident.SwitchBlocks.insertLast(SwitchBlock(h-1, v-1, tileID)); if (jjEventGet(h-1, v-1) == OBJECT::FASTFIRE) incident.AmmoPickupLocations.insertLast(Point(h-1,v-1)); } } } } } @SwitchBlocks = @Incidents[WarpTargetID >= 0 ? WarpTargetID : (Incidents.length + WarpTargetID)].SwitchBlocks; } { jjAnimSets[ANIM::CUSTOM[3]].allocate(array={Incidents.length}); uint thumbnailFrameID = jjAnimations[jjAnimSets[ANIM::CUSTOM[3]]]; const array switchBlockThumbnailColors = {116, 113, 133, 129, 0,0,0, 120}; for (uint i = 0; i < Incidents.length; ++i) { const PerIncident@ incident = Incidents[i]; jjPIXELMAP thumbnail(incident.RightT - incident.LeftT + 1, incident.BottomT - incident.TopT + 1); uint xP = 0; for (int x = incident.LeftT; x <= incident.RightT; ++x, ++xP) { const auto@ column = tilesAreWalls[x+1]; uint yP = 0; for (int y = incident.TopT; y <= incident.BottomT; ++y, ++yP) switch (column[y+1]) { case 1: thumbnail[xP,yP] = 120; break; case 2: { const uint16 shortenedTileID = uint(jjTileGet(4,x,y) - 36); if (shortenedTileID < 8) thumbnail[xP,yP] = switchBlockThumbnailColors[shortenedTileID]; break; } case 3: thumbnail[xP,yP] = 115; break; } } jjANIMFRAME@ thumbframe = jjAnimFrames[thumbnailFrameID++]; thumbnail.save(thumbframe); thumbframe.hotSpotX = -thumbnail.width / 2; thumbframe.hotSpotY = -thumbnail.height / 2; } } { for (uint h = 1; h <= LEVELWIDTH; ++h) for (uint v = 1; v <= LEVELHEIGHT; ++v) { const uint8 t = tilesAreWalls[h][v]; if (t == 1 || t == 3) { applyOutlinesToTile(t,h,v,4); if (t == 3) { const auto top = tilesAreWalls[h][v-1], bottom = tilesAreWalls[h][v+1], left = tilesAreWalls[h-1][v], right = tilesAreWalls[h+1][v]; if (((top == 1 || bottom == 1) && !(left == 3 && right == 3)) || ((left == 1 || right == 1) && !(top == 3 && bottom == 3))) { jjGenerateSettableTileArea(5,h-1,v-1,1,1); applyOutlinesToTile(1,h,v,5); } } } } tilesAreWalls.resize(0); } { for (uint i = 0; i < 4; ++i) { jjPAL DarkerPalette = jjBackupPalette; DarkerPalette.fill(0,0,0, 176, 48, i / 4.0); Palettes.insertLast(@DarkerPalette); } jjSTREAM settings("SwitchTestV2-Settings.asdat"); if (!settings.isEmpty()) { settings.pop(PaletteID); if (PaletteID != 0) TogglePalette(); } } { //jjHelpStrings[10] = "switchtestv2someotherfilename.asdat"; jjSTREAM records(jjHelpStrings[10]); uint numberOfRecords = records.getSize() / 8; //will be 0 if the file doesn't exist yet if (numberOfRecords > Incidents.length) //improperly formatted file somehow numberOfRecords = Incidents.length; bool everyIncidentHasBeenBeatenSoFar = true; for (uint i = 0; i < numberOfRecords; ++i) { records.pop(Incidents[i].recordNumberOfDeaths); records.pop(Incidents[i].recordTimeElapsed); if (Incidents[i].recordTimeElapsed != 70 * 10000) { if (everyIncidentHasBeenBeatenSoFar) LastIncidentCompleted = i + 1; } else everyIncidentHasBeenBeatenSoFar = false; Incidents[i].stringifyRecordTime(); //jjDebug(i + ": " + Incidents[i].recordTimeElapsedAsString); } if (LastIncidentCompleted >= Incidents.length) LastIncidentCompleted = Incidents.length - 1; } { jjWeapons[1].replenishes = false; for (int i = 1; i <= 9; ++i) jjWeapons[i].defaultSample = false; jjObjectPresets[OBJECT::BLASTERBULLET].behavior = Switcher; jjObjectPresets[OBJECT::BOUNCERBULLET].behavior = Dasher; jjObjectPresets[OBJECT::BOUNCERBULLET].xSpeed = 32; jjObjectPresets[OBJECT::BOUNCERBULLET].ySpeed = 0; jjObjectPresets[OBJECT::BOUNCERBULLET].xAcc = 4; jjObjectPresets[OBJECT::BOUNCERBULLET].yAcc = 0; jjObjectPresets[OBJECT::ICEBULLET].behavior = Builder; jjObjectPresets[OBJECT::ICEBULLET].xSpeed = 1; jjObjectPresets[OBJECT::ICEBULLET].freeze = 0; jjObjectPresets[OBJECT::ICEBULLET].lightType = LIGHT::NONE; jjObjectPresets[OBJECT::ICEBULLET].curFrame = jjAnimations[jjAnimSets[ANIM::CUSTOM[2]] + 2] + 8; jjObjectPresets[OBJECT::SEEKERBULLET].behavior = Ghoster; jjObjectPresets[OBJECT::MORPH].behavior = MorphBeam; jjObjectPresets[OBJECT::MORPH].playerHandling = HANDLING::SPECIALDONE; jjObjectPresets[OBJECT::FASTFEET].behavior = Recolor; jjObjectPresets[OBJECT::FASTFEET].playerHandling = HANDLING::SPECIALDONE; jjObjectPresets[OBJECT::AIRBOARD].behavior = Airboard(); jjObjectPresets[OBJECT::AIRBOARD].scriptedCollisions = true; jjObjectPresets[OBJECT::FASTFIRE].behavior = Ammo(); jjObjectPresets[OBJECT::FASTFIRE].scriptedCollisions = true; jjObjectPresets[OBJECT::BUBBLESHIELDBULLET].behavior = function(obj) { obj.delete(); }; } for (uint transition = 0; transition < 4; ++transition) { jjPIXELMAP new(39 - transition); const jjPIXELMAP old(39 - (transition ^ 1)); for (uint frame = 0; frame < 16; ++frame) { const uint corner = (frame + 1) * 4; for (uint x = 0; x < 32; ++x) for (uint y = 0; y < 32; ++y) if (x + y < corner) new[x,y] = old[x,y]; new.save(jjTileCount + (transition << 4) + frame); } } } void onLevelBegin() { Player.spriteMode = SPRITE::INVISIBLE; if (WarpTargetID < 0) //debug AssignWarpTargetID(Incidents.length + WarpTargetID); //e..g -1 is last, -2 is next but last if (jjGameMode == GAME::CTF) jjChat("/noctfcolors on"); if (jjGameConnection != GAME::LOCAL && jjIsServer) jjChat("/nosplitscreeners on"); for (int i = 1; i <= 4; ++i) { jjWeapons[i].allowed = true; jjWeapons[i].style = WEAPON::MISSILE; } changeIncident(Player); } int LastResolutionHeight; int ResolutionCameraOffsetX, ResolutionCameraOffsetY; int AsteroidCurFrame, GhostCordCurFrame; const float ASTEROIDXOFFSET = 200; class Asteroid { float xPos, yPos; float xSpeed, ySpeed; int angle; int height; int multiplier; int scaleCmp; Asteroid() { initialize(); } int opCmp(const Asteroid& in other) { return scaleCmp - other.scaleCmp; } void initialize() { xPos = jjRandom() & 800; yPos = 0; height = 480 + (jjRandom() % 280); xSpeed = ySpeed * multiplier / 3; //previous values ySpeed = ((jjRandom() & 31) + 4) / 17.f; angle = jjRandom(); multiplier = ((jjRandom() & 1) << 1) - 1; } void draw() { const int counter = int(yPos += ySpeed); const float scale = 1.5 + multiplier * ((counter - 256) / 256.f); scaleCmp = int(scale * 10000); jjDrawRotatedSpriteFromCurFrame(Player.cameraX + (xPos -= xSpeed), Player.cameraY + 700 - jjSin(counter) * height, AsteroidCurFrame, angle += multiplier, scale, scale, SPRITE::BRIGHTNESS, int8(scale * 66), (scale > 1.5) ? 6 : 7, 4, Player.playerID); if (counter >= 520) initialize(); } } array Asteroids(5); void onMain() { if (jjGameConnection != GAME::LOCAL && (Player.health <= 0 || !Player.isInGame)) { GameBegun = false; Dying = false; GameOver = false; CurrentMenuOption = 0; ViewingLevelSelect = false; } if (LastResolutionHeight != jjResolutionHeight) { ResolutionCameraOffsetX = (jjResolutionWidth - 320) / -2; ResolutionCameraOffsetY = (jjResolutionHeight - 200) / -2; if (jjGameConnection == GAME::LOCAL) { //in local games, having a partially empty layer 8 will normally leave trails, but by imposing a maxresolution SLIGHTLY smaller than the real resolution, this can be avoided LastResolutionHeight = jjResolutionHeight; jjChat("/maxresolution " + jjResolutionWidth + "x" + (LastResolutionHeight - 1)); for (int i = 0; i < 8; ++i) jjAlert(""); } } if (!jjLowDetail) { Asteroids.sortDesc(); for (int i = Asteroids.length; --i >= 0;) Asteroids[i].draw(); } const bool pressingF2 = jjKey[0x71] && !jjKey[0x11]; if (pressingF2 != PressingF2LastTick) { PressingF2LastTick = pressingF2; if (pressingF2) { PaletteID = (PaletteID + 1) & 3; TogglePalette(); jjSTREAM settings; settings.push(PaletteID); settings.save("SwitchTestV2-Settings.asdat"); } } for (int otherPlayerID = 0; otherPlayerID < 32; ++otherPlayerID) { const jjPLAYER@ otherPlayer = jjPlayers[otherPlayerID]; if (otherPlayer.isInGame && otherPlayer.spriteMode == SPRITE::INVISIBLE) { const bool flashing = otherPlayer.blink != 0 && ((jjRenderFrame >> 2) & 1) == 0; if (!flashing || (Dying && KnockedIntoScreenCounter != 0)) { if (!Dying || otherPlayer !is Player) { if (AirboardCounter < AIRBOARDHALFWAYTIME || otherPlayer !is Player) { //normal drawing case jjDrawSpriteFromCurFrame(otherPlayer.xPos, otherPlayer.yPos, otherPlayer.curFrame, otherPlayer.direction, SPRITE::PLAYER, otherPlayerID); //jjDrawRectangle(otherPlayer.xPos - 20, otherPlayer.yPos, 40, 1, 24); //jjDrawRectangle(otherPlayer.xPos, otherPlayer.yPos - 20, 1, 40, 24); } else { const auto scale = (AIRBOARDHALFWAYTIME - (AirboardCounter - AIRBOARDHALFWAYTIME)) / 50.f + 1; Player.light = 12 + int(scale * 2); jjDrawResizedSpriteFromCurFrame(otherPlayer.xPos, otherPlayer.yPos, otherPlayer.curFrame, scale,scale, SPRITE::PLAYER, otherPlayerID); } } else { if (SweptAwayIntoSpaceCounter > 20) { const float scale = SweptAwayIntoSpaceCounter / 160.f; jjANIMATION@ animation = jjAnimations[LastPlayerCurAnim]; jjDrawResizedSpriteFromCurFrame(otherPlayer.xPos, otherPlayer.yPos, animation.firstFrame + ((jjGameTicks >> 2) % animation.frameCount), scale * otherPlayer.direction, scale, SPRITE::PLAYER, otherPlayerID, 6); } else if (KnockedIntoScreenCounter != 0) { const jjANIMATION@ FallAnim = jjAnimations[jjAnimSets[otherPlayer.setID] + RABBIT::FALL]; float scale = KnockedIntoScreenCounter; if (scale > 3.0f) scale = 3.0f; jjDrawResizedSprite(otherPlayer.xPos, otherPlayer.yPos, ANIM::AMMO, 5, int(scale * 2), scale, scale, SPRITE::SINGLEHUE, 95, 1); if (!flashing) jjDrawRotatedSpriteFromCurFrame(otherPlayer.xPos, otherPlayer.yPos + KnockedIntoScreenCounter * 2, FallAnim.firstFrame + ((jjGameTicks >> 3) % FallAnim.frameCount), int(KnockedIntoScreenCounter * 4 * otherPlayer.direction), scale, scale, SPRITE::PLAYER, otherPlayerID, 1); } } } } } for (uint triggerID = 0; triggerID < 2; ++triggerID) { if (TriggerTimers[triggerID] == 15) { //15 and 16 look just the same TriggerTimers[triggerID] = -1; jjTileType[38 - (triggerID << 1)] = 0; //normal jjTileType[39 - (triggerID << 1)] = 0; // } else if (TriggerTimers[triggerID] != -1) { if (TriggerTimers[triggerID] == 0) { jjTileType[38 - (triggerID << 1)] = 3; //invisible jjTileType[39 - (triggerID << 1)] = 3; // } const uint tileID = jjTileCount + ((triggerID << 5) | TriggerTimers[triggerID]); for (int i = SwitchBlocks.length - 1; i >= 0; --i) { const SwitchBlock@ block = SwitchBlocks[i]; if (block.triggerID == triggerID) jjDrawTile(block.location.x << 5, block.location.y << 5, tileID + ((jjTileGet(4, block.location.x, block.location.y) & 1) << 4), TILE::ALLQUADRANTS, 5); } ++TriggerTimers[triggerID]; } } } void onDrawLayer8(jjPLAYER@ play, jjCANVAS@ screen) { jjUseLayer8Speeds = true; if (jjLayerHasTiles[2] = jjKey[0x76]) //F7 jjLayerYOffset[2] = jjSin(jjGameTicks << 3) * 4; //for (uint i = 0; i < 16; ++i) // for (uint j = 0; j < 4; ++j) // screen.drawTile(i * 32, j * 32, jjTileCount + j * 16 + i); } const int glowOffset = 320-78-(jjGameConnection==GAME::LOCAL?1:2); void onDrawLayer6(jjPLAYER@ play, jjCANVAS@ screen) { jjUseLayer8Speeds = false; screen.drawResizedSprite(ResolutionCameraOffsetX, ResolutionCameraOffsetY + glowOffset, ANIM::CUSTOM[0], 0, 0, jjResolutionWidth, 1.f, SPRITE::ALPHAMAP, 207); //screen.drawString(ResolutionCameraOffsetX + 50, ResolutionCameraOffsetY + 50, "Hello World", STRING::MEDIUM, STRING::NORMAL, 0, SPRITE::RESIZED, 128); } void onDrawLayer4(jjPLAYER@, jjCANVAS@ screen) { const Point@ point = Incidents[WarpTargetID].warpTargetLocation; int xPos = point.x - 32; int yPos = point.y - 64; //draw staticky screen screen.drawRectangle(xPos, yPos, 96, 64, 70); if (!jjLowDetail) screen.drawRectangle(xPos += 2, yPos += 2, 92, 60, 68, SPRITE::BLEND_DISSOLVE, 192); screen.drawString(xPos, yPos + 14, Incidents[WarpTargetID].incidentNumberAsString, jjAnimations[jjAnimSets[ANIM::CUSTOM[1]]]);//, STRING::NORMAL, 0, SPRITE::PALSHIFT); if (!jjLowDetail) { screen.drawRectangle(xPos, yPos, 92, 60, 66, SPRITE::BLEND_DISSOLVE, 128); screen.drawRectangle(xPos, yPos, 92, 60, 64, SPRITE::BLEND_DISSOLVE, 64); } //screen.drawString(xPos - 32, yPos + 80, IncidentNames[WarpTargetID], STRING::MEDIUM); const uint xTile = point.x / 32 - 1, yTile = point.y / 32 - 2; uint16 tileID; for (uint x = 0; x < 3; ++x) for (uint y = 0; y < 2; ++y) if ((tileID = jjTileGet(4, xTile+x, yTile+y)) != 43) //blocks spawned by Builder in front of the screen screen.drawTile((xTile + x) << 5, (yTile + y) << 5, tileID); } string ColorTimeString(const string &in time, const string &in color, bool includeNoStarPrefix) { if (includeNoStarPrefix || time[0] != '$'[0]) return time.substr(0,1) + color + time.substr(1); return color + time.substr(1); } bool GameBegun = WarpTargetID != 0; bool GameOver = false; bool onDrawAmmo(jjPLAYER@ play, jjCANVAS@ screen) { if (!play.isLocal || GameOver) return true; if (!GameBegun) { if (!ViewingLevelSelect) { if (/*jjGameConnection != GAME::LOCAL || */LastIncidentCompleted == 0) { if ((jjRenderFrame & 8) == 0) screen.drawString(0x8000, jjResolutionHeight - 100, "Press Fire", STRING::MEDIUM, STRING::SPIN); } else { array Options = {"#New Game", "#Continue", "#Incident Select"}; if (jjGameConnection != GAME::LOCAL) Options.removeAt(2); if (LastIncidentCompleted == Incidents.length-1) Options.removeAt(1); for (uint i = 0; i < Options.length; ++i) screen.drawString(0x8000, jjResolutionHeight - 250 + i*50, Options[i], STRING::MEDIUM, int(i) == CurrentMenuOption ? STRING::SPIN : STRING::NORMAL); } screen.drawString(0x10000 + 10, 12, "§1|F2 for brightness", STRING::SMALL); } else { screen.drawString(0x8000, 40, "Incident Select", STRING::LARGE); if (jjSubscreenWidth >= 800) { if (ThumbnailFadeTimer != 0) screen.drawResizedSprite(80, jjSubscreenHeight>>1, ANIM::CUSTOM[3], 0, PreviousMenuOption, 5,5, SPRITE::BLEND_DISSOLVE, ThumbnailFadeTimer); screen.drawResizedSprite(80, jjSubscreenHeight>>1, ANIM::CUSTOM[3], 0, CurrentMenuOption, 5,5, ThumbnailFadeTimer == 0 ? SPRITE::BLEND_NORMAL : SPRITE::BLEND_DISSOLVE, 255 - ThumbnailFadeTimer); if (ThumbnailFadeTimer != 0) ThumbnailFadeTimer -= 8; } array xPos = {0x10000 + (jjSubscreenWidth - 120), 180, 450}; for (uint j = 0; j < 3; ++j) xPos[j] += (jjSubscreenWidth - 640) / 2 * (j == 0 ? -1 : 1); int yPos = 120; const uint maxIncidentsDisplayedAtOnce = (jjSubscreenHeight - 170) / 30; int firstIncidentToList = CurrentMenuOption - (maxIncidentsDisplayedAtOnce / 2); if (firstIncidentToList < 0) firstIncidentToList = 0; else { const int theMax = int(Incidents.length) - maxIncidentsDisplayedAtOnce - 1; if (firstIncidentToList > theMax) firstIncidentToList = theMax; } for (uint i = 0; i < maxIncidentsDisplayedAtOnce; ++i) { const uint incidentNumber = i + firstIncidentToList; const auto@ incident = Incidents[incidentNumber]; const array strings = {"|||" + incident.incidentNumberAsString, "#" + IncidentNames[incidentNumber], /*incidentNumber < LastIncidentCompleted ? */ColorTimeString(incident.recordTimeElapsedAsString, incident.recordNumberOfDeaths == 0 ? "||||" : "", true)/* : ""*/}; for (uint j = 0; j < 3; ++j) screen.drawString(xPos[j], yPos, strings[j], STRING::MEDIUM, (j == 1 && int(incidentNumber) == CurrentMenuOption) ? STRING::SPIN : /*incidentNumber > LastIncidentCompleted ? STRING::DARK :*/ STRING::NORMAL); yPos += 30; } const int totalsYStart = jjSubscreenHeight - 60; screen.drawSprite(5, totalsYStart, ANIM::CUSTOM[1], 0, 5, 1, SPRITE::PALSHIFT, 230); const uint MaxStars = (Incidents.length - 1)*3; screen.drawString(26, totalsYStart+10, (TotalStars < MaxStars ? ": " : "||||: ") + TotalStars + "/" + MaxStars, STRING::MEDIUM); screen.drawSpriteFromCurFrame(17, totalsYStart+33, jjObjectPresets[OBJECT::STOPWATCH].curFrame + 7 - (CurrentMenuOption & 7)); screen.drawString(26, totalsYStart+30, TotalTime, STRING::MEDIUM); if (!UsedIngameF11AtLeastOnce && jjGameConnection == GAME::LOCAL) screen.drawString(0x10000 + 10, 12, "§1|Hold F11 ingame to return here.", STRING::SMALL); return true; } const int titleYPos = jjResolutionHeight / 5; screen.drawString(0x8000, titleYPos, "Mighty Switch Test!", STRING::LARGE, STRING::NORMAL, 0, SPRITE::SINGLEHUE, 112); screen.drawString(0x8110, titleYPos + 14, "2!", STRING::LARGE, STRING::NORMAL, 0, SPRITE::SINGLEHUE, 128); } else if (AirboardCounter != 0) { if (AirboardCounter >= AIRBOARDHALFWAYTIME) { //finished screen.drawString(0x8000, 70, !Cheater ? ("Incident " + Incidents[WarpTargetID].incidentNumberAsString + " Complete!") : ("Cheated in Incident " + Incidents[WarpTargetID].incidentNumberAsString), STRING::LARGE, STRING::BOUNCE); const bool wideScreen = jjResolutionWidth > 640; const int ColumnZeroXPos = 50; //labels const int ColumnOneXPos = wideScreen ? 200 : 180; //new const int ColumnTwoXPos = wideScreen ? 380 : 330; //record const int ColumnThreeXPos = wideScreen ? 610 : 520; //par int YPos = 160; if (!Cheater) { screen.drawString(ColumnOneXPos, YPos, "New:", STRING::MEDIUM); screen.drawString(ColumnTwoXPos, YPos, "Record:", STRING::MEDIUM); screen.drawString(ColumnThreeXPos, YPos, "Par:", STRING::MEDIUM); } YPos += 40; if (!Cheater) { screen.drawString(ColumnZeroXPos, YPos, "Time:", STRING::MEDIUM); screen.drawString(ColumnOneXPos, YPos, ColorTimeString(TimeElapsedStringThisIncident, TimeElapsedRecordSet ? "|||" : "", false), STRING::MEDIUM); } if (Cheater) {} else if (TimeElapsedRecordSet) screen.drawString(ColumnTwoXPos, YPos, "#|||||~New Record!", STRING::MEDIUM, STRING::SPIN); else screen.drawString(ColumnTwoXPos, YPos, ColorTimeString(Incidents[WarpTargetID].recordTimeElapsedAsString, "", false), STRING::MEDIUM); if (!Cheater) screen.drawString(ColumnThreeXPos, YPos, "0:" + formatInt(Incidents[WarpTargetID].parTime, "0", 2), STRING::MEDIUM); YPos += 40; screen.drawString(ColumnZeroXPos, YPos, "Deaths:", STRING::MEDIUM); screen.drawString(ColumnOneXPos, YPos, (DeathsRecordSet ? NumberOfDeathsThisIncident == 0 ? "||||" : "|||" : "") + NumberOfDeathsThisIncident, STRING::MEDIUM); if (Cheater) {} else if (DeathsRecordSet) screen.drawString(ColumnTwoXPos, YPos, (NumberOfDeathsThisIncident == 0 ? "#|" : "#") + "|||||~New Record!", STRING::MEDIUM, STRING::SPIN); else screen.drawString(ColumnTwoXPos, YPos, "" + Incidents[WarpTargetID].recordNumberOfDeaths, STRING::MEDIUM); if (AirboardCounter == AIRBOARDHALFWAYTIME) { screen.drawString(0x8000, jjResolutionHeight - 100, "|F|I|R|E|: |Continue |B|A|C|K|S|P|A|C|E|:|||||| Retry", STRING::MEDIUM, ColoredBounce); screen.drawString(0x8000, jjResolutionHeight - 70, "|F|1|1|: ||Incident Select", STRING::MEDIUM, ColoredBounce); } } else { //started //eh } } else { for (uint i = 1; i <= 4; ++i) { const jjANIMATION@ curAnim = jjAnimations[jjAnimSets[ANIM::CUSTOM[2]] + i - 1]; if (curAnim.frameCount > 0) { const uint curFrame = curAnim.firstFrame + ((jjGameTicks >> 2) % curAnim.frameCount); const int x = jjSubscreenWidth - 120 + i * 25; const SPRITE::Mode spriteMode = i == play.currWeapon ? SPRITE::SINGLEHUE : SPRITE::TRANSLUCENT; const uint8 spriteParam = 128 - (CurrentTriggerID << 4); int ammoCount = play.ammo[i]; if (i == play.currWeapon && ammoCount != 0) screen.drawSprite(x - 8, jjSubscreenHeight - 17, ANIM::FONT, 1, (ammoCount == 63) ? 95 : (16 + ammoCount), 1, SPRITE::SINGLEHUE, spriteParam); if (ammoCount == 63) ammoCount = 1; while (ammoCount != 0) screen.drawSpriteFromCurFrame(x, jjSubscreenHeight - 3 - ammoCount-- * 25, curFrame, 1, spriteMode, spriteParam); } } if (NumberOfDeathsThisIncident >= 10)// && !Dying) screen.drawString(0x10000 + 10, 12, "§1|F7 for hints", STRING::SMALL); if (TimeSpentPressingF11 != 0) { screen.drawString(0x10000 + 10, 34, "§1|Hold F11 for Incident Select.", STRING::SMALL); screen.drawRectangle(jjSubscreenWidth - 160, 50, TimeSpentPressingF11, 8, 16 + (125 - TimeSpentPressingF11) / 20); } } return true; } bool onDrawScore(jjPLAYER@ play, jjCANVAS@ screen) { return true;//!GameBegun; } bool onDrawHealth(jjPLAYER@ play, jjCANVAS@ screen) { return true; } bool onDrawLives(jjPLAYER@ play, jjCANVAS@ screen) { return true; } bool onDrawShieldTimer(jjPLAYER@ play, jjCANVAS@ screen) { //this doesn't currently exist, but it's a plausible name for such a hook if one is ever defined, so this might be helpful someday return true; } const uint AIRBOARDTOTALTIME = 560; const uint AIRBOARDHALFWAYTIME = 280; //AIRBOARDTOTALTIME / 2; uint SpendFramesCheckingIfPlayerIsStuck = 0; uint SweptAwayIntoSpaceCounter = 0; uint SweptAwayIntoSpaceMaximumLength = 160; float KnockedIntoScreenCounter = 0; bool Dying = false; uint AirboardCounter = 0, AirboardFlyawayCounter = 0; bool WarpingToNextIncidentOnline = false; uint LastPlayerCurAnim; float LastPlayerXSpeed, LastPlayerYSpeed; int CurrentTriggerID = 0; bool RetryingLastIncident = false; uint TimeSpentPressingF11 = 0; bool UsedIngameF11AtLeastOnce = false; bool PressingF2LastTick = false; void immobilize(jjPLAYER@ play) { play.keyFire = play.keyJump = play.keySelect = play.keyRun = play.keyLeft = play.keyRight = play.keyUp = play.keyDown = false; play.xSpeed = play.xAcc = play.ySpeed = play.yAcc = 0; play.idle = 0; } void ReturnToLevelSelect() { GameBegun = false; ViewingLevelSelect = true; CalculateTotalStars(); Dying = false; RetryingLastIncident = false; TimeSpentPressingF11 = 0; AirboardCounter = 0; Player.lighting = 100; Player.fly = FLIGHT::NONE; Player.shieldTime = -70; CurrentMenuOption = WarpTargetID; } uint TotalStars; string TotalTime; void CalculateTotalStars() { TotalStars = 0; uint totalTimeInt = 0; uint hours = 0; for (uint i = 0; i < Incidents.length - 1; ++i) { const PerIncident@ incident = Incidents[i]; const int timeDifference = incident.recordTimeElapsed / 70 - incident.parTime; if (timeDifference < 0) TotalStars += 3; else if (timeDifference < 3) TotalStars += 2; else if (timeDifference < 6) TotalStars += 1; if (incident.recordTimeElapsed != UNFINISHEDINCIDENTTIME) totalTimeInt += incident.recordTimeElapsed; else hours += 1; } hours += totalTimeInt / (70*60*60); totalTimeInt %= (70*60*60); TotalTime = ": " + hours + ":" + StringifyTime(totalTimeInt).substr(1); } void Die() { if (!Dying) { Player.cameraFreeze(Player.cameraX, Player.cameraY, false, true); NumberOfDeathsThisIncident += 1; TimeSinceLastMorph = 140; Dying = true; Cheater = false; Player.keyFire = false; Player.specialMove = 0; } } void SweepIntoSpace(bool quick) { if (!quick) { SweptAwayIntoSpaceCounter = SweptAwayIntoSpaceMaximumLength; if (SweptAwayIntoSpaceMaximumLength > 70) SweptAwayIntoSpaceMaximumLength -= 2; //shorter each time, to limit player boredom jjSample(Player.xPos, Player.yPos, SOUND::FROG_FROG4);//, 63, 22050); } else SweptAwayIntoSpaceCounter = 45; LastPlayerCurAnim = Player.curAnim; LastPlayerXSpeed = Player.xSpeed / 8; LastPlayerYSpeed = Player.ySpeed / 8; Die(); } void safeWarp(jjPLAYER@ play, uint8 warpID) { play.warpToID(warpID, true); play.xPos = (int(play.xPos) & ~31) + 16; play.yPos = (int(play.yPos) & ~31) + 12; } void changeIncident(jjPLAYER@ play, bool warp = true) { if (warp) safeWarp(play, WarpTargetID); for (int i = SwitchBlocks.length - 1; i >= 0; --i) { const SwitchBlock@ block = SwitchBlocks[i]; const uint16 originalTileID = block.originalTileID; jjTileSet(4, block.location.x, block.location.y, originalTileID); if (!(originalTileID >= 36 && originalTileID <= 39)) //only a temporary block SwitchBlocks.removeAt(i); } for (uint i = jjObjectCount; --i != 0; ) if (jjObjects[i].behavior == Builder) jjDeleteObject(i); TriggerTimers[0] = TriggerTimers[1] = -1; for (uint tileID = 36; tileID <= 39; ++tileID) jjTileType[tileID] = 0; Triggers[0] = Triggers[1] = false; const auto@ incident = Incidents[WarpTargetID]; if (incident.character != -1) { const bool airboard = play.fly == FLIGHT::AIRBOARD; play.morphTo(incident.character, false); if (airboard) play.fly = FLIGHT::AIRBOARD; } Player.helicopter = 0; play.currWeapon = WEAPON::GUN9; for (uint i = 1; i <= incident.ammoCount.length; ++i) { play.ammo[i] = incident.ammoCount[i - 1]; jjWeapons[i].infinite = play.ammo[i] == 63; if (play.ammo[i] != 0 && i < play.currWeapon) play.currWeapon = i; } for (uint i = 0; i < incident.AmmoPickupLocations.length; ++i) { const Point@ point = incident.AmmoPickupLocations[i]; jjParameterSet(point.x, point.y, 2,1,0); } GhostTriggerID = CurrentTriggerID = incident.initiallyBlue ? 1 : 0; SetFur(); play.alreadyDoubleJumped = false; if (play.fly == FLIGHT::FLYCARROT) play.fly = FLIGHT::NONE; Dying = false; play.xOrg = play.xPos; play.yOrg = play.yPos; GhostX = GhostY = 0; TimeStartedThisIncident = jjGameTicks; TimeSinceLastMorph = 140; play.cameraFreeze(incident.warpTargetLocation.x + 16, incident.warpTargetLocation.y + 13, true, true); if (warp) play.cameraUnfreeze(true); } void beginIncident() { if (Player.currWeapon != WEAPON::GUN9) jjSamplePriority(SOUND::Sample(SOUND::FROG_FROG + Player.currWeapon - WEAPON::BLASTER)); //jjDebug(IncidentNames[WarpTargetID]); TimeStartedThisIncident = jjGameTicks; NumberOfDeathsThisIncident = 0; Cheater = false; } const uint NormalFur = jjLocalPlayers[0].fur; void SetFur() { const uint8 furColor = 128 - (CurrentTriggerID << 4); //0x28 - (CurrentTriggerID << 3); //if (jjGameMode == GAME::CTF)f // Player.fur = furColor | (furColor << 8) | (furColor << 16) | (furColor << 24); //else switch (Player.charCurr) { case CHAR::JAZZ: Player.fur = (NormalFur & 0x000000FF) | (furColor << 8) | (furColor << 16) | (furColor << 24); break; case CHAR::SPAZ: Player.fur = (NormalFur & 0xFF00FF00) | (furColor << 0) | (furColor << 16); break; } } int warpInsideTile(int xTile, int yTile) { const uint16 tileID = jjTileGet(4, xTile, yTile); if (tileID == 0 || tileID == 105) //space return -2; if (tileID == 37 || tileID == 39) //special block came into solidity return 1; //if (tileID == 105) //border for purposes of Dasher gun // return 3; if (jjMaskedPixel(xTile << 5, yTile << 5)) //wallclimbing return 2; if (tileID == uint(38 - (CurrentTriggerID << 1))) //special block that isn't solid return -1; return 0; } int warpInsidePixel(float x, float y) { return warpInsideTile(int(x) >> 5, int(y) >> 5); } void onPlayer(jjPLAYER@ play) { if (GameOver) { if (jjGameConnection == GAME::LOCAL) { play.xSpeed = 1; play.ySpeed = 0; play.direction = 1; } play.keyFire = false; play.fly = FLIGHT::AIRBOARD; play.shieldType = SHIELD::BUBBLE; play.shieldTime = 70 * 99; } else if (!GameBegun) { const bool canChangeSelection = ViewingLevelSelect || LastIncidentCompleted != 0; const bool fire = play.keyFire || play.keySelect || jjKey[0xD]; const bool up = canChangeSelection && play.keyUp; const bool down = canChangeSelection && play.keyDown; bool pageUp = false, pageDown = false, end = false, home = false; if (ViewingLevelSelect) { pageUp = jjKey[33]; pageDown = jjKey[34]; end = jjKey[35]; home = jjKey[36]; } if (!PressedMenuKeyLastTick) { const bool alreadyWon = LastIncidentCompleted == Incidents.length-1; int theMax; if (ViewingLevelSelect) theMax = Incidents.length - 1;//(LastIncidentCompleted + (alreadyWon ? 0 : 1)); else { theMax = 3; if (alreadyWon) theMax -= 1; if (jjGameConnection != GAME::LOCAL) theMax -= 1; } bool incidentChanged = false; const auto menuOptionBeforeChange = CurrentMenuOption; if (up) { incidentChanged = true; if ((CurrentMenuOption -= 1) < 0) CurrentMenuOption = theMax - 1; } else if (down) { incidentChanged = true; if ((CurrentMenuOption += 1) >= theMax) CurrentMenuOption = 0; } else if (pageUp) { incidentChanged = true; if ((CurrentMenuOption -= (jjSubscreenHeight - 170) / 30) < 0) CurrentMenuOption = 0; } else if (pageDown) { incidentChanged = true; if ((CurrentMenuOption += (jjSubscreenHeight - 170) / 30) >= theMax) CurrentMenuOption = theMax - 1; } else if (home) { incidentChanged = true; CurrentMenuOption = 0; } else if (end) { incidentChanged = true; CurrentMenuOption = theMax - 1; } else if (fire) { if (!ViewingLevelSelect) { if (alreadyWon && CurrentMenuOption == 1) CurrentMenuOption = 2; switch (CurrentMenuOption) { case 0: GameBegun = true; play.cameraUnfreeze(false); if (jjGameConnection != GAME::LOCAL) LastIncidentCompleted = AssignWarpTargetID(0); changeIncident(play); return; case 1: CurrentMenuOption = LastIncidentCompleted; break; case 2: ViewingLevelSelect = true; CalculateTotalStars(); CurrentMenuOption = 0; PressedMenuKeyLastTick = true; return; } } else { } ThumbnailFadeTimer = 0; //WarpingToNextIncidentOnline = true; AssignWarpTargetID(CurrentMenuOption); //play.warpToID(AssignWarpTargetID(CurrentMenuOption)); changeIncident(play); jjSamplePriority(SOUND::COMMON_SHLDOF3); play.shieldTime = 1; play.shieldType = SHIELD::BUBBLE; GameBegun = true; beginIncident(); return; } if (ViewingLevelSelect && incidentChanged) { PreviousMenuOption = menuOptionBeforeChange; ThumbnailFadeTimer = 248; } } immobilize(play); play.cameraFreeze(0, 160, false, true); PressedMenuKeyLastTick = fire || up || down || pageUp || pageDown || home || end; } else { if (!Dying) { if (WarpingToNextIncidentOnline) { if (play.warpID == 0) { WarpingToNextIncidentOnline = false; //play.cameraUnfreeze(false); beginIncident(); play.xOrg = play.xPos; play.yOrg = play.yPos; } } else if (play.fly != FLIGHT::AIRBOARD) { //normal gameplay const int shouldWarpTile = warpInsidePixel(play.xPos, play.yPos); if (shouldWarpTile > 0) { //inside solid tile {//if (shouldWarpTile == 1 && play.fly == 0) { jjSample(play.xPos, play.yPos, SOUND::COMMON_SMASH); jjSample(play.xPos, play.yPos, SOUND::SPAZSOUNDS_AUTSCH1); KnockedIntoScreenCounter = 1.0; } Die(); } else if (shouldWarpTile == -2) { //empty space SweepIntoSpace(false); } else { //normal tile TimeSinceLastMorph += 1; if (SpendFramesCheckingIfPlayerIsStuck > 0) { //copied over from SwitchTestV.j2as --SpendFramesCheckingIfPlayerIsStuck; if (warpInsidePixel(play.xPos, play.yPos) <= 0) { const int truncatedX = int(play.xPos) & 31; if (truncatedX < 12) { const int shouldWarp = warpInsidePixel(play.xPos - 32, play.yPos); if (shouldWarp >= 1) play.xPos += (12 - truncatedX); //extract //else if (shouldWarp == -1) // play.xPos -= 32; //squeeze into tube } else if (truncatedX > 20) { const int shouldWarp = warpInsidePixel(play.xPos + 32, play.yPos); if (shouldWarp >= 1) play.xPos -= (truncatedX - 20); //else if (shouldWarp == -1) // play.xPos += 32; } const int truncatedY = int(play.yPos) & 31; if (truncatedY > 12) { int shouldWarp = warpInsidePixel(play.xPos, play.yPos + 32); if (shouldWarp <= 0) { if (truncatedX < 12) shouldWarp = warpInsidePixel(play.xPos - 32, play.yPos + 32); else if (truncatedX > 20) shouldWarp = warpInsidePixel(play.xPos + 32, play.yPos + 32); } if (shouldWarp >= 1) play.yPos -= (truncatedY - 12); //else if (shouldWarp == -1) // play.yPos += 32; } else if (truncatedY < 4 ) { if (warpInsidePixel(play.xPos, play.yPos - 32) >= 1) play.yPos += (4 - truncatedY); } } } if (play.ySpeed < LastPlayerYSpeed && LastPlayerYSpeed < 0.f && jjMaskedHLine(int(play.xPos) - 13, 26, int(play.yPos) + 25)) { //walljump play.ySpeed = 1; if (play.keyDown) play.buttstomp = 1; play.keyJump = false; //probably not needed } LastPlayerYSpeed = play.ySpeed; if (play.currWeapon == WEAPON::SEEKER && play.ammo[WEAPON::CURRENT] != 0 && !Dying) { //ghost float ghostDrawX, ghostDrawY; if (GhostX == 0 && GhostY == 0) { ghostDrawX = play.xOrg; ghostDrawY = play.yOrg; } else { ghostDrawX = play.xPos + GhostX; ghostDrawY = play.yPos + GhostY; jjDrawRotatedSpriteFromCurFrame(play.xPos, play.yPos, GhostCordCurFrame, GhostAngle, 1, GhostScale, SPRITE::TRANSLUCENT,0, 4); } jjDrawSpriteFromCurFrame(ghostDrawX, ghostDrawY, play.curFrame, play.direction, SPRITE::/*TRANSLUCENT*/SINGLEHUE,72, 4); //if (play.blink == 0 || ((jjRenderFrame >> 2) & 1) == 1) //jjDrawSpriteFromCurFrame(play.xPos, play.yPos, play.curFrame, play.direction, SPRITE::PLAYER, play.playerID, 3); } if (jjGameConnection == GAME::LOCAL) { if (jjKey[0x7A]) { if (TimeSpentPressingF11++ == 125) { UsedIngameF11AtLeastOnce = true; ReturnToLevelSelect(); } } else TimeSpentPressingF11 = 0; } } } else { //on airboard if (play.shieldTime <= 0) { //just starting AirboardCounter = AIRBOARDTOTALTIME; AirboardFlyawayCounter = 0; play.xOrg = play.xPos; play.yOrg = play.yPos; play.cameraFreeze(play.cameraX, play.cameraY, false, true); play.lighting = 0; play.shieldType = SHIELD::BUBBLE; switch (play.charCurr) { case CHAR::JAZZ: jjSamplePriority(SOUND::ENDTUNEJAZZ_TUNE); break; case CHAR::SPAZ: jjSamplePriority(SOUND::ENDTUNESPAZ_TUNE); break; case CHAR::LORI: jjSamplePriority(SOUND::ENDTUNELORI_CAKE); break; } } else if (AirboardCounter == AIRBOARDHALFWAYTIME) { //halfway if (jjKey[0x7A]) { ReturnToLevelSelect(); Player.light = 13; return; } else { RetryingLastIncident = jjKey[0x08]; //backspace if (RetryingLastIncident || play.keyFire) { AirboardCounter -= 1; Player.light = 13; } } } else if (--AirboardCounter == AIRBOARDHALFWAYTIME-2) { if (!RetryingLastIncident) AssignWarpTargetID(WarpTargetID + 1); //advancement else RetryingLastIncident = false; changeIncident(play); play.cameraFreeze(play.xPos, play.yPos, true, true); play.lighting = 100; } ++AirboardFlyawayCounter; if (jjIsTSF && AirboardCounter == 80) play.shieldType = SHIELD::NONE; //TSF has sound count bug if (AirboardCounter == 0) { //end play.fly = FLIGHT::NONE; //lose airboard { jjOBJ@ shard = jjObjects[jjAddObject(OBJECT::SHARD, play.xPos, play.yPos, 0, CREATOR::OBJECT, BEHAVIOR::AIRBOARDFALL)]; //dispose of airboard shard.determineCurAnim(ANIM::PICKUPS, 36); shard.xSpeed = 3.5; } play.shieldTime = 1; //dispose of shield play.xPos = play.xOrg; play.yPos = play.yOrg; //play.xOrg = 0; //play.yOrg = 0; play.cameraUnfreeze(true); beginIncident(); } else { if (AirboardCounter >= AIRBOARDHALFWAYTIME) { //leave old place const auto angle = jjGameTicks << 3; const auto distance = AirboardFlyawayCounter * 1.5; play.xPos = play.xOrg + jjSin(angle) * distance; play.yPos = play.yOrg + jjCos(angle) * distance; } else if (AirboardCounter < AIRBOARDHALFWAYTIME) { //approach new place play.xPos = play.xOrg - AirboardCounter * 1.75; } play.shieldTime = 70 * 99; play.direction = 1; //right immobilize(play); } } } else { //dying==true if (SweptAwayIntoSpaceCounter != 0) { SweptAwayIntoSpaceCounter -= 1; if (SweptAwayIntoSpaceCounter == 20) { jjObjects[jjAddObject(OBJECT::EXPLOSION, play.xPos, play.yPos)].determineCurAnim(ANIM::AMMO, 82); } else if (SweptAwayIntoSpaceCounter > 20) { play.xPos += LastPlayerXSpeed; play.yPos += LastPlayerYSpeed; } } else if (KnockedIntoScreenCounter != 0) { if ((KnockedIntoScreenCounter += 0.2) >= 24.f) KnockedIntoScreenCounter = 0; } else { changeIncident(play); play.cameraUnfreeze(true); play.blink = 70; } immobilize(play); } //if (true) { const PerIncident@ incident = Incidents[WarpTargetID]; const bool safeToUnfreeze = !Dying && play.fly != FLIGHT::AIRBOARD && !WarpingToNextIncidentOnline; if (jjSubscreenWidth >= incident.WidthP) play.cameraFreeze(incident.CenterXP, safeToUnfreeze && jjSubscreenHeight < incident.HeightP, true, true); if (jjSubscreenHeight >= incident.HeightP) play.cameraFreeze(safeToUnfreeze && jjSubscreenWidth < incident.WidthP, incident.CenterYP, true, true); else if (safeToUnfreeze && jjSubscreenWidth < incident.WidthP) play.cameraUnfreeze(true); //} } } bool LoadedSuccessfulSound = false; void Next() { if (uint(WarpTargetID) < Incidents.length - 1) { const int TimeElapsedThisIncident = jjGameTicks - TimeStartedThisIncident; TimeElapsedStringThisIncident = StringifyTime(TimeElapsedThisIncident, Incidents[WarpTargetID].parTime); if (!Cheater) { if (TimeElapsedRecordSet = (Incidents[WarpTargetID].recordTimeElapsed > TimeElapsedThisIncident)) { Incidents[WarpTargetID].recordTimeElapsed = TimeElapsedThisIncident; Incidents[WarpTargetID].stringifyRecordTime(); } if (DeathsRecordSet = (Incidents[WarpTargetID].recordNumberOfDeaths > NumberOfDeathsThisIncident)) { Incidents[WarpTargetID].recordNumberOfDeaths = NumberOfDeathsThisIncident; } if (TimeElapsedRecordSet || DeathsRecordSet) { //at least one record set jjSTREAM records; for (uint i = 0; i < Incidents.length; ++i) { records.push(Incidents[i].recordNumberOfDeaths); records.push(Incidents[i].recordTimeElapsed); } records.save(jjHelpStrings[10]); } } else TimeElapsedRecordSet = DeathsRecordSet = false; SpendFramesCheckingIfPlayerIsStuck = 0; SweptAwayIntoSpaceCounter = 0; KnockedIntoScreenCounter = 0; Dying = false; if (jjGameConnection == GAME::LOCAL) Player.fly = FLIGHT::AIRBOARD; else { if (!LoadedSuccessfulSound) { jjSampleLoad(SOUND::COMMON_TELPORT1, "SUCCESSF.WAV"); LoadedSuccessfulSound = true; } WarpingToNextIncidentOnline = true; Player.warpToID(AssignWarpTargetID(WarpTargetID + 1)); LastIncidentCompleted = WarpTargetID; changeIncident(Player, false); } } else if (!GameOver) { GameOver = true; if (jjGameConnection == GAME::LOCAL) jjNxt(); else Player.cameraUnfreeze(); } } bool Cheater = false; bool onCheat(string &in cheat) { if (Player.fly == FLIGHT::AIRBOARD || Dying || GameOver || !GameBegun) return true; if (cheat == "jjnxt" || cheat == "jjnext" || cheat == "jjshield") { Cheater = true; Next(); } else if (cheat == "jjfly") { Cheater = true; Player.fly = (Player.fly == FLIGHT::NONE) ? FLIGHT::FLYCARROT : FLIGHT::NONE; } else if (cheat == "jjmorph") { Cheater = true; Player.morph(true, true); SetFur(); } else if (cheat == "jjk") { Die(); } else if (cheat == "jjammo" || cheat == "jjguns" || cheat == "jjgod") { for (int i = 1; i <= 4; ++i) if (!jjWeapons[i].infinite) Player.ammo[i] = 9; Cheater = true; } return !(cheat == "jjt" || cheat == "jjq"); } array Triggers(2, false); array TriggerTimers(2, -1); void setTriggerTo(uint8 triggerID, bool value) { if (Triggers[triggerID] != value) { Triggers[triggerID] = value; for (int i = SwitchBlocks.length - 1; i >= 0; --i) { const SwitchBlock@ block = SwitchBlocks[i]; if (block.triggerID == triggerID) block.doSwitch(); } TriggerTimers[triggerID] = 0; } } void PlayerJustRelocated() { switch (warpInsidePixel(Player.xPos, Player.yPos)) { case -2: case 3: SweepIntoSpace(true); break; case 1: case 2: KnockedIntoScreenCounter = 2.0; jjSample(Player.xPos, Player.yPos, SOUND::COMMON_SMASH); Die(); break; default: SpendFramesCheckingIfPlayerIsStuck = 2; break; } } void Switcher(jjOBJ@ obj) { if (jjPlayers[obj.creator].isLocal) { setTriggerTo(CurrentTriggerID, !Triggers[CurrentTriggerID]); SpendFramesCheckingIfPlayerIsStuck = 2; jjSamplePriority(SOUND::COMMON_CANSPS); } obj.delete(); } void Dasher(jjOBJ@ obj) { if (jjPlayers[obj.creator].isLocal) { array morphTiles; if (TimeSinceLastMorph > 140) { for (int i = jjObjectCount; --i != 0;) { const jjOBJ@ beam = jjObjects[i]; if (beam.behavior == MorphBeam) { morphTiles.insertLast(beam.var[0]); morphTiles.insertLast(beam.var[1]); } } } if (obj.ySpeed == -32) Player.yPos = (int(Player.yPos) & ~31) + 12; else Player.xPos = (int(Player.xPos) & ~31) + 16 + Player.direction * 4; const PerIncident@ incident = Incidents[WarpTargetID]; while (true) { int targetX = int(Player.xPos + obj.xSpeed); int targetY = int(Player.yPos + obj.ySpeed); if (targetX < incident.LeftOuterBoundP || targetX >= incident.RightOuterBoundP || targetY < incident.TopOuterBoundP) break; const int shouldWarp = warpInsidePixel(targetX, targetY); if (shouldWarp > 0) //wall break; float sparkX = Player.xPos, sparkY = Player.yPos; for (int i = 0; i < 8; ++i, sparkX += obj.xAcc, sparkY += obj.yAcc) { for (int j = -1; j <= 1; j += 2) { jjPARTICLE@ spark = jjAddParticle(PARTICLE::SPARK); if (spark !is null) { spark.xPos = sparkX; spark.yPos = sparkY; spark.xSpeed = obj.yAcc * j / 6; spark.ySpeed = obj.xAcc * j / 6; spark.spark.color = CurrentTriggerID == 0 ? 40 : 32; spark.spark.colorStop = spark.spark.color + 8; } } jjAddObject(OBJECT::EXPLOSION, sparkX, sparkY, 0,CREATOR::OBJECT, function(expl) { expl.playerHandling = HANDLING::EXPLOSION; expl.lightType = LIGHT::POINT2; if (++expl.age == 10) expl.delete(); }); } Player.xPos = targetX; Player.yPos = targetY; if (shouldWarp == -1) { //unsolid block of the right color targetX >>= 5; targetY >>= 5; jjTileSet(4, targetX, targetY, jjTileGet(4, targetX, targetY) + 1); } else { const int currTile = getCurrTileValue(targetX, targetY); for (uint i = 0; i < morphTiles.length; ++i) if (currTile == morphTiles[i]) { morphTiles.resize(0); Morph(); } } } PlayerJustRelocated(); jjSamplePriority(SOUND::COMMON_TELPORT2); } obj.delete(); } void Builder(jjOBJ@ obj) { if (jjPlayers[obj.creator].isLocal) { if (obj.state == STATE::START) { if (obj.ySpeed < 0) obj.xPos = (int(Player.xPos) & ~31) | 16; else obj.yPos = (int(Player.yPos) & ~31) | 16; obj.state = STATE::FLY; obj.var[0] = 40 - (CurrentTriggerID << 3); obj.var[1] = 39 - (CurrentTriggerID << 1); obj.var[2] = CurrentTriggerID; } obj.xPos += obj.xSpeed; obj.yPos += obj.ySpeed; const int xNext = int(obj.xPos + obj.xSpeed * 16), yNext = int(obj.yPos + obj.ySpeed * 16); if (jjMaskedPixel(xNext, yNext) && jjTileGet(4, xNext>>5, yNext>>5) != uint(obj.var[1] ^ 2)) { while (jjMaskedPixel(int(obj.xPos), int(obj.yPos))) { //in case a block sprung up around this while it was in flight obj.xPos -= obj.xSpeed * 32; obj.yPos -= obj.ySpeed * 32; } const PerIncident@ incident = Incidents[WarpTargetID]; if (!(obj.xPos < incident.LeftOuterBoundP || obj.xPos >= incident.RightOuterBoundP || obj.yPos < incident.TopOuterBoundP)) { const uint x = int(obj.xPos) >> 5, y = int(obj.yPos) >> 5; const uint16 oldTileID = jjTileGet(4, x,y); jjTileSet(4, x,y, obj.var[1]); if (!(oldTileID >= 36 && oldTileID <= 39)) SwitchBlocks.insertLast(SwitchBlock(x,y, oldTileID, obj.var[2])); SpendFramesCheckingIfPlayerIsStuck = 2; jjSamplePriority(SOUND::COMMON_PLOPKORK); } obj.delete(); } else jjDrawRotatedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame, obj.age -= obj.direction, 1,1, SPRITE::SINGLEHUE, obj.var[0]);//, 3); } else obj.delete(); } int GhostX = 0, GhostY = 0, GhostAngle; float GhostScale; int GhostTriggerID; void Ghoster(jjOBJ@ obj) { if (jjPlayers[obj.creator].isLocal) { if (GhostX == 0 && GhostY == 0) { const int potentialGhostX = (int(Player.xOrg) & ~31) - (int(Player.xPos) & ~31); const int potentialGhostY = (int(Player.yOrg) & ~31) - (int(Player.yPos) & ~31); //const float maxGhostDistance = 96; //if (abs(potentialGhostX) <= maxGhostDistance && abs(potentialGhostY) <= maxGhostDistance) { GhostX = potentialGhostX; GhostY = potentialGhostY; //} else { // jjSamplePriority(SOUND::COMMON_HORN1); // return; //} } //else { int targetX = int(Player.xPos), targetY = int(Player.yPos); if (warpInsidePixel(targetX, targetY) == -1) { //unsolid block of the right color targetX >>= 5; targetY >>= 5; jjTileSet(4, targetX, targetY, jjTileGet(4, targetX, targetY) + 1); } } Player.xPos += GhostX; //offsetPosition? Player.yPos += GhostY; GhostX = -GhostX; GhostY = -GhostY; if (GhostTriggerID != CurrentTriggerID) { CurrentTriggerID ^= 1; GhostTriggerID ^= 1; SetFur(); } PlayerJustRelocated(); GhostAngle = int(atan2(-GhostX, GhostY) * -512.0 * 0.318309886142228); GhostScale = sqrt(GhostX*GhostX+GhostY*GhostY) / 96.f; jjSamplePriority(SOUND::COMMON_STEAM); } obj.delete(); } const bool AllowLori = false; //jjIsTSF; uint TimeSinceLastMorph = 140; int getCurrTileValue(int x, int y) { return (x >> 5) + (y >> 5 << 16); } int getCharID(CHAR::Char curr) { if (curr == CHAR::JAZZ) return 0; if (curr == CHAR::SPAZ) return 1; return 2; } ///@Event 71=Morph Beam |+|Morph |Morph | |Direction:{Up,Down}1 void MorphBeam(jjOBJ@ obj) { if (obj.state == STATE::START) { obj.state = STATE::WAKE; obj.direction = jjParameterGet(int(obj.xPos / 32), int(obj.yPos / 32), 0, 1); obj.xPos = obj.xOrg = int(obj.xPos) & ~31; obj.yPos = obj.yOrg = int(obj.yPos) & ~31; obj.var[0] = getCurrTileValue(int(obj.xPos), int(obj.yPos)); if (obj.direction == 0) { //up obj.direction = -1; obj.yPos += 31; } else { //down } obj.var[1] = getCurrTileValue(int(obj.xPos), int(obj.yPos + 32 * obj.direction)); } else if (obj.state == STATE::DEACTIVATE) { obj.deactivate(); } else { const bool canMorph = TimeSinceLastMorph > 140 && Player.fly != FLIGHT::AIRBOARD && !Dying && !GameOver; if (canMorph) { jjPARTICLE@ part = jjAddParticle(PARTICLE::STAR); if (part !is null) { part.xPos = obj.xPos + (jjRandom() & 31); part.yPos = obj.yPos; part.xSpeed = 0; part.ySpeed = (jjRandom() & 3) * obj.direction; part.star.color = ((3 - getCharID(Player.charCurr)) << 3) + (jjRandom() & 7); part.star.angularSpeed = (jjRandom() & 31); part.star.frame = canMorph ? 0 : 1; } jjDrawRectangle(obj.xPos, obj.yPos, 32, 64 * obj.direction, 15, SPRITE::BLEND_NORMAL, uint8(abs(jjSin(jjRenderFrame << 4) * 64))); if (Player.currTile == obj.var[0] || Player.currTile == obj.var[1]) Morph(); } } } void Morph() { if (jjIsTSF) jjCharacters[CHAR::LORI].morphBoxCycle = AllowLori; Player.morph(true, true); SetFur(); Player.alreadyDoubleJumped = false; TimeSinceLastMorph = 0; //jjSample(Player.xPos, Player.yPos, SOUND::COMMON_GLASS2); jjSample(Player.xPos, Player.yPos, SOUND::COMMON_HOLYFLUT); for (uint i = 0; i < 1024; ++i) if (jjParticles[i].type == PARTICLE::STAR) jjParticles[i].type = PARTICLE::INACTIVE; } ///@Event 79=Recolor |+|Morph |Recolor | |Color:{Yellow,Blue}1 void Recolor(jjOBJ@ obj) { if (obj.state == STATE::START) { obj.state = STATE::WAKE; obj.var[0] = getCurrTileValue(int(obj.xPos), int(obj.yPos)); obj.var[2] = jjParameterGet(int(obj.xPos / 32), int(obj.yPos / 32), 0, 1); obj.var[3] = 82 + obj.var[2] * 80; obj.xPos = int(obj.xPos) & ~31; obj.yPos = int(obj.yPos) & ~31; } else if (obj.state == STATE::DEACTIVATE) { obj.deactivate(); } else { jjDrawTile(obj.xPos, obj.yPos, obj.var[3] + ((jjGameTicks >> 1) & 7)); if (Player.currTile == obj.var[0] && CurrentTriggerID != obj.var[2] && Player.fly != FLIGHT::AIRBOARD && !Dying && !GameOver) { CurrentTriggerID ^= 1; Player.morphTo(Player.charCurr, true); SetFur(); jjSample(Player.xPos, Player.yPos, SOUND::COMMON_SHLDOF3); } } } class Airboard : jjBEHAVIORINTERFACE { void onBehave(jjOBJ@ obj) { obj.behave(BEHAVIOR::AIRBOARD); } bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) { if (bullet is null) { if (!Dying || !player.isLocal) { if (player.isLocal) { if (Player.fly != FLIGHT::AIRBOARD && !GameOver) Next(); else return true; } obj.frameID = 0; obj.behavior = BEHAVIOR::EXPLOSION2; obj.playerHandling = HANDLING::EXPLOSION; } } return true; } } ///@Event 61=Ammo |+|Ammo |Ammo |Pickup |Weapon:{Switcher,Dasher,Builder,Ghoster}2 class Ammo : jjBEHAVIORINTERFACE { void onBehave(jjOBJ@ obj) { if (obj.state == STATE::START) { obj.var[0] = jjParameterGet(int(obj.xOrg) >> 5, int(obj.yOrg) >> 5, 0, 2) + 1; obj.determineCurAnim(ANIM::CUSTOM[2], obj.var[0] - 1); obj.state = STATE::FLOAT; } else if (obj.state == STATE::DEACTIVATE) obj.deactivate(); else { obj.playerHandling = jjParameterGet(int(obj.xOrg) >> 5, int(obj.yOrg) >> 5, 2, 1) == 0 ? HANDLING::PICKUP : HANDLING::PARTICLE; const jjANIMATION@ anim = jjAnimations[obj.curAnim]; if (obj.playerHandling == HANDLING::PICKUP) jjDrawSpriteFromCurFrame(obj.xPos, obj.yPos + jjSin((obj.objectID*8+jjGameTicks+int(obj.xPos+obj.yPos*256))*16) * 4, anim.firstFrame + ((jjGameTicks >> 2) % anim.frameCount), 1, SPRITE::SINGLEHUE, 128 - (CurrentTriggerID << 4)); } } bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) { if (bullet is null) { if (!Dying && player.isLocal && Player.fly != FLIGHT::AIRBOARD && !GameOver) { jjParameterSet(int(obj.xOrg) >> 5, int(obj.yOrg) >> 5, 2, 1, 1); const int ammoType = obj.var[0]; const int previousAmmoAmount = player.ammo[ammoType]; if ((previousAmmoAmount == 0 && jjAutoWeaponChange) || (player.ammo[WEAPON::CURRENT] == 0)) player.currWeapon = ammoType; player.ammo[ammoType] = previousAmmoAmount + 1; jjSample(obj.xPos, obj.yPos, SOUND::Sample(SOUND::FROG_FROG + ammoType - 1)); jjObjects[jjAddObject(OBJECT::EXPLOSION, obj.xPos, obj.yPos)].curAnim = obj.killAnim; } } return true; } } void TogglePalette() { Palettes[PaletteID].apply(); const uint8 fadeColorIntensity = 255 * (4-PaletteID) / 4; jjSetFadeColors(fadeColorIntensity,fadeColorIntensity,fadeColorIntensity); }