Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- 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>Yuh seem to have a heap o' sand in yore craw. I reckon a punk like yuh can take on the hard job as the new sheriff in town. Don't disappoint. <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>Damn yuh sure fast on the draw. You'll make an upstandin' hell-eating 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>

              
            
!

CSS

              
                * {
  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;
  }
}
              
            
!

JS

              
                $ ->
  $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("Justice served 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 craves the job of whippin' a squirt like you. He's a slick artist on the draw! Watch out"
      when 2
        @$messagePS.html "Name's Goldie Gaia. She runs the saloon even if she has to send you to the bone yard with your boots on."
      else
        @$messagePS.html "Pumpgun Ed ain't no man to monkey with. Yuh figure, this big fella lays yuh 'cross the hitch-rack an' fan yuh to a frazzle"
    @$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 = "You don't want to be too sudden with the trio. They gotta draw first."
        @noHonor++
      when 2
        noHonorMessage = "You're sure playin' with luck. Yuh best go an' rustle your blankets."
        @noHonor++
      else
        random = Math.floor(Math.random() * (4 - 1) ) + 1;
        switch random
          when 1
            noHonorMessage = "Mixin' it with some chance! An' this time o' day!"
          when 2
            noHonorMessage = "Happened kinda sudden, didn't yer?"
          else
            noHonorMessage = "What the devil! What fer kind of a thing shows no honour in a fast draw."   
    @$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()
              
            
!
999px

Console