HTML5 game experiment with CreateJS
How do I make an html5 game experiment with createjs?
My first try with CreateJS, using EaselJS and TweenJS. Credits to Brad Manderscheid (https://twitter.com/bmanderscheid), who inspired this game with his book 'Beginning HTML5 Games with CreateJS' (http://www.apress.com/9781430263401).. What is a html5 game experiment with createjs? How do you make a html5 game experiment with createjs? This script and codes were developed by Michaela on 27 July 2022, Wednesday.
HTML5 game experiment with CreateJS - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>HTML5 game experiment with CreateJS</title> <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=Open+Sans:300);
body,
button { background-color: #E8E5E0; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 300; line-height: 1.5; letter-spacing: 0.05em;
}
button { border: none; outline: none;
}
#canvas { background-color: #CD7794;
}
#restart { background-color: transparent; border: 1px solid #CD7794; color: #CD7794; cursor: pointer; padding-top: 4px; text-transform: uppercase;
}
.container { display: block; margin-top: -280px; margin-left: -300px; position: absolute; top: 50%; left: 50%;
}
.manual { color: #F5AAC8; font-size: 2em; text-align: center;
}
.modal { background-color: rgba(255, 255, 255, 0.8); display: none; margin-top: -16px; margin-left: -300px; position: absolute; top: 50%; left: 50%; text-align: center; width: 600px; height: 100px;
}
.modal.is-visible { display: block;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <body onload="init()"> <div class="container"> <p class="manual">Drag and drop the shapes</p> <canvas id="canvas" width=600 height=400></canvas> </div> <div id="restart-dialog" class="modal"> <p> Yeeha, you won! You must be a very smart guy! </p> <button id="restart" name="button">Restart</button> </div>
</body> <script src='http://code.createjs.com/createjs-2013.12.12.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
HTML5 game experiment with CreateJS - Script Codes CSS Codes
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300);
body,
button { background-color: #E8E5E0; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 300; line-height: 1.5; letter-spacing: 0.05em;
}
button { border: none; outline: none;
}
#canvas { background-color: #CD7794;
}
#restart { background-color: transparent; border: 1px solid #CD7794; color: #CD7794; cursor: pointer; padding-top: 4px; text-transform: uppercase;
}
.container { display: block; margin-top: -280px; margin-left: -300px; position: absolute; top: 50%; left: 50%;
}
.manual { color: #F5AAC8; font-size: 2em; text-align: center;
}
.modal { background-color: rgba(255, 255, 255, 0.8); display: none; margin-top: -16px; margin-left: -300px; position: absolute; top: 50%; left: 50%; text-align: center; width: 600px; height: 100px;
}
.modal.is-visible { display: block;
}
HTML5 game experiment with CreateJS - Script Codes JS Codes
var stage, shapes = [], slots = [], score = 0;
/** * Initializing the game */
function init () { stage = new createjs.Stage('canvas'); buildShapes(); setBlocks(); startGame();
}
/** * Build the slots and draw them on canvas, * build the shapes and prepare to randomize them. * Every slot and shape gets a key to bind them together. * Both shapes and slots were pushed in their arrays. */
function buildShapes () { var colors = ['rect', 'circle', 'star', 'roundrect'], i, shape, slot; for ( i = 0; i < colors.length; i++ ) { slot = new createjs.Shape(); slot.graphics.beginStroke('#F2DEE7'); slot.graphics.beginFill('#CD7794'); switch (i) { case i = 0: slot.graphics.drawRect(0, 0, 100, 100); slot.regX = slot.regY = 50; break; case i = 1: slot.graphics.drawCircle(0, 0, 50); slot.regX = slot.regY = 0; break; case i = 2: slot.graphics.drawPolyStar(0, 0, 50, 6, 0.6, -90); slot.regX = slot.regY = 0; break; case i = 3: slot.graphics.drawRoundRect(0, 0, 100, 100, 25); slot.regX = slot.regY = 50; break; } slot.key = i; slot.y = 80; slot.x = (i * 130) + 100; stage.addChild(slot); slots.push(slot); shape = new createjs.Shape(); shape.graphics.beginFill('#F2DEE7'); switch (i) { case i = 0: shape.graphics.drawRect(0, 0, 100, 100); shape.regX = shape.regY = 50; break; case i = 1: shape.graphics.drawCircle(0, 0, 50); shape.regX = shape.regY = 0; break; case i = 2: shape.graphics.drawPolyStar(0, 0, 50, 6, 0.6, -90); shape.regX = shape.regY = 0; break; case i = 3: shape.graphics.drawRoundRect(0, 0, 100, 100, 25); shape.regX = shape.regY = 50; break; } shape.key = i; shapes.push(shape); }
}
/** * Set the blocks on stage on random places */
function setBlocks () { var i, r, shape, l = shapes.length; for ( i = 0; i < l; i++ ) { r = Math.floor(Math.random() * shapes.length); shape = shapes[r]; shape.homeY = 320; shape.homeX = (i * 130) + 100; shape.y = shape.homeY; shape.x = shape.homeX; shape.addEventListener('mousedown', startDrag); stage.addChild(shape); shapes.splice(r, 1); }
}
/** * Game logic: * Drag and drop the shapes, * test if they are over a suitable slot, * if yes, place them in slot and count up, * if no, remove them to their home place. * * @param {event} e - mousedown event */
function startDrag (e) { var shape = e.target, slot = slots[shape.key]; stage.setChildIndex(shape, stage.getNumChildren() - 1); stage.addEventListener('stagemousemove', function (e) { shape.x = e.stageX; shape.y = e.stageY; }); stage.addEventListener('stagemouseup', function (e) { var pt = slot.globalToLocal(stage.mouseX, stage.mouseY); stage.removeAllEventListeners(); if ( shape.hitTest(pt.x, pt.y) ) { shape.removeEventListener('mousedown', startDrag); score++; createjs.Tween.get(shape).to({x:slot.x, y:slot.y}, 200, createjs.Ease.quadOut).call(checkGame); } else { createjs.Tween.get(shape).to({x:shape.homeX, y:shape.homeY}, 200, createjs.Ease.quadOut); } });
}
/** * Check if the shapes are all placed correctly. * If yes, give the user feedback * and the possibility to reload the game */
function checkGame () { if ( score === 4 ) { var modal = document.getElementById('restart-dialog'), restartButton = document.getElementById('restart'); modal.className = modal.className + ' is-visible'; restartButton.onclick = function (e) { e.preventDefault(); modal.className = 'modal'; score = 0; init(); }; }
}
/** * Start and update the game */
function startGame () { createjs.Ticker.setFPS(60); createjs.Ticker.addEventListener('tick', function (e) { stage.update(); });
}
Developer | Michaela |
Username | Fischaela |
Uploaded | July 27, 2022 |
Rating | 3 |
Size | 4,135 Kb |
Views | 56,672 |
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 |
Animation tests | 2,748 Kb |
Geildanke typography | 3,249 Kb |
Pure CSS Navigation | 3,649 Kb |
Animated progress bar | 3,495 Kb |
IPad app prototype template | 2,396 Kb |
WebGL Starfield PointCloud Test | 3,098 Kb |
Geildanke products | 5,250 Kb |
WebGL Wood with Sun Animation | 3,600 Kb |
WebGL Template for ThreeJS | 2,713 Kb |
Timeline scribble | 4,488 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 |
Preloader | Rikki_Sixx | 2,815 Kb |
Animated Logo | Shakdaniel | 2,672 Kb |
Minimal Menu | Achudars | 3,430 Kb |
Simple Buttons | Haydenmills | 1,750 Kb |
A Pen by Stan Williams | Stanssongs | 6,706 Kb |
Basic HTML Slideshow | Tomhodgins | 3,386 Kb |
CSS3 Butterfly | Timohausmann | 3,430 Kb |
Flexbox slider | Rendro | 3,459 Kb |
CSS Colors | Alexpate | 2,232 Kb |
Mostly Fluid | Mccreath | 3,308 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!