HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!-- Art based on https://www.instagram.com/p/BsvHvCsnegd/ -->
<div class="screen">
<div class="cloud cloud--2"></div>
<div class="cloud cloud--1"></div>
<div class="js-opening opening-screen">
<img src="https://gilleskurt.com/thefearsomethree/ostitle.png" alt="" class="opening-screen__title">
<img src="https://gilleskurt.com/thefearsomethree/osfigures.png" alt="" class="opening-screen__figures">
<button class="js-start opening-screen__start-button"></button>
<div class="js-message message-box message-box--full is-hidden">
<p>Looks like you've got some real guts, partner. I reckon you might just be tough enough to be the new sheriff in town. Don’t go provin’ me wrong now!<button type="button" class="js-continue continue-button">Continue...</button></p>
</div>
</div>
<div class="js-play is-hidden">
<div class="js-sheriff sheriff"></div>
<div class="js-opponent opponent opponent--1"></div>
<div class="message-box message-box--half">
<button type="button" class="js-draw shoot-button is-hidden">Shoot!</button>
<span class="js-result"></span>
<span class="js-message"></span>
<button type="button" class="js-result-continue continue-button is-hidden">Continue...</button>
<button type="button" class="js-duel continue-button is-hidden">Continue...</button>
</div>
</div>
<div class="js-outro is-hidden">
<div class="message-box message-box--full">
<span>Dang, you're quick on the draw! You'll make one tough, no-nonsense sheriff!</span>
<span class="js-total-time"></span>
<button type="button" class="js-save-and-quit continue-button">Save and Quit...</button>
</div>
</div>
</div>
* {
box-sizing: border-box;
font-family: 'VT323', monospace!important;
font-size: 21px!important;
margin: 0;
padding: 0;
}
$dimensionXY: 500px;
$small: 7px;
$medium: 15px;
$large: 30px;
$xlarge: 60px;
$yellow: #F59600;
$opponent1: 0;
$opponent2: -206px;
$opponent3: -412px;
$sheriff: -618px;
$standing: 0;
$armed: -206px;
$shooting: -412px;
$dead: -618px;
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.screen {
background-image: url("https://gilleskurt.com/thefearsomethree/bgprops.png"), url("https://gilleskurt.com/thefearsomethree/bg.png");
height: $dimensionXY;
overflow: hidden;
position: relative;
width: $dimensionXY;
}
@keyframes cloudToRight {
to {
transform: translateX(700px);
}
}
.cloud {
background-image: url("https://gilleskurt.com/thefearsomethree/clouds.png");
height: 200px;
position: absolute;
width: 200px;
}
.cloud--1 {
animation: cloudToRight 120s linear infinite;
transform: translateX(-110px);
}
.cloud--2 {
animation: cloudToRight 200s 10s linear infinite;
transform: translateX(-200px);
background-position-x: 250px;
}
@keyframes blink {
0%, 30% {
opacity: 0;
}
32%, 100% {
opacity: 1;
}
}
@mixin button {
background-color: transparent;
border: 0;
color: $yellow;
&:hover {
cursor: pointer;
}
}
.opening-screen {}
.opening-screen__start-button {
@include button;
animation: blink 1.5s 3.5s linear infinite;
background-image: url("https://gilleskurt.com/thefearsomethree/press-start.png");
height: $dimensionXY;
opacity: 0;
width: $dimensionXY;
}
@keyframes topDownFadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
.opening-screen__title {
animation: topDownFadeIn 1.5s 1s ease forwards;
opacity: 0;
position: absolute;
transform: translateY(-20%);
}
.opening-screen__figures {
animation: topDownFadeIn 2s 1s ease forwards;
opacity: 0;
position: absolute;
transform: translateY(-5%);
}
@keyframes moveUp {
to {
transform: translateY(-5%);
}
}
.has-message {
.opening-screen__figures,
.opening-screen__title {
animation: moveUp 0.4s ease forwards;
opacity: 1;
transform: translateY(0);
}
}
.continue-button {
@include button;
&::after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
}
.game-over,
.game-end{
.message-box {
background-color: transparent;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
bottom: 50%;
left: 50%;
text-align: center;
transform: translate(-50%, 50%);
}
}
.opening-screen {
.message-box {
transition: opacity 0.4s ease, transform 0.4s ease;
}
}
.message-box {
background-color: rgba(151, 106, 68, 0.9);
border-radius: $small;
padding: $medium;
position: absolute;
bottom: $small;
transform: translateY(0);
opacity: 1;
&.is-hidden {
opacity: 0;
transform: translateY(20%);
}
}
.message-box--full {
left: 7px;
width: calc(100% - 15px);
}
.message-box--half {
right: 7px;
width: calc(100% - 150px);
}
@keyframes moveIn {
to {
opacity: 1;
transform: translateX(0);
}
}
@keyframes goner {
to {
opacity: 1;
transform: rotate(-30deg) translate(-100%);
}
}
.sheriff {
animation: moveIn 1s ease forwards;
background-image: url("https://gilleskurt.com/thefearsomethree/character-spritesheet.png");
background-position-x: $standing;
background-position-y: $sheriff;
height: 200px;
opacity: 0;
position: absolute;
left: 0;
bottom: 0;
width: 200px;
transform: translateX(-10%);
z-index: 2;
&.is-armed {
background-position-x: $armed;
}
&.is-dead {
background-position-x: $dead;
}
&.is-gone {
transform: translateX(0);
animation: goner 1s ease forwards;
}
&.is-shooting {
background-position-x: $shooting;
}
}
.opponent {
animation: moveIn 1s ease forwards;
background-image: url("https://gilleskurt.com/thefearsomethree/character-spritesheet.png");
background-position-x: $standing;
height: 200px;
opacity: 0;
position: absolute;
right: 100px;
bottom: 70px;
width: 200px;
transform: translateX(10%);
&.is-armed {
background-position-x: $armed;
}
&.is-dead {
background-position-x: $dead;
}
&.is-shooting {
background-position-x: $shooting;
}
}
.opponent--1 {
background-position-y: $opponent1;
}
.opponent--2 {
background-position-y: $opponent2;
}
.opponent--3 {
background-position-y: $opponent3;
}
.is-hidden {
display: none;
}
.shoot-button {
@include button;
text-align: center;
width: 100%;
&::after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
}
$ ->
$document = $ (document)
@$body = $document.find "body"
# opening screen -----------------------------
@$openingScreen = $document.find ".js-opening"
@$playScreen = $document.find ".js-play"
@$startButtonOS = @$openingScreen.find ".js-start"
@$messageOS = @$openingScreen.find ".js-message"
startButtonOS = =>
@$startButtonOS.addClass "is-hidden"
@$messageOS.removeClass "is-hidden"
@$openingScreen.addClass "has-message"
@$startButtonOS.on "click", => startButtonOS()
@$continueButtonOS = @$openingScreen.find ".js-continue"
@$continueButtonOS.on "click", =>
@$openingScreen.addClass "is-hidden"
@$playScreen.removeClass "is-hidden"
@$openingScreen.removeClass "has-message"
showDuelInfo()
# play screen -----------------------------
@$messagePS = @$playScreen.find ".js-message"
@$duelButton = $document.find ".js-duel"
@$drawButton = $document.find ".js-draw"
@$sheriff = $document.find ".js-sheriff"
@$opponent = $document.find ".js-opponent"
@$resultPS = $document.find ".js-result"
@result
@$timer
@dueling = false
@level = 1
@gameOver = false
@noHonor = 1
@totalTime = 0
restart = =>
# completely restarts game
@level = 1
@noHonor = 0
@dueling = false
@gameOver = false
@totalTime = 0
resetMessages()
@$outroScreen.addClass "is-hidden"
@$playScreen.addClass "is-hidden"
@$openingScreen.removeClass "is-hidden"
@$startButtonOS.removeClass "is-hidden"
@$messageOS.addClass "is-hidden"
@$body.removeClass "game-over"
@$body.removeClass "game-end"
@$sheriff.removeClass "is-dead"
@$sheriff.removeClass "is-gone"
death = =>
@totalTime = 0
@$opponent.addClass "is-shooting"
@$sheriff.addClass "is-dead"
setTimeout (=>
@$sheriff.addClass "is-gone"
@$opponent.removeClass "is-shooting"
@$resultPS.html "Game Over"
@$duelButton.removeClass "is-hidden"
@level = 1
@gameOver = true
@$body.addClass "game-over"
return
), 200
win = =>
@totalTime = @totalTime + @result
@$sheriff.addClass "is-shooting"
@$opponent.addClass "is-dead"
@$resultPS.html("Law and order served up hot in " + @result.toFixed(3) + " seconds")
@level++
@$resultContinue.removeClass "is-hidden"
setTimeout (=>
@$sheriff.removeClass "is-shooting"
@$sheriff.addClass "is-armed"
return
), 200
setTimeout (=>
@$sheriff.removeClass "is-armed"
return
), 1000
@$resultContinue = $document.find ".js-result-continue"
@$resultContinue .on "click", =>
@$resultContinue.addClass "is-hidden"
resetMessages()
# if won the game
if @level == 4
enterOutro()
# continue as normal
else
showDuelInfo()
reset = =>
# stops game if no reaction
death()
clearInterval @$timer
@$duelButton.removeClass "is-hidden"
@$drawButton.addClass "is-hidden"
showDuelInfo = =>
@$opponent.removeClass "is-armed"
@$opponent.removeClass "is-dead"
@$opponent.removeClass "opponent--1"
@$opponent.removeClass "opponent--2"
@$opponent.removeClass "opponent--3"
@$opponent.addClass "opponent--" + @level
switch @level
when 3
@$messagePS.html "Big Gilly Boulder? He’s the fastest draw this side of the desert, and he’s itchin’ to prove it."
when 2
@$messagePS.html "Goldie Gaia runs the saloon, and she ain’t afraid to send you to Boot Hill if you step outta line."
else
@$messagePS.html "Pumpgun Ed ain't someone to mess with. This big fella could flatten you faster than a tumbleweed in a twister."
@$duelButton.removeClass "is-hidden"
resetMessages = =>
@$messagePS.html ""
@$resultPS.html ""
enterDuelMode = =>
@$duelButton.addClass "is-hidden"
@$drawButton.removeClass "is-hidden"
resetMessages()
@delay = (Math.floor(Math.random()*(6 -1)+1)) * 1000
# start duel
@$duel = setTimeout ( =>
@dueling = true
# style start
@$opponent.addClass "is-armed"
# start timer
startTime = Date.now()
@$timer = setInterval((=>
elapsedTime = Date.now() - startTime
# announce result
@result = (elapsedTime / 1000)
if @result > 2
reset()
return
), 10)
), @delay
noHonor = =>
# if clicked to early
clearInterval @$duel
@$duelButton.removeClass "is-hidden"
@$drawButton.addClass "is-hidden"
switch @noHonor
when 1
noHonorMessage = "Wait for your opponent to draw first. No shootin’ early, or you’ll get called a no-good cheater."
@noHonor++
when 2
noHonorMessage = "Click “Shoot!” as soon as they make their move. The faster, the better!"
@noHonor++
else
random = Math.floor(Math.random() * (4 - 1) ) + 1;
switch random
when 1
noHonorMessage = "Jumpin’ the gun won’t win ya respect, just a bad reputation. Try again!"
when 2
noHonorMessage = "Draw too early? That’s dishonorable, partner! Try again."
else
noHonorMessage = "Hold your horses! You gotta let ‘em draw first, or it ain't a real duel."
@$resultPS.html noHonorMessage
# Duel button
@$duelButton.on "click", =>
if @gameOver
restart()
else
enterDuelMode()
# Draw button
@$drawButton.on "click", =>
if @dueling
# good draw
clearInterval @$timer
@$opponent.removeClass "is-armed"
@$drawButton.addClass "is-hidden"
switch @level
when 3
if @result < 0.33
win()
else
death()
when 2
if @result < 0.4
win()
else
death()
else
if @result < 2
win()
else
death()
else
# failed draw
noHonor()
@dueling = false
# Outro screen -----------------------------
@$outroScreen = $document.find ".js-outro"
@$saveAndQuitButton = @$outroScreen.find ".js-save-and-quit"
@$totalTime = @$outroScreen.find ".js-total-time"
enterOutro = =>
@$totalTime.html "Total time: " + @totalTime.toFixed(3) + "seconds"
@$playScreen.addClass "is-hidden"
@$outroScreen.removeClass "is-hidden"
@$body.addClass "game-end"
@$totalTime = 0
@$saveAndQuitButton .on "click", =>
restart()
Also see: Tab Triggers