Climb

Size
3,424 Kb
Views
22,264

How do I make an climb?

What is a climb? How do you make a climb? This script and codes were developed by Gregory Potdevin on 01 October 2022, Saturday.

Climb Previews

Climb - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Climb</title>
</head>
<body> <button onclick="refresh()">refresh</button>
Difficulty (0-1) : <input id="diff" value="0.2" min="0" max="1" onchange="refresh()" type="number" step="0.1">
<button onclick="randomFilling()">random filling</button>
<pre id="level"></pre> <script src="js/index.js"></script>
</body>
</html>

Climb - Script Codes JS Codes

var DIFFICULTY = 0.25 // 0-1
function flip(str){ function flipChar(c){ if (c === 'L') return 'R' else if (c === 'R') return 'L' return c } var arr = [] for(var i=str.length-1; i>=0; i--){ arr.push(flipChar(str[i])) } return arr.join('')
}
function lerp(r, min, max) { return min + r*(max-min)
}
function randInt(min, max){ return min + Math.floor(Math.random()*(1+max-min))
}
function randFloat(min, max, round){ var v = lerp(Math.random(), min, max) if (round) v = Math.floor(v*100)/100 return v
}
function randBool(){ return Math.random() < 0.5
}
function makePattern(pattern, size, doFlip){ if (!size) size = 1 size = ("" + size).substring(0, 4) // manual trim ^^ if (doFlip) pattern = flip(pattern) return ' {pattern: "' + pattern + '", size: ' + size + '},\n'
}
function stomps(length){ var pattern = "" pattern += makePattern("1 1") var left = randBool() for(var i=0; i<length; i++){ var baseSize = lerp(DIFFICULTY, 1, 0.7) var size = randFloat(baseSize-0.1, randFloat+0.1) if (Math.random() < 0.2) { pattern += makePattern("1 * 1", size) left = !left } else { if (Math.random() < 0.7) left = !left if (left) pattern += makePattern("1 L 1", size) else pattern += makePattern("1 R 1", size) } } return pattern
}
function multiSpikes(){ var pattern = "" pattern += makePattern("1 1") pattern += makePattern("X 1 1 X", 0.2) pattern += makePattern("1 1X1 1") pattern += makePattern("X 1 1 X", 0.2) pattern += makePattern("1 1") return pattern
}
function soloStar(){ var pattern = "" pattern += makePattern("1 1") pattern += makePattern("X * X", 0.2) pattern += makePattern("1 1") return pattern
}
function horizontalBars(length){ var pattern = "" var h = DIFFICULTY < 0.5 ? 'H' : 'h' var isFlip = randBool() pattern += makePattern("1 1") for(var i=0; i<length; i++){ var isFake = Math.random() < 0.3 if (isFake){ pattern += makePattern("1 " + h + " 2", 0.4, isFlip) pattern += makePattern("1 2", 1, isFlip) } else { pattern += makePattern("1 " + h + " 2", 0.4, isFlip) pattern += makePattern("2 1", 1, isFlip) isFlip = !isFlip } } return pattern
}
function sideSpikes(length){ var pattern = "" pattern += makePattern("1 1") var size = 0.01*Math.floor(lerp(DIFFICULTY, 0.6, 0.35)*100) var isFlip = randBool() for(var i=0; i<length; i++){ var len = randInt(1, 3) for(var j=0; j<len; j++){ pattern += makePattern("1 5", size, isFlip) } isFlip = !isFlip } return pattern
}
function middlePlatforms(length){ var pattern = "" pattern += makePattern("1 1") var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.1, 0.7)*100) var isFlip = randBool() var other = 0 function col(n){ return 2 + ((other+n)%3) } pattern += makePattern(col(0) + " 1", size, isFlip) for(var i=0; i<length; i++){ pattern += makePattern(col(0) + " 1 " + col(1), size, isFlip) pattern += makePattern("1 " + col(1), size, isFlip) pattern += makePattern(col(2) + " 1 " + col(1), size, isFlip) pattern += makePattern(col(2) + " 1", size, isFlip) other += 2 } return pattern
}
function mediumPassage(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.5)*100) var isFlip = randBool() pattern += makePattern("1 1", 1, isFlip) pattern += makePattern(" 1 1 ", 1, isFlip) for(var i=0; i<length; i++){ var n = randInt(2, 5) isFlip = !isFlip pattern += makePattern(" " + n + " 1 ", size, isFlip) } pattern += makePattern("1 1", 1, isFlip) return pattern
}
function smallPassage(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.5)*100) var isFlip = randBool() pattern += makePattern("1 1", 1, isFlip) pattern += makePattern(" 1 1 ", 1, isFlip) pattern += makePattern(" 1 1 ", size, isFlip) for(var i=0; i<length; i++){ var n = randInt(2, 5) isFlip = !isFlip pattern += makePattern(" " + n + " 1 ", size, isFlip) } pattern += makePattern(" 1 1 ", 1, isFlip) pattern += makePattern("1 1", 1, isFlip) return pattern
}
function middleSpikes(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.5)*100) var isFlip = randBool() pattern += makePattern("1 2", 1, isFlip) for(var i=0; i<length; i++){ var passAround = randBool() if (passAround){ pattern += makePattern("1 X 1", 0.4, isFlip) pattern += makePattern("2 X 1", 0.4, isFlip) pattern += makePattern("2 1", 1, isFlip) } else { pattern += makePattern("1 X 2", 0.7, isFlip) pattern += makePattern("2 X 1", 0.7, isFlip) pattern += makePattern("2 1", 1, isFlip) } isFlip = !isFlip } return pattern
}
function alternateColors(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.6)*100) var isFlip = randBool() for(var i=0; i<length; i++){ var tmpSize = size + randFloat(-0.2, 0.2, true) pattern += makePattern("1 " + randInt(2, 4), tmpSize, isFlip) if (Math.random() < 0.75) isFlip = !isFlip } return pattern
}
function alternateSpikes(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.6)*100) var isFlip = randBool() for(var i=0; i<length; i++){ var tmpSize = size + randFloat(-0.1, 0.2, true) pattern += makePattern("1 " + 5, tmpSize, isFlip) if (Math.random() < 0.75) isFlip = !isFlip } return pattern
}
function alternateHoles(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.6)*100) var isFlip = randBool() for(var i=0; i<length; i++){ var tmpSize = size + randFloat(-0.1, 0.2, true) pattern += makePattern("1 ", tmpSize, isFlip) if (Math.random() < 0.75) isFlip = !isFlip } return pattern
}
function alternateAll(length){ var pattern = "" var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.0, 0.6)*100) var isFlip = randBool() for(var i=0; i<length; i++){ var tmpSize = size + randFloat(-0.1, 0.2, true) var choices = ["2", "3", "4", "5", " ", "+", "X"] var c = choices[Math.floor(Math.random()*choices.length)] pattern += makePattern("1 " + c, tmpSize, isFlip) if (Math.random() < 0.75) isFlip = !isFlip } return pattern
}
function circles(length){ var pattern = "" var isFlip = randBool() pattern += makePattern("1 ", 1, isFlip) for(var i=0; i<length; i++){ var version = randInt(0, 3) if (DIFFICULTY < 0.5) version = 3 if (version == 0){ // Nothing to do pattern += makePattern("1 U 1", 1, isFlip) pattern += makePattern("1 1", 1, isFlip) } else if (version == 1){ // FAKE Nothing to do pattern += makePattern("1 C 1", 1, isFlip) pattern += makePattern("1 ", 1, isFlip) } else if (version >= 2){ // CHANGE !! pattern += makePattern("1 C 1", 1, isFlip) pattern += makePattern(" 1", 1, isFlip) isFlip = !isFlip } } return pattern
}
function simpleHole(){ var pattern = "" pattern += makePattern("1 1", 1) pattern += makePattern(" ", 0.2) pattern += makePattern("1 1", 1) return pattern
}
function sawSlalom(){ var length = lerp(DIFFICULTY, 3, 7) var size = lerp(DIFFICULTY, 1.2, 1) var pattern = " // slalom\n" pattern += makePattern("1 1", 1) var isFlip = randBool() for(var i=0; i<length; i++){ var tmpSize = size + randFloat(-0.1, 0.1, true) var len = Math.floor(lerp(DIFFICULTY, 1, 3)) + randInt(0, 2) var p = "5" for(var j=0; j<5; j++) p += j < len ? "+" : " "; p += "1" pattern += makePattern(p, tmpSize, isFlip) isFlip = !isFlip } return pattern
}
function sawField(){ var pattern = "" pattern += makePattern("1 1") var length = lerp(DIFFICULTY, 6, 15) * randFloat(1, 1.5) var size = 0.01*Math.floor(lerp(DIFFICULTY, 1.25, 1.1)*100) var changeProba = lerp(DIFFICULTY, 0.3, 0.8) var isFlip = randBool() for(var i=0; i<length; i++){ var p = (i%2) ? '+ + +' : ' + + ' if (Math.random() < changeProba){ pattern += makePattern(" " + p + "1", size, isFlip) isFlip = !isFlip } else { pattern += makePattern("1" + p + "1", size, isFlip) } } return pattern
}
function randomLevel(){ var n = lerp(DIFFICULTY, 3, 5) + randInt(0, 2); var totalAngle = 0 var level = ""; var turnCnt = 0 var prevAngle = 0 level += " // XXX - \n" level += " { speed: 1, size: 1, obstacles: [\n" level += makePattern("1 1", 1) for(var i=0; i<n; i++){ if ((i > 0) && (Math.random() < 0.5)){ level += makePattern(" o ", 0.2) } var rand = randInt(0, 16) if (rand == 0){ level += stomps(randInt(2, 4)) } else if (rand == 1){ level += horizontalBars(randInt(2, 4)) } else if (rand == 2){ level += sideSpikes(randInt(2, 4)) } else if (rand == 3){ level += middlePlatforms(randInt(1, 2)) } else if (rand == 4){ level += mediumPassage(randInt(2, 5)) } else if (rand == 5){ level += smallPassage(randInt(2, 5)) } else if (rand == 6){ level += middleSpikes(randInt(1, 3)) } else if (rand == 7){ level += multiSpikes() } else if (rand == 8){ level += alternateSpikes(randInt(3, lerp(DIFFICULTY, 3, 6))) } else if (rand == 9) { level += alternateColors(randInt(3, lerp(DIFFICULTY, 3, 6))) } else if (rand == 10) { level += alternateHoles(randInt(3, lerp(DIFFICULTY, 3, 6))) } else if (rand == 11) { level += circles(lerp(DIFFICULTY, 1, 4)) } else if (rand == 12) { level += simpleHole() } else if (rand == 13) { level += sawSlalom() } else if (rand == 14) { level += sawField() } else { level += alternateAll(randInt(4, lerp(DIFFICULTY, 4, 8))) } if (Math.random() > DIFFICULTY && Math.random() < 0.5){ level += "\n" + soloStar() } level += "\n" } level += makePattern("1 1", 1) level += " ]},\n" return level
}
DIFFICULTY = Number(document.getElementById("diff").value)
var el = document.getElementById("level");
el.innerHTML = randomLevel()
function refresh(){ var el = document.getElementById("level"); DIFFICULTY = Number(document.getElementById("diff").value) el.innerHTML = randomLevel()
}
function randomFilling(){ var el = document.getElementById("level"); DIFFICULTY = Number(document.getElementById("diff").value) el.innerHTML = alternateAll(20)
}
Climb - Script Codes
Climb - Script Codes
Home Page Home
Developer Gregory Potdevin
Username GregoryPotdevin
Uploaded October 01, 2022
Rating 3
Size 3,424 Kb
Views 22,264
Do you need developer help for Climb?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Gregory Potdevin (GregoryPotdevin) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!