IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Vous êtes nouveau sur Developpez.com ? Créez votre compte ou connectez-vous afin de pouvoir participer !

Vous devez avoir un compte Developpez.com et être connecté pour pouvoir participer aux discussions.

Vous n'avez pas encore de compte Developpez.com ? Créez-en un en quelques instants, c'est entièrement gratuit !

Si vous disposez déjà d'un compte et qu'il est bien activé, connectez-vous à l'aide du formulaire ci-dessous.

Identifiez-vous
Identifiant
Mot de passe
Mot de passe oublié ?
Créer un compte

L'inscription est gratuite et ne vous prendra que quelques instants !

Je m'inscris !

Le CSS est-il un langage de programmation ? La question divise les développeurs
Surtout au vu de la qualité de certains jeux vidéo mis sur pied en s'appuyant uniquement sur le CSS

Le , par Patrick Ruiz

7PARTAGES

26  0 
Le CSS est-il un langage de programmation ? La question divise les développeurs
Surtout au vu de la qualité de certains jeux vidéo mis sur pied en s’appuyant uniquement sur le CSS

Le langage CSS (en anglais Cascading Style Sheets, qu'on peut traduire par feuilles de style en cascade) sert d’habitude à gérer l'aspect visuel d'une page web. En d'autres termes, le langage CSS gère la présentation d'une page web : la couleur du texte, l'utilisation de telle ou telle police, les images ou couleurs d'arrière-plan, les espaces et marges des différents éléments, le positionnement des éléments, etc. Ce dernier est donc d’abord connu comme un langage pour le web. Certains intervenants de la filière sont néanmoins d’avis que c’est limiter le CSS qui est un langage de programmation à part entière. Et pour cause : il existe toute une niche de jeux vidéo mis sur pied en s’appuyant uniquement sur le CSS.



« CSS est un langage de feuille de style personnalisé et ne fonctionne pas comme un langage de programmation. CSS définit l'apparence du balisage plutôt que la manière de mettre sur pied une application », soulignent des intervenants de la filière d’avis que le CSS n’est pas un langage de programmation à part entière.



C’est un positionnement sujet à contradiction quand on sait qu’un langage de programmation peut être défini de façon simple comme un code de communication entre un humain et une machine. L’humain s’appuie sur le code pour donner des instructions à la machine qui les exécute. Et la disponibilité de jeux vidéo comme The Mine, mis sur pied en s’appuyant uniquement sur le CSS, l’illustre. Les trois grandes étapes de la programmation informatique sont respectées : l’analyse qui décrit le problème rencontré de façon claire ; l’algorithme qui décrit la solution au problème sous une forme très simple compréhensible par tous ; le programme qui traduit l’algorithme sous une forme numérique compréhensible par un appareil numérique.


« La logique sous-jacente est en fait relativement simple et utilise une technique vieille de plus de 7 ans. En cliquant sur une flèche (dans ce cas un label), il vérifie l'entrée pertinente et en utilisant le pseudo-sélecteur : checked, nous pouvons parcourir le DOM le nombre correct d'itérations et déplacer l'ensemble de la fenêtre de visualisation d'un "segment" entier. Les ascenseurs fonctionnent de la même manière, sauf que lorsque nous cliquons vers le bas, nous vérifions le segment du dessous.

En ce qui concerne la logique de jeu, nous utilisons à nouveau le même concept. La pioche, par exemple, est une étiquette pour une case à cocher. Lorsque nous cliquons dessus, la case est cochée, puis, lorsque nous cliquons sur le rocher, nous demandons à css de vérifier si les entrées du rocher et de la pioche sont toutes deux cochées », indique l’auteur de The Mine à propos de certains aspects algorithmiques du jeu dont le code source est disponible.

[CODE=CSS]-# Game grid variablesb
-# Make sure these are reflected in the SASS
- rows = 4;
- columns = 12;
- tilesPerSegment = 3;
- tilePerSegmentVertical = 7;
- hasIntro = true;
- hasLoader = true;
-# Game
.game
-# Loader
- if(hasLoader == true)
.game_loader
.game_loader__inner
.logo
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/mineLogo.gif'}
.subtitle
%h1 A no JS Adventure game
.bar
.bar_inner
%span Loading checkboxes...
-# Intro
- if(hasIntro == true)
.game_intro
%input#intro-1{:class => 'dialogue', :type => 'radio', :name => 'intro', :checked => 'checked'}
.dialogue
Ahhhhhhh!!
%label{:for => 'intro-2'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%input#intro-2{:class => 'dialogue', :type => 'radio', :name => 'intro'}
.dialogue
The floor just collapsed under me
%label{:for => 'intro-3'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%input#intro-3{:class => 'dialogue', :type => 'radio', :name => 'intro'}
.dialogue
Geez it sure is dark in here
%label{:for => 'intro-4'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%input#intro-4{:class => 'dialogue', :type => 'radio', :name => 'intro'}
.dialogue
Let me light my torch...
%label{:for => 'intro-5'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%input#intro-5{:class => 'dialogue', :type => 'radio', :name => 'intro'}
.dialogue.end
Better. Need to find a way out.
%input#intro-6{:class => 'dialogue', :type => 'radio', :name => 'intro'}
.overlay

-# Padlock game
%input#interactiveObject--lock{:type=> 'checkbox'}
.padlock
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/padlockBig.png'}
-(1..3).each do |col|
-(1..9).each do |i|
- if(i == 9)
%input{:type=> 'checkbox', 'value' => i, :id => "padlock#{col}-#{i}", :checked => 'checked'}
%span{:id => "span-#{col}"} #{10 - i}
- else
%input{:type=> 'checkbox', 'value' => i, :id => "padlock#{col}-#{i}"}
%span{:id => "span-#{col}"} #{10 - i}
%label.check{:for => 'interactiveObject--lock'} check

-# Game items

%input#interactiveObject1{:type => 'radio', 'data-reference' => '1', 'data-debug' => "Empty box 1"}
%input#interactiveObject2{:type => 'radio', 'data-reference' => '2', 'data-debug' => "Pickaxe"}
%input#interactiveObject3{:type => 'checkbox', 'data-reference' => '3', 'data-debug' => "Boulder"}
%input#interactiveObject4{:type => 'radio', 'data-reference' => '4', 'data-debug' => "Dynamite plunger"}
%input#interactiveObject5{:type => 'checkbox', 'data-reference' => '5', 'data-debug' => "Dynamite door"}
%input#interactiveObject6{:type => 'radio', 'data-reference' => '6', 'data-debug' => "Planks"}
%input#interactiveObject7{:type => 'checkbox', 'data-reference' => '7', 'data-debug' => "Plank gap"}
%input#interactiveObject8{:type => 'radio', 'data-reference' => '8', 'data-debug' => "Note 1"}
%input#interactiveObject9{:type => 'radio', 'data-reference' => '9', 'data-debug' => "Note 2"}
%input#interactiveObject10{:type => 'radio', 'data-reference' => '10', 'data-debug' => "Note 3"}
%input#interactiveObject11{:type => 'radio', 'data-reference' => '11', 'data-debug' => "Lock door"}
%input#interactiveObject12{:type => 'radio', 'data-reference' => '12', 'data-debug' => "Handle"}
%input#interactiveObject13{:type => 'checkbox', 'data-reference' => '13', 'data-debug' => "Cog"}
%input#interactiveObject14{:type => 'checkbox', 'data-reference' => '14', 'data-debug' => "Waterfall"}
%input#interactiveObject15{:type => 'radio', 'data-reference' => '15', 'data-debug' => "Dynamite"}
%input#interactiveObject16{:type => 'radio', 'data-reference' => '16', 'data-debug' => "Fuses"}
%input#interactiveObject17{:type => 'checkbox', 'data-reference' => '17', 'data-debug' => "End door"}
%input#interactiveObject18{:type => 'radio', 'data-reference' => '18', 'data-debug' => "Empty box 2"}
%input#interactiveObject19{:type => 'radio', 'data-reference' => '19', 'data-debug' => "Empty box 3"}
%input#interactiveObject20{:type => 'radio', 'data-reference' => '20', 'data-debug' => "Empty box 4"}
%input#interactiveObject21{:type => 'radio', 'data-reference' => '21', 'data-debug' => "Empty box 5"}
%input#interactiveObject22{:type => 'radio', 'data-reference' => '22', 'data-debug' => "Empty box 6"}

-# Checkboxes for movement
-(1..rows).each do |row|
-(1..columns).each do |index|
- if(row == 1 && index == 2)
%input{:id => "indexRow#{row}-#{index}", :type => "radio", :name => "trigger", :checked => 'checked'}
- else
%input{:id => "indexRow#{row}-#{index}", :type => "radio", :name => "trigger"}

-# Game character
.game_character

-# Game intermediates
.game_key

-# Game segments
.viewport
%img.level{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/tilemaps.png'}
-(1..rows).each do |row|
-(1..columns).each do |index|
.game_segment
.drip_container
-(1..4).each do
.drip
.tiles
-(1..tilesPerSegment * tilePerSegmentVertical).each do |tile|
-if (row == 1 && index == 3 && tile == 15)
.tile
%label{:for => 'interactiveObject1', 'data-reference' => '1'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-24.png'}
.response
Nothing useful in here
-if (row == 1 && index == 12 && tile == 14)
.tile
%label{:for => 'interactiveObject2', 'data-reference' => '2'}
%img.object{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_035.png'}
.response
A pickaxe. This should come in handy
-if (row == 1 && index == 7 && tile == 15)
.tile
%label{:for => 'interactiveObject3', 'data-reference' => '3'}
%img.forced{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_062.png'}
.responseSuccess
Ha! That got it
.forcedResponse
I need a tool to get past this
%label{:for => 'interactiveObject3'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 1 && index == 8 && tile == 15)
.tile
%label{:for => 'interactiveObject4', 'data-reference' => '4'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_166.png'}
.response
That seemed to do something...
-if (row == 3 && index == 7 && tile == 13)
.tile.beam
%label{:for => 'interactiveObject5', 'data-reference' => '5'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/beam.gif'}
.responseSuccess
door gone
.forcedResponse
Something must blow this up
%label{:for => 'interactiveObject5'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 2 && index == 6 && tile == 15)
.tile
%label{:for => 'interactiveObject6', 'data-reference' => '6'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
A Plank of wood
-if (row == 3 && index == 5 && tile == 13)
.tile
%label{:for => 'interactiveObject7', 'data-reference' => '7'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_169.png'}
.responseSuccess
planks on
.forcedResponse
CSS won't let me jump this
%label{:for => 'interactiveObject7'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 1 && index == 6 && tile == 13)
.tile
%label{:for => 'interactiveObject8', 'data-reference' => '8'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
A strange note
-if (row == 1 && index == 10 && tile == 13)
.tile
%label{:for => 'interactiveObject9', 'data-reference' => '9'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-24.png'}
.response
A strange note
-if (row == 3 && index == 5 && tile == 14)
.tile
%label{:for => 'interactiveObject10', 'data-reference' => '10'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-24.png'}
.response
A strange note
-if (row == 3 && index == 4 && tile == 13)
.tile.door
%label{:for => 'interactiveObject--lock', 'data-reference' => '11'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/doorLocked.png'}
.response
A locked door
-if (row == 3 && index == 2 && tile == 13)
.tile
%label{:for => 'interactiveObject12', 'data-reference' => '12'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
Cog handle
-if (row == 4 && index == 10 && tile == 13)
.tile
%label{:for => 'interactiveObject13', 'data-reference' => '13'}
%img.forced{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_148.png'}
.responseSuccess
That turned off the water
.forcedResponse
There's no handle
%label{:for => 'interactiveObject13'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 4 && index == 11 && tile == 13)
.tile.water
%label{:for => 'interactiveObject14', 'data-reference' => '14'}
%img.forced{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/waterOn.gif'}
.forcedResponse
Cant get through here
%label{:for => 'interactiveObject14'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 2 && index == 3 && tile == 15)
.tile
%label{:for => 'interactiveObject15', 'data-reference' => '15'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_161.png'}
.response
Dynamite sticks
-if (row == 4 && index == 12 && tile == 15)
.tile
%label{:for => 'interactiveObject16', 'data-reference' => '16'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
Box of fuses
-if (row == 2 && index == 12 && tile == 15)
.tile
%label{:for => 'interactiveObject17', 'data-reference' => '17'}
%img.forced{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_168.png'}
.forcedResponse
If only i had some dynamite & fuses
%label{:for => 'interactiveObject17'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (row == 2 && index == 7 && tile == 15)
.tile
%label{:for => 'interactiveObject18', 'data-reference' => '18'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-24.png'}
.response
Nothing useful in here
-if (row == 2 && index == 10 && tile == 15)
.tile
%label{:for => 'interactiveObject19', 'data-reference' => '19'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
Full of junk
-if (row == 3 && index == 9 && tile == 15)
.tile
%label{:for => 'interactiveObject20', 'data-reference' => '20'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-24.png'}
.response
Just an empty box
-if (row == 1 && index == 12 && tile == 13)
.tile
%label{:for => 'interactiveObject21', 'data-reference' => '21'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-25.png'}
.response
Nothing i can use
-if (row == 4 && index == 8 && tile == 13)
.tile
%label{:for => 'interactiveObject22', 'data-reference' => '22'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyCorridor-_094.png'}
.response
Nope empty
.tile
%label{:for => "indexRow#{row}-#{index}"}
.game_segment__control
-if (index != 1)
.forward
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
-if (index != columns)
.backward
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%label{:for => "indexRow#{row}-#{index}"}
.game_segment__control
.down
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}
%label{:for => "indexRow#{row - 1}-#{index}"}
.game_segment__control
.up
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/arrowMovement.png'}

-# Game inventory
.game_inventory
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/creepyBackpack.png'}
.game_inventory__item
.item.pickaxe{'data-reference' => '0'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/apple.gif'}
.details A healthy snack
.name Apple
.item.pickaxe{'data-reference' => '2'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/pickInventory.gif'}
.details A sturdy looking pickaxe
.name Pickaxe
.item.pickaxe{'data-reference' => '6'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/plankInventory.gif'}
.details A thick plank of wood
.name Plank
.item.pickaxe{'data-reference' => '8'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/note1.gif'}
.details A mysterious note
.name Note 1
.item.pickaxe{'data-reference' => '9'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/note2.gif'}
.details A mysterious note
.name Note 2
.item.pickaxe{'data-reference' => '10'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/note3.gif'}
.details A mysterious note
.name Note 3
.item.pickaxe{'data-reference' => '12'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/handleInventory.gif'}
.details Looks like its used to turn something
.name Handle
.item.pickaxe{'data-reference' => '15'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/dynamiteInventory.gif'}
.details No good without any fuses
.name Dynamite sticks
.item.pickaxe{'data-reference' => '16'}
%img{:src => 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/fusesInventory.gif'}
.details Some fuses for dynamite
.name Fuses
-# Game conditional checks
.game_win
.game_win__inner
.character
%p Thanks for playing
%a{:href => 'https://www.codepen.io/jcoulterdesign', :target => '_blank'} Follow me on codepen
%span for more shenanigans

Raw
script.js
// Nope, nothing here. Just a big long list of checkboxes and radio buttons.... You see, what happens is, let's say you click on the boulder, the input for the boulder is checked but the input for the pickaxe isn't. So CSS check to see if the checkbox is checked and the other checkbox is checked to check if the rule should apply. If the checkbox of the pickaxe is not checked then the check shows that the checkbox checked state of the previous checkbox isnt checked and thus the current checked box doesnt apply the checked checkbox state. Got that? Great. Me neither.
Raw
scripts
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Raw
style.scss
$rows: 4 !global;
$columns: 12 !global;
$gameObjects: 22;
$tileSize: 48px;
$walkSpeed: 1s;
$tilesPerSegment: 3;
$tilesPerSegmentVertical: 7;
$segmentHeight: $tileSize * $tilesPerSegmentVertical;
$debug: false;

* {
box-sizing: border-box;
}

@font-face {
font-family: pixles;
src: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/04B_03__.TTF);
}

/* ------------------------------------------------------------------------------------

Game styling

--------------------------------------------------------------------------------------- */

body {
background: #141415;
overflow: hidden;
font-family: pixles;
font-size: 15px;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
height: 100vh;
margin: 0;

& .game {
width: $tileSize * $tilesPerSegment * $columns;
position: absolute;
left: calc(50% - 72px);
right: 0;
top: calc(50% - 212px);
margin: auto;

input {
display: none;
}

// End screen styles

&_win {
position: fixed;
left: 0;
top: 0;
background: #141415;
z-index: 9;
width: 100%;
height: 100%;
opacity: 0;
pointer-events: none;
transition: all 1s 0s;

&__inner {
position: absolute;
left: 0;
right: 0;
margin: auto;
width: 300px;
top: 50%;
transform: translateY(-50%);
text-align: center;
opacity: 0;
transition: all 1s 2s;

p {
color: white;
margin-bottom: 30px;
}

span {
color: white;
opacity: 0.4;
}

a {
margin-bottom: 16px;
color: #78f148;
text-align: center;
width: 100%;
display: block;
}
}

.character {
width: 48px;
height: 48px;
position: relative;
left: -60px;
margin: auto;
background: red;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/corridorMainCharacter.gif');
animation: walk-1 $walkSpeed infinite;
z-index: 1;
background-position: 0 0;
transform: translateY(-50%) translateX($tileSize * ($tilesPerSegment / 2) - 8);
transition: all $walkSpeed linear;
z-index: 1;
pointer-events: none;
}
}

// Side inventory styles

&_inventory {
position: fixed;
z-index: 9;
left: 0;
color: white;
top: 50%;
-webkit-transform: translateY(-50%);
font-size: 11px;
right: 0;
margin: auto;
left: -420px;
width: 140px;
padding-left: 15px;
transform: translateY(-50%);
height: 64px;
cursor: pointer;
transition: all .6s .3s;

&:hover {
height: 371px;
transition: all .6s .2s;

.item {
opacity: 1;
left: 0px;
transition: all 0.3s;
-webkit-filter: blur(0px);

&:first-child {
display: block;
}
}
}

h1 {
font-weight: normal;
font-size: 12px;
}

img {
transform: scale(3);
image-rendering: pixelated;
cursor: pointer;
transform-origin: 0 0;

&:hover {

}
}

&__item {
margin-top: 70px;
text-align: center;
position: relative;
left: -24px;
width: 100%;
height: 100%;

.item {
margin: 10px 0 30px 0;
display: none;
opacity: 0;
left: 0px;
position: relative;
transition: all 0s;
float: left;
margin-right: 10px;
width: 34%;

&:hover {
z-index: 15;

.details {
opacity: 1;
top: -4px;
}
}

.name {
position: relative;
top: 11px;
}

.details {
padding: 7px;
opacity: 0;
border-radius: 4px;
position: absolute;
font-size: 13px;
text-align: center;
transition: all 0.2s .2s;
pointer-events: none;
background: white;
color: #141415;
width: 120px;
top: -4px;
left: 50px;
z-index: 20;
}

img {
transform: scale(2);
transform-origin: 50% 50%;
}
}
}
}

// Padlock stuff

.padlock {
display: none;
position: absolute;
width: 280px;
top: 71px;
left: -70px;
height: 280px;
background: #301f41b8;
z-index: 4;
border-radius: 324px;
border: 4px solid #ffb128;

img {
position: absolute;
left: 80px;
top: 35px;
}
}

%o {
display:block;
position: absolute;
left: 0;
right: 0;
top: 220px;
margin: auto;
}

.check {
display: none;
width: 80px;
cursor: pointer;
height: 80px;
position: absolute;
z-index: 6;
top: 303px;
left: 30px;
text-align: center;
line-height: 77px;
background: wheat;
color: #615133;
border-radius: 100px;
border: 3px solid #ffb128;
transition: all 0.3s;

&:hover {
background: #ffb128;
color: white;
}
}

input#interactiveObject--lock:not(:checked) {
+ span {
display: none;
}
}

input#interactiveObject--lock:checked {
+ .padlock {
display: block;

$y: '';
$x: ' + span ';

+ input {
display: block;
@for $i from 1 through 26 {

$y: $y + ' + span + input';
$x: $x + ' + input + span ';

#{$y} {
display: block;
}
#{$x} {
display: block;
}
#{$y} + span + label {
display: block;
}
}
}
}
}

#padlock1-1,#padlock2-1,#padlock3-1 {
&:after {
display: block !important;
}
}

#padlock1-9,#padlock2-9,#padlock3-9 {
&:after {
display: none !important;
}
}

input[id*="padlock"] {
@extend %o;

z-index: 3;
outline: none;
display:none;
-webkit-appearance: none;

+ span {
@extend %o;

background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/padlockBG.png);
width: 10px;
width: 22px;
height: 36px;
left: 0;
display: none;
line-height: 40px;
text-align: center;
position: fixed;
color: #444444;
top: 50%;
transform: translateY(9px) translateX(-35px);
}

@for $i from 1 through 34 {
&:nth-of-type(#{$i}) {
z-index: $i + 10;

&:checked {
z-index: 64 + $i;

& + span {
z-index: 64 - $i;
}
}
}
}

&:checked {
z-index: 30;

&:before {
display: none;
}

& + span {
& + input {
&:after {
display: none;
}
}
}
}

&:after {
background: red;
display: block;
content: '';
top: 48px;
position: absolute;
cursor: pointer;
height: 23px;
left: -7px;
width: 22px;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/padlockDown.png);
}

&:before {
display: block;
content: '';
position: absolute;
height: 23px;
width: 22px;
left: -7px;
top: -30px;
color: white;
background: red;
cursor: pointer;
background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/padlockUp.png);
}

&[id*="padlock1"] {
left: 19px;
+ span {
left: -27px;
}
}

&[id*="padlock2"] {
left: 64px;
+ span {
left: 66px;
}
}

&[id*="padlock3"] {
left: 106px;
+ span {
left: 149px;
}
}
}

// Loading screen styles

&_loader {
position: fixed;
z-index: 15;
background: #141415;
left: 0;
top: 0;
width: 100%;
height: 100%;
pointer-events: none;
opacity: 1;
animation: fadeOut 1.5s 7s forwards;

&__inner {
position: absolute;
left: 0;
right: 0;
margin: auto;
top: 50%;
transform: translateY(-50%);
font-size: 12px;
width: 200px;
text-align: center;

h1 {
font-weight: normal;
font-size: 12px;
}

& .logo {
width: 200px;
height: 70px;
margin: auto;
margin-bottom: 10px;
transform: scale(0);
opacity: 0;
animation: logo 2s forwards;

img {
width: 100%;
}
}

span {
color: rebeccapurple;
display: block;
opacity: 0;
margin-top: 8px;
animation: fadeIn 1.5s 3s forwards;
}

& .bar {
background: #3c3c3e;
position: relative;
height: 2px;
margin-top: 30px;
opacity: 0;
animation: fadeIn 1.5s 2.5s forwards;

&_inner {
width: 0px;
height: 100%;
background: white;
position: absolute;
top: 0;
animation: bar 3s 3s forwards;
}
}

& .subtitle {
color: #f49112;
margin: -18px 0px 40px 0;
opacity: 0;
animation: fadeIn 1.5s 1.5s forwards;
}
}
}

// Our little character

&_character {
width: 48px;
height: 48px;
background: red;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217233/corridorMainCharacter.gif');
position: absolute;
top: 216px;
left: -16px;
z-index: 1;
background-position: 0 0;
transform: translateY(-50%) translateX($tileSize * ($tilesPerSegment / 2) - 8);
transition: all $walkSpeed linear;
z-index: 1;
pointer-events: none;

img {
position: absolute;
border: 512px solid #0c0c0d;
transform: translateY(-685px) translateX(-670px);
opacity: 1;
}
}

// Intro dialogue

&_intro {
position: absolute;
top: 38px;
left: -33px;
z-index: 14;

input {
display: none;
}

input[type="radio"]:checked + div {
opacity: 1;
top: 140px;
transition: all 0.5s 0.8s;
pointer-events: all;

label {
opacity: 1;
bottom: -10px;
}
}

input#intro-1[type="radio"]:checked + div {
top: 140px;
opacity: 0;
transition: all 0.5s 0.8s;
animation: dialogueIn .5s 9s forwards;
pointer-events: all;
}

input#intro-1[type="radio"]:not(:checked) + div {
opacity: 0;
top: 160px;
transition: all 0.5s 0.8s;
}

input[type="radio"]#intro-5:checked + div + input + div {
opacity: 0;
pointer-events: none !important;
}

input[type="radio"]#intro-5:checked + div {
opacity: 0;
animation: showResponse 2s 2s forwards;
}

& .overlay {
position: fixed;
top: 0 !important;
width: 140%;
left: 0;
opacity: 1;
height: 260%;
background: #141415;
z-index: -1;
pointer-events: all;
transition: all 4s .7s !important;
}

& .dialogue {
position: absolute;
top: 160px;
opacity: 0;
width: 170px;
left: 20px;
padding: 15px;
border-radius: 4px;
font-size: 13px;
text-align: center;
transition: all 0.2s .2s;
pointer-events: none;
background: white;
color: #141415;

&.end {
position: absolute;
width: 130px;
left: 0;
text-align: center;
right: 0;
pointer-events: none;
top: 100px !important;
margin: auto;
transform: translateY(140px) translateX(39px);
background: white;
color: #141415;
padding: 8px;
border-radius: 5px;
}

label {
border-radius: 5px;
position: absolute;
right: -6px;
bottom: -20px;
z-index: 1;
opacity: 0;
cursor: pointer;
transition: all 0.4s 1s;

img {
transform: scale(2);
image-rendering: pixelated;
}

&:hover {
right: -13px;
background: #66bf60;
}
}
}
}

// Viewport

.viewport {
position: relative;
z-index: 0;
transition: all $walkSpeed linear;

.level {
position: absolute;
left: 0;
z-index: 1;
transform: scale(3);
transform-origin: 0 0;
image-rendering: pixelated;
}
}

&_segment {
width: $tileSize * $tilesPerSegment;
height: $segmentHeight;
border: 0px solid white;
float: left;
z-index: 1;
position: relative;
color: white;

.drip_container {
position: relative;
top: 80px;
display: none;
z-index: 10;

& .drip {
width: 3px;
height: 20px;
background: #81eeef;
position: absolute;
height: 0;
top: 14px;
opacity: 1;

@for $i from 1 through 5 {
&:nth-of-type(#{$i}) {
left: random(144) + 0px;
animation: drip 1.25s random(52) / 10 + 0s linear infinite;
}
}
}
}

@keyframes drip {
0% {height: 0;}
2% {height: 6px;}
5% {height: 6px;top:14px}
22% {top:158px; height:4px;opacity:1;}
23%{opacity: 0;height:0px}
100%{opacity: 0}
}

& .tiles {
& .tile {
width: $tileSize;
height: $tileSize;
float: left;
image-rendering: pixelated;

// Special tiles

&.door {
position: absolute;
top: 92px;
height: 144px;
left: -12px;
width: 60px;

img {
position: relative;
}
}

&.beam {
position: absolute;
top: 95px;
height: 108px;
}

&.water {
position: absolute;
top: 107px;
height: 108px;
}

&:before {
display: none;
content: ' ';
position: absolute;
width: 4px;
height: 10px;
border-left: 4px solid #e69c69;
border-right: 4px solid #e69c69;
z-index: 1;
left: 67px;
top: 140px;
transition: all 1s linear;
}

&:after {
top: -48px;
transition: all 1s linear;
height: 40px !important;
display: block;
overflow: hidden;
pointer-events: none;

img {
position: relative;
top: -400px;
}
}

img {
width: 100%;
cursor: pointer;

&:hover {
-webkit-filter: drop-shadow(2px 0px white) drop-shadow(-2px 0px white) drop-shadow(0px -2px white);
}
}

label {
pointer-events: none;

.response,
.forcedResponse,
.responseSuccess {
display: none;
position: absolute;
width: 130px;
left: 0;
text-align: center;
right: 0;
pointer-events: none;
top: calc(50% - 46px);
margin: auto;
background: white;
color: #141415;
padding: 8px;
border-radius: 5px;
}

.forcedResponse {
pointer-events: all !important;

label {
border-radius: 5px;
position: absolute;
right: -6px;
cursor: pointer;
bottom: -14px;
transform: scale(2);
z-index: 3;
cursor: pointer;
transition: all 0.4s 1s;

&:hover {
right: -2px;
}
}
}
}

&:after {
display: block;
width: $tileSize;
height: $tileSize;
transform: scale(3);
image-rendering: pixelated;
transform-origin: 0 0;
}
}
}

// Game controls

&__control {
div {
position: absolute;
opacity: 0;
pointer-events: none;
border-radius: 4px;
top: 50%;
cursor: pointer;

img {
transform: scale(3);
image-rendering: pixelated;
position: relative;
left: 0;
top: 0;
transition: all 0.3s;
}
}

& .forward {
transform: translateY(50px) translateX(-$tileSize);
left: 66px;
transition: all 0.3s 0s;

&:hover {
img {
left: 4px;
}
}
}

& .backward {
transform: translateY(50px) translateX(47px);
right: 65px;
transition: all 0.3s .1s;

&:hover {
img {
left: -4px;
}
}

img {
transform: rotate(180deg) scale(3);
}
}

& .up {
top: 90px !important;
left: 50%;
transform: translateX(-50%) translateY(25px);
transition: all 0.3s .2s;

&:hover {
img {
top: -4px;
}
}

img {
transform: rotate(-90deg) scale(3);
}
}

& .down {
bottom: 350px !important;
left: 50%;
opacity: 0;
top: auto;
transform: translateX(-50%) translateY(10px);
transition: all 0.3s .2s;

&:hover {
img {
top: 4px;
}
}

img {
transform: rotate(90deg) scale(3);
}
}
}
}
}
}

/* ------------------------------------------------------------------------------------

Calculate the way an animated sprite should be shown from its width and frame count
then animate the background image

--------------------------------------------------------------------------------------- */

@function walkCycle($frames, $width, $height, $row) {

$t: 100 / $frames;
$o: 0;
$p: '';

@for $i from 1 through $frames {
$o: $o + $t;
$p: $p + ($o - .1) + '%{background-position:-' + ($i - 1) * $width + 'px ' + $height * ($row - 1) + 'px;}';
$p: $p + $o + '%{background-position:-' + $i * $width + 'px ' + $height * ($row - 1) + 'px;}';
@if($o != 100) {
$p: $p + ($o + .1) + '%{background-position:-' + $i * $width + 'px ' + $height * ($row - 1) + 'px;}';
} @else {
$o: 100;
}
}

$v: '1%{background-position: 0px ' + $height * ($row - 1) + 'px;}' + $p;

@return unquote($v);
}

/* ------------------------------------------------------------------------------------------------------

Name: Traverse through scenes
Description: Makes it incredibly easy to trigger scene changes using the checkbox *hack*
Instead of doing input#index39:checked + input + div + div { props }

--------------------------------------------------------------------------------------------------------- */

@mixin traverse($n: 4) {
$div: "" !global; // Empty div string
$input: "" !global; // Empty input string
$input2: "" !global;
$input3: "" !global;
$input4: "" !global;
$label: "" !global; // Empty input string
$label2: "" !global;
$label3: "" !global;
$label4: "" !global;
$inputOffset: "+ input " !global;

// This needs to be made dynamic

@for $i from 1 through 47 {
$input: $input + "+ input " !global;
$inputOffset: $inputOffset + "+ input " !global;
}

@for $i from 1 through 35 {
$input2: $input2 + "+ input " !global;
}

@for $i from 1 through 23 {
$input3: $input3 + "+ input " !global;
}

@for $i from 1 through 11 {
$input4: $input4 + "+ input " !global;
}

@for $i from 1 through $columns {
@keyframes walk-#{$i} {
animation: walkCycle([/type="radio"]...
La fin de cet article est réservée aux abonnés. Soutenez le Club Developpez.com en prenant un abonnement pour que nous puissions continuer à vous proposer des publications.

Une erreur dans cette actualité ? Signalez-nous-la !

Avatar de Pyramidev
Expert éminent https://www.developpez.com
Le 09/02/2024 à 19:36
Ça me rappelle une image de CommitStrip publiée le 15 mars 2019 suite à l'ajout des fonctions trigonométrique dans CSS :

7  0