Created
February 26, 2017 18:12
-
-
Save GitSquared/6790b184c18ad1b4423bee81340048df to your computer and use it in GitHub Desktop.
Render de dégats pour jeux HTML5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Déganimation</title> | |
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | |
<script> | |
window.cursorPos = {x: 0, y: 0}; | |
$(() => { | |
$(document).mousemove((event) => { | |
window.cursorPos.x = event.pageX; | |
window.cursorPos.y = event.pageY - 18; | |
}); | |
$(document).click(() => { | |
faireMal(1); | |
}); | |
}); | |
let faireMal = (degats) => { | |
let rand = parseInt((Math.random() * 100), 10); | |
$("body").append('<span class="texteDegats" id="'+rand+'" style="left:'+window.cursorPos.x+'px;top:'+window.cursorPos.y+'px;">-'+degats+'</span>'); | |
let tmp = window.cursorPos.y - 80; | |
setTimeout(() => { | |
$("span#"+rand).attr('style', 'left:'+window.cursorPos.x+'px;top:'+tmp+'px;opacity:0;'); | |
setTimeout(() => { | |
$("span#"+rand).remove(); | |
}, 1000); | |
}, 20) | |
} | |
</script> | |
<style> | |
div#personnaj { | |
background-image: url("http://fc02.deviantart.net/fs70/f/2010/277/9/f/3d_stickman_render_example_by_bobthestickman-d303pe3.jpg"); | |
width: 250px; | |
height: 250px; | |
background-size: cover; | |
} | |
span.texteDegats { | |
transition: all 1s ease-in; | |
color: red; | |
font-weight: bold; | |
position: fixed; | |
cursor: default !important; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="personnaj"></div><br /><br /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment