Tile Game
How do I make an tile game?
My first attempt at coding a game using html, css and jQuery. It's pretty random as far as games go and I know canvas is likely a far better choice here but I just wanted to see if I could pull it off. Anyway... enjoy! :). What is a tile game? How do you make a tile game? This script and codes were developed by Adrian Payne on 18 August 2022, Thursday.
Tile Game - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Tile Game</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ @import url(http://fonts.googleapis.com/css?family=Luckiest+Guy);
body{ height:100%; overflow:hidden; background: radial-gradient(ellipse at center, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 25%,rgba(161,219,255,1) 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f0f9ff', endColorstr='#a1dbff',GradientType=1 ); font-family: "Luckiest Guy", sans-serif; letter-spacing:1px
}
div{ box-sizing:border-box;
}
.wrapper{ width:520px; margin:80px auto; position:relative;
}
.gameover{ box-sizing:border-box; padding:70px 0 0 0; width:362px; height:327px; position:absolute; top:0; left:-6px; background: rgba(0,0,0,0.5); z-index:100; margin-top:-35px; border-radius:15px; text-align:center; display:none; color:#fff;
}
.gameBoard{ width:350px; position:relative; float:left;
}
.gameBoard .row{ clear:both;
}
.sidebar{ width:140px; height:285px; position:relative; float:right;
}
.scoreBoard{ width:110px; height:170px; margin-top:-34px; padding:10px 10px 0; text-align:right; position:relative; top:21px; left:15px; border-radius:8px; background: rgba(0,0,0,0.8);
}
.lootracker li{ height:40px;
}
.lootracker li img{ height:30px; position:relative; top:8px;
}
/* Board Tiles */
.gametile{ width:70px; height:91px; float:left; margin-top:-34px; position:relative; transition: top 200ms ease; cursor: pointer;
}
.grass{ background: url('http://adrianpayne.me/game/assets/images/grass.png') no-repeat;
}
.grass:hover{ top:-10px;
}
.dirt{ background: url('http://adrianpayne.me/game/assets/images/dirt.png') no-repeat;
}
.stone{ background: url('http://adrianpayne.me/game/assets/images/stone.png') no-repeat;
}
.water{ background: url('http://adrianpayne.me/game/assets/images/water.png') no-repeat;
}
.air{ background: url('http://adrianpayne.me/game/assets/images/air.png') no-repeat;
}
/* Game Elements */
.gem{ width:46px; height:49px; position:relative; left:12px;
}
.star{ width:51px; height:51px; position:relative; left:3px; top:-10px;
}
.chest{ width:55px; height:68px; position:relative; left:8px; top:-14px;
}
.chest-closed{ background: url('http://adrianpayne.me/game/assets/images/chest-closed.png') no-repeat 0 0;
}
.chest-open{ background: url('http://adrianpayne.me/game/assets/images/chest-open.png') no-repeat 0 0;
}
/* Buttons */
.button{ width:80px; padding: 5px 10px 5px 10px; display:block; position:absolute; left:17px; bottom:38px; line-height:20px; font-size:18px; text-decoration:none; text-align:center; color:#fff; border-radius:8px; border: 2px solid PeachPuff; background: url('http://adrianpayne.me/game/assets/images/button.jpg') repeat;
}
.button:hover{ color:Khaki; border-color: Sienna;
}
.button:active{ font-size:16px; border-color: PeachPuff;
}
/* Text Styles */
h2{ font-size:22px; color:#fff;
}
h3{ font-size:35px; color:#fff; margin-bottom:5px;
}
.final-score{ font-size:55px; color:gold;
}
.score{ position:absolute; font-size:26px; color:gold; right:10px;
}
.loot{ position:absolute; font-size:22px; color:#fff; right:10px; top:75px;
}
/* Avatar */
.avatar{ position:absolute; left:-85px;
}
.speech-bubble{ background: url('http://adrianpayne.me/game/assets/images/speech.png') no-repeat 0 0; width:100px; height:62px; position:absolute; text-align:center; text-transform:uppercase; font-size:20px; line-height:56px; left:-180px; top:-30px; opacity:0;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <!--
My first attempt at coding a game using html, css and jQuery. It's pretty random as far as games go. Just wanted to see if I could pull it off. Anyway... enjoy! :)
Image assets are part of "Danc's Miraculously Flexible Game Prototyping Tiles"
Sounds: Me :)
-->
<div class="wrapper"> <img src="http://adrianpayne.me/game/assets/images/avatar.png" class="avatar" /> <div class="speech-bubble"></div> <div class="gameBoard"> <div class="gameover"> <h3>You scored</h3> <span class="final-score"></span><br/> <span>by @dazulu</span> </div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> <div class="gametile"></div> </div> <div class="sidebar"> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="stone gametile"></div> <div class="scoreBoard"> <h2 class="fancy-text">Score</h2> <span class="score fancy-text"></span> <div class="loot"> <ul class="lootracker"> <li><span class="gemcount">0</span> x <img src="http://adrianpayne.me/game/assets/images/gem.png"/></li> <li><span class="starcount">0</span> x <img src="http://adrianpayne.me/game/assets/images/star.png"/></li> </ul> </div> </div> <a href="javascript:void(0)" class="button fancy-text reset">Reset board</a> </div> </div> <!-- Preload Game Sounds --> <audio preload="auto" id="pop-1" > <source src="http://adrianpayne.me/game/assets/sounds/pop1.mp3"></source> Your browser says no sound for you :( </audio> <audio preload="auto" id="pop-2" > <source src="http://adrianpayne.me/game/assets/sounds/pop2.mp3"></source> </audio> <audio preload="auto" id="gemfind" > <source src="http://adrianpayne.me/game/assets/sounds/gem.mp3"></source> </audio> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Tile Game - Script Codes CSS Codes
@import url(http://fonts.googleapis.com/css?family=Luckiest+Guy);
body{ height:100%; overflow:hidden; background: radial-gradient(ellipse at center, rgba(240,249,255,1) 0%,rgba(203,235,255,1) 25%,rgba(161,219,255,1) 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f0f9ff', endColorstr='#a1dbff',GradientType=1 ); font-family: "Luckiest Guy", sans-serif; letter-spacing:1px
}
div{ box-sizing:border-box;
}
.wrapper{ width:520px; margin:80px auto; position:relative;
}
.gameover{ box-sizing:border-box; padding:70px 0 0 0; width:362px; height:327px; position:absolute; top:0; left:-6px; background: rgba(0,0,0,0.5); z-index:100; margin-top:-35px; border-radius:15px; text-align:center; display:none; color:#fff;
}
.gameBoard{ width:350px; position:relative; float:left;
}
.gameBoard .row{ clear:both;
}
.sidebar{ width:140px; height:285px; position:relative; float:right;
}
.scoreBoard{ width:110px; height:170px; margin-top:-34px; padding:10px 10px 0; text-align:right; position:relative; top:21px; left:15px; border-radius:8px; background: rgba(0,0,0,0.8);
}
.lootracker li{ height:40px;
}
.lootracker li img{ height:30px; position:relative; top:8px;
}
/* Board Tiles */
.gametile{ width:70px; height:91px; float:left; margin-top:-34px; position:relative; transition: top 200ms ease; cursor: pointer;
}
.grass{ background: url('http://adrianpayne.me/game/assets/images/grass.png') no-repeat;
}
.grass:hover{ top:-10px;
}
.dirt{ background: url('http://adrianpayne.me/game/assets/images/dirt.png') no-repeat;
}
.stone{ background: url('http://adrianpayne.me/game/assets/images/stone.png') no-repeat;
}
.water{ background: url('http://adrianpayne.me/game/assets/images/water.png') no-repeat;
}
.air{ background: url('http://adrianpayne.me/game/assets/images/air.png') no-repeat;
}
/* Game Elements */
.gem{ width:46px; height:49px; position:relative; left:12px;
}
.star{ width:51px; height:51px; position:relative; left:3px; top:-10px;
}
.chest{ width:55px; height:68px; position:relative; left:8px; top:-14px;
}
.chest-closed{ background: url('http://adrianpayne.me/game/assets/images/chest-closed.png') no-repeat 0 0;
}
.chest-open{ background: url('http://adrianpayne.me/game/assets/images/chest-open.png') no-repeat 0 0;
}
/* Buttons */
.button{ width:80px; padding: 5px 10px 5px 10px; display:block; position:absolute; left:17px; bottom:38px; line-height:20px; font-size:18px; text-decoration:none; text-align:center; color:#fff; border-radius:8px; border: 2px solid PeachPuff; background: url('http://adrianpayne.me/game/assets/images/button.jpg') repeat;
}
.button:hover{ color:Khaki; border-color: Sienna;
}
.button:active{ font-size:16px; border-color: PeachPuff;
}
/* Text Styles */
h2{ font-size:22px; color:#fff;
}
h3{ font-size:35px; color:#fff; margin-bottom:5px;
}
.final-score{ font-size:55px; color:gold;
}
.score{ position:absolute; font-size:26px; color:gold; right:10px;
}
.loot{ position:absolute; font-size:22px; color:#fff; right:10px; top:75px;
}
/* Avatar */
.avatar{ position:absolute; left:-85px;
}
.speech-bubble{ background: url('http://adrianpayne.me/game/assets/images/speech.png') no-repeat 0 0; width:100px; height:62px; position:absolute; text-align:center; text-transform:uppercase; font-size:20px; line-height:56px; left:-180px; top:-30px; opacity:0;
}
Tile Game - Script Codes JS Codes
var score = 0;
var numTiles = 25;
var tileCounter = 0;
var chestCount = 0;
var chestChance = 5;
var gemChance = 58;
var gemPoints = 500;
var chestPoints = 1500;
var gemcount = "";
var starcount = "";
var defaultTile = "grass";
var newTile = "";
var dirt = "dirt";
var stone = "stone";
var water = "water";
var gemText = "Nice!";
var chestText = "Wow!!";
var startText = "Go!";
var endText = "Yay!";
$(document).ready(function(){ init(defaultTile,score); $('.'+defaultTile).on('click',function(){ if($(this).hasClass(defaultTile)){ //get a % value of 100 for "drop rates" random = Math.floor(Math.random() * 100); if(chestCount===1){ getGem($(this),random); } else{ if(random <= chestChance){ chest($(this)); } else{ getGem($(this),random); } } } if($('.off').length === 25 && $('.chest-closed').length === 0){ $('.gameover').show(); $('.final-score').text(score); speechText(endText,3000); } }); $('.reset').on('click',function(){ $('.chest').remove(); $('.gameBoard .gametile').removeClass('dirt water stone off').addClass(defaultTile); score=0; chestCount=0; gemcount=0; starcount=0; $('.gemcount').text(0); $('.starcount').text(0); $('.score').text(score); $('.final-score').text(score); $('.gameover').hide(); speechText(startText,600); });
});
function init(defaultTile,score){ $('.gameBoard .gametile').addClass(defaultTile); $('.score').text(score);
}
function getGem(tile){ if(random > chestChance && random <= (gemChance + chestChance)){ gem(tile); } else{ changeTile(tile,water); sndEffects(0); }
}
function gem(tile) { changeTile(tile,dirt); speechText(gemText,250); sndEffects(1); scoreCalc(gemPoints); gemcount++; $('.gemcount').text(gemcount); $(tile).append("<img class='gem' src='http://adrianpayne.me/game/assets/images/gem.png' />"); $(tile).find('.gem').animate({top:"-30px",opacity:"0"},700); setTimeout(function() { $('img:last-child', tile).remove(); }, 800);
}
function chest(tile) { changeTile(tile,stone); $(tile).append("<div class='chest chest-closed'></div>"); chestCount = 1; sndEffects(0); $(".chest").click(function(){ $(this).unbind(); $(this).addClass('chest-open').removeClass('chest-closed'); $(this).append("<img class='star' src='http://adrianpayne.me/game/assets/images/star.png' />"); $(this).find('.star').animate({top:"-40px",opacity:"0"},800); $('.starcount').text(1); speechText(chestText,300); sndEffects(1); scoreCalc(chestPoints); $(this).delay(200).fadeOut("slow"); });
}
function changeTile(tile, type){ $(tile).removeClass(defaultTile).addClass(type).addClass("off");
}
function sndEffects(loot) { $("#pop-" + Math.ceil(Math.random() * 2))[0].play(); if(loot){ $("#gemfind")[0].play(); }
}
function speechText(text,delay){ $('.speech-bubble').stop(true, false).animate({opacity:"1"},200); $('.speech-bubble').text(text); $('.speech-bubble').delay(delay).animate({opacity:"0"},40);
}
function scoreCalc(points) { score += points; $('.score').text(score);
}
Developer | Adrian Payne |
Username | dazulu |
Uploaded | August 18, 2022 |
Rating | 4.5 |
Size | 6,146 Kb |
Views | 42,504 |
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!
Name | Size |
Simple Advent calendar with message | 4,871 Kb |
Radio button label click select | 2,295 Kb |
CSS Shop Icon | 3,260 Kb |
A Pen by Adrian Payne | 2,652 Kb |
Animated fire extinguisher | 3,223 Kb |
Round and round we go... | 3,929 Kb |
CSS Ribbons | 2,322 Kb |
Get Image Dimensions Client Side While Loading Image | 4,078 Kb |
CSS butterfly | 4,053 Kb |
CSS modal slide up animation with FB-ish zoom on scroll | 5,349 Kb |
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!
Name | Username | Size |
Ghost Buttons with CSS3 | Mithicher | 2,509 Kb |
Table border-collapse property | Maxds | 1,672 Kb |
C.Rowe Button | Brownerd | 2,473 Kb |
Pure CSS Read More Arrow | Zephyr | 1,747 Kb |
Pure CSS albums gallery | Renaudtertrais | 2,978 Kb |
LeMandinque | Aadesida | 9,046 Kb |
VerbalExpressions Converter | Cmalven | 2,607 Kb |
Save for later... | Victorfreire | 1,359 Kb |
Heatmap Color Scales | Stevepepple | 2,331 Kb |
BabyStore | Pablo-Ai | 3,807 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!