Initial commit
1
demo/sis/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*~
|
||||
7
demo/sis/MIT-LICENCE.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
63
demo/sis/css/countdown.css
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#countdown {
|
||||
float: left;
|
||||
margin-top:12px;
|
||||
margin-left:12px;
|
||||
width:210px;
|
||||
padding: 3px;
|
||||
color: white;
|
||||
background-color: black;
|
||||
font-family: Tahoma;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
.clock {
|
||||
background : transparent url("../images/hours.png") no-repeat top left;
|
||||
height:40px;
|
||||
width:30px;
|
||||
float:left;
|
||||
}
|
||||
|
||||
.separator {
|
||||
background-position : -30px -220px;
|
||||
}
|
||||
|
||||
.n0 {
|
||||
background-position : 0 -7px;
|
||||
}
|
||||
.n1 {
|
||||
background-position : 0 -49px;
|
||||
}
|
||||
.n2 {
|
||||
background-position : 0 -91px;
|
||||
}
|
||||
.n3 {
|
||||
background-position : 0 -133px;
|
||||
}
|
||||
.n4 {
|
||||
background-position : 0 -176px;
|
||||
}
|
||||
.n5 {
|
||||
background-position : -30px -7px;
|
||||
}
|
||||
.n6 {
|
||||
background-position : -30px -50px;
|
||||
}
|
||||
.n7 {
|
||||
background-position : -30px -91px;
|
||||
}
|
||||
.n8 {
|
||||
background-position : -30px -133px;
|
||||
}
|
||||
.n9 {
|
||||
background-position : -30px -176px;
|
||||
}
|
||||
64
demo/sis/css/scoreboard.css
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
.scoreboard {
|
||||
float: left;
|
||||
/* margin-top:12px;
|
||||
margin-left:12px;
|
||||
*/ width: 180px;
|
||||
height: 40px;
|
||||
padding: 3px;
|
||||
color: white;
|
||||
background-color: black;
|
||||
font-family: Tahoma;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
.clock {
|
||||
background : transparent url("../images/hours.png") no-repeat top left;
|
||||
height:40px;
|
||||
width:30px;
|
||||
float:left;
|
||||
}
|
||||
|
||||
.separator {
|
||||
background-position : -30px -220px;
|
||||
}
|
||||
|
||||
.n0 {
|
||||
background-position : 0 -7px;
|
||||
}
|
||||
.n1 {
|
||||
background-position : 0 -49px;
|
||||
}
|
||||
.n2 {
|
||||
background-position : 0 -91px;
|
||||
}
|
||||
.n3 {
|
||||
background-position : 0 -133px;
|
||||
}
|
||||
.n4 {
|
||||
background-position : 0 -176px;
|
||||
}
|
||||
.n5 {
|
||||
background-position : -30px -7px;
|
||||
}
|
||||
.n6 {
|
||||
background-position : -30px -50px;
|
||||
}
|
||||
.n7 {
|
||||
background-position : -30px -91px;
|
||||
}
|
||||
.n8 {
|
||||
background-position : -30px -133px;
|
||||
}
|
||||
.n9 {
|
||||
background-position : -30px -176px;
|
||||
}
|
||||
129
demo/sis/css/spaceinvaders.css
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#playground {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.alien {
|
||||
}
|
||||
|
||||
.shipShot {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.shipShot.carot {
|
||||
background-color: orange;
|
||||
}
|
||||
|
||||
.shipShot.shotgun {
|
||||
background-color: grey;
|
||||
}
|
||||
|
||||
.shipShot.shotCorn {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.alienShot {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.weapon_bar {
|
||||
height: 10px;
|
||||
width: 100px;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.weapon_level {
|
||||
height: 8px;
|
||||
position: relative;
|
||||
margin: 1px;
|
||||
}
|
||||
.weapon_level.good {
|
||||
background-color: green;
|
||||
}
|
||||
.weapon_level.middle {
|
||||
background-color: yellow;
|
||||
}
|
||||
.weapon_level.bad {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.life {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
float: left;
|
||||
background-image: url('../images/sprite.png');
|
||||
background-position: 0px -16px;
|
||||
}
|
||||
|
||||
/** SCOREBOARD**/
|
||||
|
||||
.clock {
|
||||
background : transparent url("../images/font.png") no-repeat top left;
|
||||
height:32px;
|
||||
width:32px;
|
||||
float:left;
|
||||
}
|
||||
|
||||
.clock.red {
|
||||
background : transparent url("images/font-red.png") no-repeat top left;
|
||||
}
|
||||
|
||||
.clock.yellow {
|
||||
background : transparent url("images/font-yellow.png") no-repeat top left;
|
||||
}
|
||||
|
||||
.clock.small {
|
||||
position: relative;
|
||||
top: 45%;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
}
|
||||
|
||||
.n0 {
|
||||
background-position : 0px 0px;
|
||||
}
|
||||
.n1 {
|
||||
background-position : -32px 0px;
|
||||
}
|
||||
.n2 {
|
||||
background-position : -64px 0px;
|
||||
}
|
||||
.n3 {
|
||||
background-position : -96px 0px;
|
||||
}
|
||||
.n4 {
|
||||
background-position : -128px 0px;
|
||||
}
|
||||
.n5 {
|
||||
background-position : -160px 0px;
|
||||
}
|
||||
.n6 {
|
||||
background-position : -192px 0px;
|
||||
}
|
||||
.n7 {
|
||||
background-position : -224px 0px;
|
||||
}
|
||||
.n8 {
|
||||
background-position : -256px 0px;
|
||||
}
|
||||
.n9 {
|
||||
background-position : -288px 0px;
|
||||
}
|
||||
/** Scoreboard end **/
|
||||
|
||||
|
||||
/** Modal **/
|
||||
.modal {
|
||||
background-color: yellow;
|
||||
/** Modal - end **/
|
||||
BIN
demo/sis/images/aliensprite.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
demo/sis/images/background.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
demo/sis/images/background2.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
demo/sis/images/explosion_big.png
Normal file
|
After Width: | Height: | Size: 360 KiB |
BIN
demo/sis/images/explosion_small.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
demo/sis/images/farm.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
demo/sis/images/font.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
demo/sis/images/invader.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
demo/sis/images/ufo.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
60
demo/sis/index.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<!--
|
||||
Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Space invaders - Story</title>
|
||||
|
||||
<script src="lib/jquery-1.7.1.min.js" type="text/javascript" ></script>
|
||||
<script src="lib//jquery-ui-1.8.23.custom.min.js" type="text/javascript" ></script>
|
||||
<script src="lib/gamequery-0.7.1.js" type="text/javascript" ></script>
|
||||
<script src="js/tools.js" type="text/javascript" ></script>
|
||||
<script src="js/scoreboard.js" type="text/javascript" ></script>
|
||||
<script src="js/countdown.js" type="text/javasccript" ></script>
|
||||
<script src="js/lettering.js" type="text/javascript" ></script>
|
||||
|
||||
<link href="css/scoreboard.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="css/countdown.css" type="text/css" rel="stylesheet"/>
|
||||
|
||||
<script src="js/animations/animations.js" type="text/javascript" ></script>
|
||||
<script src="js/animations/aliens.js" type="text/javascript" ></script>
|
||||
<script src="js/animations/explosions.js" type="text/javascript" ></script>
|
||||
<script src="js/animations/worlds.js" type="text/javascript" ></script>
|
||||
|
||||
<script src="js/spaceinvaders-ui.js" type="text/javascript" ></script>
|
||||
<script src="js/spaceinvaders-core.js" type="text/javascript" ></script>
|
||||
<script src="js/models/weapons.js" type="text/javascript" ></script>
|
||||
<script src="js/models/models.js" type="text/javascript" ></script>
|
||||
<script src="js/models/aliens.js" type="text/javascript" ></script>
|
||||
<script src="js/models/waves.js" type="text/javascript" ></script>
|
||||
<script src="js/models/weapons.js" type="text/javascript" ></script>
|
||||
|
||||
<link href="css/spaceinvaders.css" type="text/css" rel="stylesheet"/>
|
||||
|
||||
<link href="../../extra/css/extra.css" type="text/css" rel="stylesheet" media="screen, projection" />
|
||||
<script src="../../extra/js/sis.js" type="text/javascript" ></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="playgroundContainer" style="height: 544;">
|
||||
<div id="playground">
|
||||
<div id="welcomeScreen">
|
||||
<div style="position: absolute; top: 120px; width: 700px; color: white;">
|
||||
<div id="loadingBar"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="width: 448px; text-align: center;margin-top: 00px;">
|
||||
<button id="startBtn" class="push--skeuo">Start</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
55
demo/sis/js/animations/aliens.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var ALIENS_WIDTH = 25,
|
||||
ALIENS_WIDTH_2 = 18,
|
||||
ALIENS_HEIGHT = 17,
|
||||
ALIENS_SPRITE = IMAGES_PREFIX + "invader.png",
|
||||
ALIENS_RATE = 400;
|
||||
|
||||
var ALIENS_TYPE = [
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : ALIENS_SPRITE,
|
||||
numberOfFrame : 2,
|
||||
delta : 24,
|
||||
rate : ALIENS_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL
|
||||
}),
|
||||
width : 24,
|
||||
height: 18
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : ALIENS_SPRITE,
|
||||
numberOfFrame : 2,
|
||||
delta : ALIENS_WIDTH_2,
|
||||
offsety : 20,
|
||||
rate : ALIENS_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL
|
||||
}),
|
||||
width : ALIENS_WIDTH_2,
|
||||
height: 17
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : ALIENS_SPRITE,
|
||||
numberOfFrame : 2,
|
||||
delta : ALIENS_WIDTH,
|
||||
offsety : 40,
|
||||
rate : ALIENS_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL
|
||||
}),
|
||||
width : ALIENS_WIDTH,
|
||||
height: 18
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
11
demo/sis/js/animations/animations.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var IMAGES_PREFIX = "images/";
|
||||
127
demo/sis/js/animations/explosions.js
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var EXPLOSION_BIG = IMAGES_PREFIX + "explosion_big.png",
|
||||
EXPLOSION_BIG_RATE = 50,
|
||||
EXPLOSION_SMALL = IMAGES_PREFIX + "explosion_small.png",
|
||||
EXPLOSION_SMALL_RATE = 50;
|
||||
|
||||
var EXPLOSIONS = {
|
||||
BIG : [
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 128,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 256,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 384,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 512,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 640,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 768,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
},
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_BIG,
|
||||
offsety : 896,
|
||||
numberOfFrame : 8,
|
||||
delta : 128,
|
||||
rate : EXPLOSION_BIG_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE
|
||||
}),
|
||||
width : 128,
|
||||
height: 128
|
||||
}
|
||||
],
|
||||
SMALL : [
|
||||
{
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : EXPLOSION_SMALL,
|
||||
numberOfFrame : 10,
|
||||
delta : 64,
|
||||
rate : EXPLOSION_SMALL_RATE,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL | $.gQ.ANIMATION_CALLBACK | $.gQ.ANIMATION_ONCE
|
||||
}),
|
||||
width : 64,
|
||||
height: 64
|
||||
}
|
||||
]
|
||||
}
|
||||
131
demo/sis/js/animations/worlds.js
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var FARM_SPRITE = IMAGES_PREFIX + "farm.png",
|
||||
FARM_BACKGROUND_1 = IMAGES_PREFIX + "background.png",
|
||||
FARM_BACKGROUND_2 = IMAGES_PREFIX + "background2.png";
|
||||
|
||||
var WORLD = {
|
||||
farm : {
|
||||
hero : {
|
||||
ship : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE
|
||||
}),
|
||||
width : 48,
|
||||
height : 24,
|
||||
posx : 0,
|
||||
posy : 17
|
||||
},
|
||||
/*cockpit : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsety : 24,
|
||||
offsetx : 20
|
||||
}),
|
||||
width : 20,
|
||||
height : 33,
|
||||
posx : 28,
|
||||
posy : 3
|
||||
},*/
|
||||
smallWheel : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 0,
|
||||
offsety : 24
|
||||
}),
|
||||
posx : 4,
|
||||
posy : 30,
|
||||
width: 14,
|
||||
height: 14
|
||||
},
|
||||
bigWheel : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 0,
|
||||
offsety : 38
|
||||
}),
|
||||
width : 19,
|
||||
height : 19,
|
||||
posx : 25,
|
||||
posy : 27
|
||||
}
|
||||
},
|
||||
alien : {
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : IMAGES_PREFIX + "invader.png",
|
||||
numberOfFrame : 2,
|
||||
delta : ALIENS_WIDTH,
|
||||
rate : 400,
|
||||
type : $.gQ.ANIMATION_HORIZONTAL
|
||||
}),
|
||||
width : ALIENS_WIDTH,
|
||||
height : ALIENS_HEIGHT
|
||||
},
|
||||
ufo : {
|
||||
animation: new $.gQ.Animation({imageURL: IMAGES_PREFIX + "ufo.png"}),
|
||||
width: 48,
|
||||
height: 32,
|
||||
posy: 10
|
||||
},
|
||||
life : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 14,
|
||||
offsety : 24
|
||||
}),
|
||||
width: 32,
|
||||
height: 16
|
||||
},
|
||||
weapons : {
|
||||
corn : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 19,
|
||||
offsety : 37
|
||||
}),
|
||||
width: 19,
|
||||
height: 19
|
||||
},
|
||||
carot : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 38,
|
||||
offsety : 37
|
||||
}),
|
||||
width: 19,
|
||||
height: 19
|
||||
},
|
||||
gun : {
|
||||
animation : new $.gameQuery.Animation({
|
||||
imageURL : FARM_SPRITE,
|
||||
offsetx : 57,
|
||||
offsety : 37
|
||||
}),
|
||||
width: 19,
|
||||
height: 19
|
||||
}
|
||||
},
|
||||
backgrounds : {
|
||||
farm: {
|
||||
background1 : {
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : FARM_BACKGROUND_1
|
||||
})
|
||||
},
|
||||
background2 : {
|
||||
animation : new $.gQ.Animation({
|
||||
imageURL : FARM_BACKGROUND_2
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
94
demo/sis/js/countdown.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var COUNTDOWN = {
|
||||
mustStop: false,
|
||||
|
||||
init: function( minutes, seconds ) {
|
||||
COUNTDOWN.minutes = minutes;
|
||||
COUNTDOWN.seconds = seconds;
|
||||
COUNTDOWN.mustStop = false;
|
||||
// $( "#countdown" ).width( ( minutes > 0 ? 90 : 0 ) + 90);
|
||||
// $( "#countdown" ).css( "background-color", "black" );
|
||||
},
|
||||
|
||||
start: function() {
|
||||
if( COUNTDOWN.mustStop )
|
||||
return;
|
||||
|
||||
COUNTDOWN.running = true;
|
||||
|
||||
var currentMinutes = "";
|
||||
var currentSeconds = "";
|
||||
var imageMinutes = "";
|
||||
var imageSeconds = "";
|
||||
|
||||
currentMinutes = COUNTDOWN.minutes;
|
||||
currentSeconds = COUNTDOWN.seconds;
|
||||
|
||||
var nextMinutes = COUNTDOWN.minutes;
|
||||
var nextSeconds = COUNTDOWN.seconds - 1;
|
||||
|
||||
if( nextSeconds < 0 && nextMinutes > 0 ) {
|
||||
nextSeconds = 59;
|
||||
nextMinutes = Math.min(0, nextMinutes -1);
|
||||
}
|
||||
|
||||
COUNTDOWN.minutes = nextMinutes;
|
||||
COUNTDOWN.seconds = nextSeconds;
|
||||
|
||||
if( currentMinutes <= 0 && currentSeconds < 10 )
|
||||
$( "#countdown" ).css( "background-color", "red" );
|
||||
|
||||
if(parseInt(currentMinutes) < 10 ) currentMinutes = "0" + currentMinutes;
|
||||
if(parseInt(currentSeconds) < 10 ) currentSeconds = "0" + currentSeconds;
|
||||
|
||||
for(i = 0; i < String(currentMinutes).length; i++) {
|
||||
imageMinutes += "<div class='clock n"+ String(currentMinutes)[i]+"'></div>";
|
||||
}
|
||||
|
||||
for(i = 0; i < String(currentSeconds).length; i++) {
|
||||
imageSeconds += "<div class='clock n"+ String(currentSeconds)[i]+"'></div>";
|
||||
}
|
||||
|
||||
if( COUNTDOWN.minutes > 0) {
|
||||
$("#subMinutes").empty().removeClass( "hide" ).append( imageMinutes );;
|
||||
$(".clock.clock.separator").removeClass( "hide" );
|
||||
} else {
|
||||
$("#subMinutes").empty().addClass( "hide" );
|
||||
$(".clock.clock.separator").addClass( "hide" );
|
||||
}
|
||||
|
||||
$("#subSeconds").empty().append( imageSeconds );
|
||||
|
||||
if( nextMinutes >= 0 && nextSeconds >= 0 )
|
||||
setTimeout( "COUNTDOWN.start()", 1000 );
|
||||
else
|
||||
COUNTDOWN.callback();
|
||||
},
|
||||
|
||||
add: function(seconds) {
|
||||
console.log( "Adding " + seconds + " seconds to countdown" );
|
||||
COUNTDOWN.seconds = COUNTDOWN.seconds + seconds;
|
||||
},
|
||||
|
||||
setTime: function( seconds ) {
|
||||
console.log( "Setting " + seconds + " seconds to countdown" );
|
||||
COUNTDOWN.seconds = seconds;
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
COUNTDOWN.mustStop = true;
|
||||
},
|
||||
|
||||
callback: function() {
|
||||
console.log( "COUNTDOWN.callback" );
|
||||
}
|
||||
};
|
||||
78
demo/sis/js/lettering.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
function injector(t, splitter, forceSmallParam) {
|
||||
var a = t.text().split(splitter);
|
||||
var html = "",
|
||||
clazz = "clock",
|
||||
letterSize = 32,
|
||||
count = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
lineSize,
|
||||
letter, iLetter,
|
||||
i, x, y
|
||||
forceSmall = false;//forceSmallParam ? forceSmallParam : false;
|
||||
if( typeof customClazz != "undefined" ) {
|
||||
clazz = " clock " + customClazz;
|
||||
}
|
||||
if (a.length) {
|
||||
$(a).each(
|
||||
function(i, letter) {
|
||||
iLetter = (letter.charCodeAt(0) - 97);
|
||||
if( letter === " " ) {
|
||||
html += "<span class='blank'></span>";
|
||||
width += 16;
|
||||
count = count + 1;
|
||||
} else {
|
||||
if( letter.charCodeAt(0) > 47 && letter.charCodeAt(0) < 58 ) { // Numbers
|
||||
letterSize = 32;
|
||||
if( forceSmall ) {
|
||||
letterSize = 16;
|
||||
}
|
||||
html += "<span class='" + clazz + (forceSmall ? "small" : "") + "' style='top: -50%;background-position: -" + ( parseInt( letter, null ) * letterSize) + "px -" + (forceSmall ? 128 : 0) +"px'></span>";
|
||||
count = count + 1;
|
||||
} else { // Letters
|
||||
if( ( letter.charCodeAt(0) >= 'a'.charCodeAt(0) && letter.charCodeAt(0) <= 'z'.charCodeAt(0)) ) {
|
||||
if( height < 16 ) {
|
||||
height = 16;
|
||||
}
|
||||
width += 16;
|
||||
lineSize = 20;
|
||||
x = (iLetter % lineSize) * 16;
|
||||
y = Math.floor(iLetter / lineSize) * 16 + 144;
|
||||
html += "<span class='" + clazz + " small' style='background-position: -" + x + "px -" + y + "px'></span>";
|
||||
count = count + 1;
|
||||
} else {
|
||||
if( letter.charCodeAt(0) >= 'A'.charCodeAt(0) && letter.charCodeAt(0) <= 'Z'.charCodeAt(0)) {
|
||||
iLetter = letter.charCodeAt(0) - 'A'.charCodeAt(0);
|
||||
if( height < 32 ) {
|
||||
height = 32;
|
||||
}
|
||||
width += 32;
|
||||
lineSize = 10;
|
||||
x = (iLetter % lineSize) * 32;
|
||||
y = Math.floor(iLetter / lineSize) * 32 + 32;
|
||||
html += "<span class='" + clazz + "' style='background-position: -" + x + "px -" + y + "px'></span>";
|
||||
count = count + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
t.empty().append(html);
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.lettering = function() {
|
||||
return injector( $(this), '', 'char', '' ); // always pass an array
|
||||
};
|
||||
})(jQuery);
|
||||
91
demo/sis/js/models/aliens.js
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var ALIENS = {
|
||||
alien1 : {
|
||||
health : 1,
|
||||
weapon : WEAPONS.ALIEN,
|
||||
score : 5,
|
||||
aggression : 0.0005,
|
||||
animation : ALIENS_TYPE[0]
|
||||
},
|
||||
alien2 : {
|
||||
health : 2,
|
||||
weapon : WEAPONS.ALIEN,
|
||||
score : 10,
|
||||
aggression : 0.001,
|
||||
animation : ALIENS_TYPE[1]
|
||||
},
|
||||
alien3 : {
|
||||
health : 3,
|
||||
weapon : WEAPONS.ALIEN,
|
||||
score : 20,
|
||||
aggression : 0.0015,
|
||||
animation : ALIENS_TYPE[2]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*** Actors - Aliens ***/
|
||||
function Alien(id, start, move, type) {
|
||||
"use strict";
|
||||
|
||||
this.id = id;
|
||||
this.x = start.x;
|
||||
this.y = start.y;
|
||||
this.moveFct = move;
|
||||
|
||||
this.weapon = new Weapon(type.weapon);
|
||||
this.fireDirectionY = 1;
|
||||
|
||||
this.originX = this.x;
|
||||
this.originY = this.y;
|
||||
this.directionX = -1;
|
||||
this.speed = 0.5;
|
||||
this.animation = type.animation;
|
||||
this.width = type.animation.width;
|
||||
this.height = type.animation.height;
|
||||
this.health = type.health;
|
||||
this.aggression = type.aggression;
|
||||
this.score = type.score;
|
||||
}
|
||||
|
||||
Alien.prototype = {
|
||||
moveFct : null,
|
||||
width : 0,
|
||||
height : 0,
|
||||
aggression : 0,
|
||||
animation : null,
|
||||
score : 0,
|
||||
|
||||
init : function() {
|
||||
"use strict";
|
||||
this.speed = 0;
|
||||
this.node.x(this.x);
|
||||
this.node.y(this.y);
|
||||
},
|
||||
|
||||
move : function() {
|
||||
"use strict";
|
||||
this._super("move", arguments);
|
||||
if (typeof this.moveFct !== undefined) {
|
||||
this.moveFct();
|
||||
}
|
||||
},
|
||||
|
||||
destroy : function() {
|
||||
this._super("destroy", arguments);
|
||||
Game.addToScore( this.score );
|
||||
}
|
||||
};
|
||||
|
||||
heriter(Alien.prototype, Actor.prototype);
|
||||
|
||||
/*** Actors - Aliens - END ***/
|
||||
234
demo/sis/js/models/models.js
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
function getAliensMidHeight() {
|
||||
var higherAlien = Math.max.apply( null,
|
||||
$(".alien").map(function() {
|
||||
return $(this).y();
|
||||
}).get() ),
|
||||
lowerAlien = Math.min.apply( null,
|
||||
$(".alien").map(function() {
|
||||
return $(this).y();
|
||||
}).get() );
|
||||
|
||||
return (higherAlien + lowerAlien) / 2;
|
||||
}
|
||||
|
||||
WORLD.farm.bonus = [
|
||||
{
|
||||
type: "weapon",
|
||||
clazz: WEAPONS.CAROT,
|
||||
animation: WORLD.farm.weapons.carot
|
||||
},
|
||||
{
|
||||
type: "weapon",
|
||||
clazz: WEAPONS.CORN,
|
||||
animation: WORLD.farm.weapons.corn
|
||||
}
|
||||
];
|
||||
|
||||
/*** Actors ***/
|
||||
function Actor() {
|
||||
"use strict";
|
||||
}
|
||||
Actor.prototype = {
|
||||
id : null,
|
||||
node : null,
|
||||
x : null,
|
||||
y : null,
|
||||
originX : 0,
|
||||
originY : 0,
|
||||
speed : 0,
|
||||
health : 1,
|
||||
directionX : 0,
|
||||
directionY : 0,
|
||||
fireDirectionX : 0,
|
||||
fireDirectionY : 0,
|
||||
weapon : null,
|
||||
animations : {},
|
||||
|
||||
getX : function() {
|
||||
"use strict";
|
||||
return this.x;
|
||||
},
|
||||
|
||||
getY : function() {
|
||||
"use strict";
|
||||
return this.y;
|
||||
},
|
||||
|
||||
move : function() {
|
||||
"use strict";
|
||||
if (!Game.running) {
|
||||
return;
|
||||
}
|
||||
this.x += this.directionX * this.speed;
|
||||
this.y += this.directionY * this.speed;
|
||||
this.x = Math.min(this.x, PLAYGROUND_WIDTH - this.node.w());
|
||||
this.x = Math.max(this.x, 0);
|
||||
this.node.x(this.x);
|
||||
this.node.y(this.y);
|
||||
},
|
||||
|
||||
getOriginX : function() {
|
||||
return this.originX;
|
||||
},
|
||||
|
||||
getOriginY : function() {
|
||||
return this.originY;
|
||||
},
|
||||
|
||||
up : function(active) {
|
||||
"use strict";
|
||||
this.directionY = active ? -1 : 0;
|
||||
},
|
||||
|
||||
down : function(active) {
|
||||
"use strict";
|
||||
this.directionY = active ? 1 : 0;
|
||||
},
|
||||
|
||||
left : function(active) {
|
||||
"use strict";
|
||||
this.directionX = active ? -1 : 0;
|
||||
},
|
||||
|
||||
right : function(active) {
|
||||
"use strict";
|
||||
this.directionX = active ? 1 : 0;
|
||||
},
|
||||
|
||||
fire : function(layout, clazz) {
|
||||
var name = "shot" + Math.ceil(Math.random() * 1000);
|
||||
if (this.weapon.fire(layout)) {
|
||||
layout.addSprite(name, $.extend({ posx : this.x + this.node.w() / 2, posy : this.y + this.fireDirectionY * this.node.h()}, this.weapon));
|
||||
$("#" + name).addClass(clazz).addClass(this.weapon.clazz);
|
||||
$("#" + name)[0].weapon = this.weapon;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
hit : function() {
|
||||
this.health = this.health - 1;
|
||||
if( this.health == 0 ) {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
return this.health;
|
||||
},
|
||||
|
||||
destroy : function() {
|
||||
$("#" + this.id).remove();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*** Actors - Heroes - END ***/
|
||||
function Ship(id, start, speed, animation) {
|
||||
"use strict";
|
||||
this.id = id;
|
||||
this.x = start.x;
|
||||
this.y = start.y;
|
||||
|
||||
this.weapon = new Weapon(WEAPONS.SHOTGUN);
|
||||
this.fireDirectionY = -1;
|
||||
|
||||
this.originX = this.x;
|
||||
this.originY = this.y;
|
||||
this.speed = speed;
|
||||
|
||||
this.animation = animation;
|
||||
|
||||
/*this.bigWheel = $("#bigWheel");
|
||||
this.smallWheel = $("#smallWheel");
|
||||
var bigWheelRadius = bigWheel.h() / 2,
|
||||
smallWheelRadius = smallWheel.h() / 2;
|
||||
this.bigWheelAngle = this.speed * 360 / ( 2 * Math.PI * bigWheelRadius );
|
||||
this.smallWheelAngle = this.speed * 360 / ( 2 * Math.PI * smallWheelRadius );*/
|
||||
|
||||
}
|
||||
|
||||
Ship.prototype = {
|
||||
speed : 0,
|
||||
directionX : 0,
|
||||
directionY : 0,
|
||||
lives : 3,
|
||||
animation : null,
|
||||
/*bigWheel : null,
|
||||
bigWheelAngle : 0,
|
||||
smallWheel : null,
|
||||
smallWheelAngle : 0,*/
|
||||
|
||||
init : function() {
|
||||
"use strict";
|
||||
this.speed = 0;
|
||||
this.node.x(this.x);
|
||||
this.node.y(this.y);
|
||||
},
|
||||
|
||||
/**
|
||||
* Arc = (2* Pi * R) / (360) * alpha
|
||||
*
|
||||
*/
|
||||
move : function() {
|
||||
"use strict";
|
||||
this._super("move", arguments);
|
||||
},
|
||||
|
||||
up : function(active) {
|
||||
if (this.y < (PLAYGROUND_HEIGHT - 2 * HUD_HEIGHT)) {
|
||||
return false;
|
||||
}
|
||||
this._super("up", arguments);
|
||||
},
|
||||
|
||||
destroy : function() {
|
||||
var _this = this,
|
||||
_hero = $("#hero"),
|
||||
explosion = EXPLOSIONS.BIG;
|
||||
|
||||
$("#life" + this.lives).remove();
|
||||
this.lives = this.lives - 1;
|
||||
|
||||
$("#actors").addSprite("heroExplosion",
|
||||
{
|
||||
width: explosion[0].width,
|
||||
height: explosion[0].height,
|
||||
posx: _hero.x() - explosion[0].width / 2 + _hero.w(),
|
||||
posy: _hero.y() - explosion[0].height / 2 - _hero.h() /4
|
||||
}
|
||||
);
|
||||
explosionBig($("#heroExplosion"), function() {$("#heroExplosion").remove()});
|
||||
_hero.children().hide();
|
||||
},
|
||||
|
||||
respawn : function() {
|
||||
$("#heroExplosion").remove();
|
||||
$("#hero").children().show();
|
||||
},
|
||||
|
||||
fire : function() {
|
||||
if(this._super("fire", arguments)) {
|
||||
Game.shots.total = Game.shots.total + 1;
|
||||
this.weapon.stock--;
|
||||
if( this.weapon.stock == 0 ) {
|
||||
this.weapon = new Weapon(WEAPONS.SHOTGUN);
|
||||
$("#current_weapon").setAnimation(this.weapon.animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
heriter(Ship.prototype, Actor.prototype);
|
||||
/*** Actors - Heroes - END ***/
|
||||
|
||||
/*** Actors - END ***/
|
||||
183
demo/sis/js/models/waves.js
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*** Move ***/
|
||||
|
||||
var MOVE = {
|
||||
translation : {
|
||||
init : function (x, y) {
|
||||
return {directionX : 1, directionY : 0};
|
||||
},
|
||||
move : function() {
|
||||
var offset = (PLAYGROUND_WIDTH - 16 * this.width) / 2;
|
||||
if (Math.abs((this.getOriginX() - this.getX())) >= offset) {
|
||||
this.directionX *= -1;
|
||||
this.y = (this.y + this.height / 4);
|
||||
}
|
||||
},
|
||||
},
|
||||
mirror : {
|
||||
init : function(x, y) {
|
||||
if( x < PLAYGROUND_WIDTH / 2 ) {
|
||||
return {directionX: -1, directionY: 0};
|
||||
}
|
||||
return {directionX: 1, directionY: 0};
|
||||
},
|
||||
move : function() {
|
||||
var offset = this.width / 2;
|
||||
if (Math.abs((this.getOriginX() - this.getX())) >= offset) {
|
||||
this.directionX *= -1;
|
||||
this.y = (this.y + this.height / 4);
|
||||
}
|
||||
},
|
||||
},
|
||||
half_part_rotation : {
|
||||
init : function (x, y) {
|
||||
return {directionX:0, directionY:0};
|
||||
},
|
||||
move : function () {
|
||||
var _this = $(this)[0],
|
||||
mid = PLAYGROUND_WIDTH / 2,
|
||||
center = _this.center,
|
||||
width = _this.width;
|
||||
|
||||
if( this.directionX == 0 && this.directionY == 0 ) {
|
||||
center = {x: ( this.getOriginX() < mid ? PLAYGROUND_WIDTH / 4 : 3 * PLAYGROUND_WIDTH / 4), y: getAliensMidHeight() };
|
||||
width = distance(center, {x: this.x, y: this.y});
|
||||
var xAxis = {x: width, y: 0},
|
||||
current = {x: center.x - this.getOriginX(), y: center.y - this.getOriginY()},
|
||||
alpha = angle( xAxis, current );
|
||||
this.directionX = 0.01;
|
||||
this.directionY = alpha;
|
||||
$(this)[0].center = center;
|
||||
$(this)[0].width = width;
|
||||
}
|
||||
|
||||
if( this.getOriginX() < mid ) {
|
||||
this.directionY = this.directionY + this.directionX;
|
||||
} else {
|
||||
this.directionY = this.directionY - this.directionX;
|
||||
}
|
||||
if( Math.abs(this.directionY) > 2 * Math.PI ) {
|
||||
this.directionY = 0;
|
||||
}
|
||||
center.y = center.y + 0.1;
|
||||
_this.center = center;
|
||||
this.x = center.x + width * Math.cos(this.directionY);
|
||||
this.y = center.y + width * Math.sin(this.directionY);
|
||||
}
|
||||
},
|
||||
|
||||
rotation : {
|
||||
init : function (x, y) {
|
||||
return {directionX:0, directionY:0};
|
||||
},
|
||||
move : function () {
|
||||
var _this = $(this)[0],
|
||||
mid = PLAYGROUND_WIDTH / 2,
|
||||
center = _this.center,
|
||||
width = _this.width;
|
||||
|
||||
if( this.directionX == 0 && this.directionY == 0 ) {
|
||||
center = {x: mid, y: getAliensMidHeight() };
|
||||
width = distance(center, {x: this.x, y: this.y});
|
||||
var xAxis = {x: width, y: 0},
|
||||
current = {x: center.x - this.getOriginX(), y: center.y - this.getOriginY()},
|
||||
alpha = angle( xAxis, current );
|
||||
this.directionX = 0.01;
|
||||
this.directionY = alpha;
|
||||
$(this)[0].center = center;
|
||||
$(this)[0].width = width;
|
||||
}
|
||||
|
||||
this.directionY = this.directionY - this.directionX;
|
||||
if( Math.abs(this.directionY) > 2 * Math.PI ) {
|
||||
this.directionY = 0;
|
||||
}
|
||||
center.y = center.y + 0.1;
|
||||
_this.center = center;
|
||||
this.x = center.x + width * Math.cos(this.directionY);
|
||||
this.y = center.y + width * Math.sin(this.directionY);
|
||||
}
|
||||
},
|
||||
|
||||
sinusoid : {
|
||||
init : function (x, y) {
|
||||
return {directionX : 1, directionY : 1};
|
||||
},
|
||||
move : function () {
|
||||
var offset = this.width / 2;
|
||||
if (Math.abs((this.getOriginX() - this.getX())) >= offset) {
|
||||
this.directionX *= -1;
|
||||
}
|
||||
|
||||
if( Math.abs(this.getOriginY() - this.getY()) >= 3 * this.height ) {
|
||||
this.directionY *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*** Move - end ***/
|
||||
|
||||
|
||||
/*** Waves ***/
|
||||
|
||||
var WAVES = [
|
||||
{
|
||||
wave : [
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ]
|
||||
],
|
||||
move : MOVE.translation,
|
||||
bonus : [40, 20]
|
||||
},
|
||||
{
|
||||
wave : [ [ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ]
|
||||
],
|
||||
move : MOVE.mirror,
|
||||
bonus : [30, 15]
|
||||
},
|
||||
{
|
||||
wave : [ [ undefined, undefined, ALIENS.alien1, undefined, undefined, undefined, undefined, undefined, ALIENS.alien1, undefined, undefined ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, undefined, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ undefined, undefined, ALIENS.alien1, undefined, undefined, undefined, undefined, undefined, ALIENS.alien1, undefined, undefined ]
|
||||
],
|
||||
move : MOVE.half_part_rotation,
|
||||
bonus : [20, 10]
|
||||
},
|
||||
{
|
||||
wave : [
|
||||
[ undefined, undefined, undefined, undefined, ALIENS.alien1, undefined, undefined, undefined, undefined ],
|
||||
[ undefined, undefined, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, undefined, undefined ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, undefined, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1 ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined ],
|
||||
[ undefined, undefined, undefined, ALIENS.alien1, ALIENS.alien1, ALIENS.alien1, undefined, undefined, undefined ],
|
||||
[ undefined, undefined, undefined, undefined, ALIENS.alien1, undefined, undefined, undefined, undefined ]
|
||||
],
|
||||
move : MOVE.rotation,
|
||||
bonus : [25, 12]
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
/*** Waves - end ***/
|
||||
140
demo/sis/js/models/weapons.js
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var WEAPONS = {
|
||||
SHOTGUN : {
|
||||
directionY : -1,
|
||||
rof : 200,
|
||||
ror : 1500,
|
||||
load : 2,
|
||||
max_load : 2,
|
||||
width : 3,
|
||||
height : 3,
|
||||
clazz : "Shotgun"
|
||||
},
|
||||
CAROT : {
|
||||
directionY : -1,
|
||||
stock : 10,
|
||||
clazz : "carot",
|
||||
load : 5,
|
||||
max_load : 5,
|
||||
width : 5,
|
||||
height : 10
|
||||
},
|
||||
CORN : {
|
||||
directionY : -1,
|
||||
stock : 3,
|
||||
clazz : "corn",
|
||||
load : 1,
|
||||
max_load : 1,
|
||||
callback : function(shot) {
|
||||
var mediumAlien = getAliensMidHeight();
|
||||
|
||||
if( shot.y() < mediumAlien ) {
|
||||
var x = shot.x(),
|
||||
y = shot.y(),
|
||||
explosion = EXPLOSIONS.SMALL[0];
|
||||
$("#shipShots").addSprite("cornExplosion", {width: explosion.width, height: explosion.height, posx: x - explosion.width / 2, posy: y - explosion.height / 2});
|
||||
explosionSmall($("#cornExplosion"), function() {$("#cornExplosion").remove()});
|
||||
shot.remove();
|
||||
|
||||
var shipShots = $("#shipShots");
|
||||
for( var i = 0; i < 8; i++) {
|
||||
var cos = Math.cos( (Math.PI / 4) * i ),
|
||||
sin = Math.sin( (Math.PI / 4) * i);
|
||||
if( Math.abs(cos) < 0.01 ) {
|
||||
cos = 0;
|
||||
}
|
||||
if( Math.abs(sin) < 0.01) {
|
||||
sin = 0;
|
||||
}
|
||||
shipShots.addSprite( "shotCorn" + i, { posx : x + 5 * cos, posy : y + 5 * sin, width: 2, height: 2});
|
||||
var shotCorn = $("#shotCorn" + i);
|
||||
shotCorn.addClass("shipShot").addClass("shotCorn");
|
||||
$("#shotCorn" + i)[0].weapon = $.extend({
|
||||
directionX : cos < 0 ? -1 : cos > 0 ? 1 : 0,
|
||||
directionY : sin < 0 ? -1 : sin > 0 ? 1 : 0,
|
||||
speed : 1
|
||||
}, shot.weapon);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ALIEN : {
|
||||
directionY : 1,
|
||||
width : 5,
|
||||
height : 10
|
||||
}
|
||||
}
|
||||
|
||||
function Weapon(type) {
|
||||
"use strict";
|
||||
this.directionY = type.directionY || 1;
|
||||
this.directionX = type.directionX || 0;
|
||||
this.width = type.width;
|
||||
this.height = type.height;
|
||||
this.speed = type.speed || 5;
|
||||
this.strenght = type.strength || 10;
|
||||
this.stock = type.stock || Infinity;
|
||||
this.rof = type.rof || 300;
|
||||
this.ror = type.ror || 1500;
|
||||
this.load = type.load || 1;
|
||||
this.max_load = type.max_load || 1;
|
||||
this.animation = type.animation;
|
||||
this.clazz = type.clazz || "default";
|
||||
this.callback = type.callback;
|
||||
|
||||
}
|
||||
|
||||
Weapon.prototype = {
|
||||
speed : 5,
|
||||
strength : 10,
|
||||
stock: Infinity,
|
||||
rof : 300,
|
||||
ror : 1500,
|
||||
load : 1,
|
||||
max_load : 1,
|
||||
width : 5,
|
||||
height : 5,
|
||||
shot_timer : false,
|
||||
reload_timer : false,
|
||||
directionX : 0,
|
||||
directionY : 1,
|
||||
animation : null,
|
||||
clazz : "default",
|
||||
callback : undefined,
|
||||
|
||||
fire : function() {
|
||||
if (this.shot_timer || this.load <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var _this = this;
|
||||
this.load = Math.max(0,this.load - 1);
|
||||
this.shot_timer = setInterval(function() {
|
||||
if (_this.load > 0) {
|
||||
clearTimeout(_this.shot_timer);
|
||||
_this.shot_timer = false;
|
||||
}
|
||||
}, this.rof);
|
||||
|
||||
if( !this.reload_timer) {
|
||||
this.reload_timer = setInterval( function() {
|
||||
_this.load = Math.min(_this.load + 1, Math.min(_this.max_load, _this.stock));
|
||||
if( _this.load == _this.max_load ) {
|
||||
clearInterval(_this.reload_timer);
|
||||
_this.reload_timer = false;
|
||||
}
|
||||
}, this.ror);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
54
demo/sis/js/scoreboard.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var SCOREBOARD = {
|
||||
score: 0,
|
||||
scoreLength: 6,
|
||||
|
||||
init: function(size) {
|
||||
if( typeof size !== "undefined" )
|
||||
SCOREBOARD.scoreLength = size;
|
||||
SCOREBOARD.score = 0;
|
||||
SCOREBOARD.set_score( 0 );
|
||||
},
|
||||
|
||||
add: function(addToScore, div) {
|
||||
SCOREBOARD.set_score( SCOREBOARD.score + addToScore, div);
|
||||
},
|
||||
|
||||
set_score: function( score, div ) {
|
||||
var currentScore = "";
|
||||
var imageScore = "";
|
||||
|
||||
SCOREBOARD.score = score;
|
||||
currentScore = SCOREBOARD.pad();
|
||||
|
||||
for(i = 0; i < String(currentScore).length; i++) {
|
||||
imageScore += "<div class='clock n"+ String(currentScore)[i]+"'></div>";
|
||||
}
|
||||
|
||||
if( typeof div === "undefined" )
|
||||
div = $(".subScoreboard");
|
||||
div.empty();
|
||||
div.append( imageScore );
|
||||
},
|
||||
|
||||
pad: function() {
|
||||
var str = '' + SCOREBOARD.score;
|
||||
while (str.length < SCOREBOARD.scoreLength) {
|
||||
str = '0' + str;
|
||||
}
|
||||
return str;
|
||||
},
|
||||
|
||||
callback: function() {
|
||||
console.log( "SCOREBOARD.callback" );
|
||||
}
|
||||
};
|
||||
318
demo/sis/js/spaceinvaders-core.js
Normal file
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Game = {
|
||||
running : false,
|
||||
wave_index : -1,
|
||||
wave : undefined,
|
||||
aliens : [],
|
||||
ship : null,
|
||||
score : 0,
|
||||
shots : {
|
||||
total : 0,
|
||||
lost : 0
|
||||
},
|
||||
|
||||
init : function() {
|
||||
"use strict";
|
||||
animations = WORLD.farm;
|
||||
Game.wave_index = Game.wave_index + 1;
|
||||
Game.wave = WAVES[Math.min(Game.wave_index, WAVES.length - 1)];
|
||||
Game.wave.score = 0;
|
||||
|
||||
var row, col, wave = Game.wave.wave;
|
||||
|
||||
for (row = 0; row < wave.length; row = row + 1) {
|
||||
var alien_width_avg = 0,
|
||||
aliens_row = wave[row],
|
||||
offset = 0;
|
||||
|
||||
for (col = 0; col < aliens_row.length; col = col + 1) {
|
||||
var current_width = typeof aliens_row[col] !== "undefined" ? aliens_row[col].animation.width : ALIENS_TYPE[2].width;
|
||||
alien_width_avg = alien_width_avg + current_width;
|
||||
}
|
||||
|
||||
alien_width_avg = alien_width_avg / aliens_row.length;
|
||||
offset = (PLAYGROUND_WIDTH - (aliens_row.length * 1.5 - 0.5) * alien_width_avg) / 2;
|
||||
|
||||
for (col = 0; col < aliens_row.length; col = col + 1) {
|
||||
Game.setAlien(col, row, offset, alien_width_avg, aliens_row[col], Game.wave.move);
|
||||
}
|
||||
}
|
||||
|
||||
SCOREBOARD.init();
|
||||
SCOREBOARD.set_score( Game.score );
|
||||
|
||||
updateLevel(Game.wave_index + 1);
|
||||
|
||||
Game.setShip();
|
||||
|
||||
hideModal();
|
||||
Game.running = true;
|
||||
},
|
||||
|
||||
game_over : function() {
|
||||
displayModal( {
|
||||
end: "Loose",
|
||||
score: Game.score
|
||||
});
|
||||
},
|
||||
|
||||
levelComplete : function() {
|
||||
"use strict";
|
||||
Game.running = false;
|
||||
var bonus = Math.round(((Game.shots.total - Game.shots.lost) / Game.shots.total) * Game.wave.score),
|
||||
wave_score = Game.wave.score;
|
||||
Game.addToScore(bonus);
|
||||
|
||||
displayModal( {
|
||||
bonus: bonus,
|
||||
wave_score: wave_score,
|
||||
score: Game.score,
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
Game.init();
|
||||
}, 5000);
|
||||
},
|
||||
|
||||
hit : function() {
|
||||
"use strict";
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var health = Game.ship.hit();
|
||||
$(".alienShot").remove();
|
||||
$(".shipShot").remove();
|
||||
$("#life" + Game.ship.lives).remove();
|
||||
Game.running = false;
|
||||
$("#hero").children().hide();
|
||||
|
||||
if( Game.ship.lives > 0 ) {
|
||||
var _this = Game.ship;
|
||||
setTimeout(function() {
|
||||
Game.ship.respawn();
|
||||
Game.running = true;
|
||||
}, 5000);
|
||||
}
|
||||
else {
|
||||
Game.game_over();
|
||||
}
|
||||
},
|
||||
|
||||
setAlien : function(x, y, offset, width, type, move) {
|
||||
"use strict";
|
||||
if( typeof type === "undefined" ) {
|
||||
return;
|
||||
}
|
||||
var id = Game.aliens.length + 1,
|
||||
alien = new Alien("alien" + id, {
|
||||
x : offset + x * width * 1.5,
|
||||
y : START_Y + (y * 1.25 * type.animation.height)
|
||||
}, move.move, type),
|
||||
directions = move.init( alien.x, alien.y );
|
||||
alien.directionX = directions.directionX;
|
||||
alien.directionY = directions.directionY;
|
||||
$("#actors").addSprite("alien" + id, $.extend({posx : alien.x, posy : alien.y}, alien.animation));
|
||||
alien.node = $("#alien" + id);
|
||||
alien.node.addClass("alien");
|
||||
$("#alien" + id)[0].alien = alien;
|
||||
Game.aliens.push(alien);
|
||||
},
|
||||
|
||||
setShip : function() {
|
||||
Game.ship = new Ship("ship", {
|
||||
x : $("#hero").x(),
|
||||
y : $("#hero").y()
|
||||
}, 3, animations.hero.ship.animation);
|
||||
var hero = $("#hero");
|
||||
$.each(animations.hero,
|
||||
function(id, obj){
|
||||
hero.addSprite(id, obj);
|
||||
});
|
||||
Game.ship.node = $("#hero");
|
||||
},
|
||||
|
||||
addToScore : function( toAdd ) {
|
||||
Game.score = Game.score + toAdd;
|
||||
Game.wave.score = Game.wave.score + toAdd;
|
||||
SCOREBOARD.add( toAdd );
|
||||
},
|
||||
|
||||
control : function() {
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).keyup(function(e){
|
||||
switch(e.keyCode) {
|
||||
case 37:
|
||||
e.preventDefault();
|
||||
Game.ship.left(false);
|
||||
break;
|
||||
case 39:
|
||||
e.preventDefault();
|
||||
Game.ship.right(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
$(document).keydown(function(e){
|
||||
switch(e.keyCode) {
|
||||
case 37:
|
||||
e.preventDefault();
|
||||
Game.ship.left(true);
|
||||
break;
|
||||
case 39:
|
||||
e.preventDefault();
|
||||
Game.ship.right(true);
|
||||
break;
|
||||
case 32:
|
||||
e.preventDefault();
|
||||
Game.ship.fire($("#shipShots"), "shipShot");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
alienControl : function() {
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$.each(Game.aliens, function(index, alien ) {
|
||||
alien.move();
|
||||
var node = alien.node;
|
||||
if( (node.y() + node.h()) > $("#hero").y() ) {
|
||||
Game.running = false;
|
||||
Game.game_over();
|
||||
return false;
|
||||
}
|
||||
if( alien.health > 0 && Math.random() < (alien.aggression * (Game.wave_index + 1)) ) {
|
||||
alien.fire($("#aliensShots"), "alienShot");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
heroShotCollision : function() {
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var shots = $(".shipShot");
|
||||
if( shots.length == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
shots.each(function(i,e) {
|
||||
var posy = $(this).y(),
|
||||
posx = $(this).x(),
|
||||
weapon = $(this)[0].weapon;
|
||||
|
||||
// Lost shots
|
||||
if( posy < -$(this).height() || posy > PLAYGROUND_HEIGHT || posx < -$(this).width() || posx > PLAYGROUND_WIDTH ) {
|
||||
Game.shots.lost = Game.shots.lost + 1;
|
||||
this.remove();
|
||||
return;
|
||||
}
|
||||
$(this).y(weapon.directionY * weapon.speed, true);
|
||||
$(this).x(weapon.directionX * weapon.speed, true);
|
||||
|
||||
if( weapon.callback ) {
|
||||
weapon.callback($(this));
|
||||
} else {
|
||||
// Shots collisions
|
||||
var collisions = $(this).collision(".alien,."+$.gQ.groupCssClass);
|
||||
collisions.each( function() {
|
||||
var alien = $(this)[0],
|
||||
alienX = alien.alien.x,
|
||||
alienY = alien.alien.y,
|
||||
alienWidth = alien.alien.width,
|
||||
alienHeight = alien.alien.height;
|
||||
|
||||
alien.alien.hit();
|
||||
Game.aliens = $.grep( Game.aliens, function( elementOfArray, index) {
|
||||
return elementOfArray.health == 0 && elementOfArray.id == alien.id;
|
||||
}, true);
|
||||
var remainingAliens = $(".alien").length;
|
||||
if( remainingAliens == Game.wave.bonus[0] || remainingAliens == Game.wave.bonus[1] ) {
|
||||
Game.bonus(alienX, alienY, alienWidth, alienHeight);
|
||||
}
|
||||
});
|
||||
if( collisions.length > 0 ) {
|
||||
this.remove()
|
||||
}
|
||||
|
||||
if( Game.aliens.length == 0 ) {
|
||||
Game.running = false;
|
||||
Game.levelComplete();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
bonusCollision : function() {
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$(".bonus").each(function(i,e) {
|
||||
var collisions = $(this).collision("#ship,."+$.gQ.groupCssClass);
|
||||
var bonus = $(this)[0].bonus;
|
||||
if( collisions.length > 0 ) {
|
||||
if( bonus.type === "weapon" ) {
|
||||
Game.ship.weapon = new Weapon(bonus.clazz);
|
||||
$("#current_weapon").setAnimation(bonus.animation.animation);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
bonus : function(alienX, alienY, alienWidth, alienHeight) {
|
||||
var bonus = animations.bonus[Math.round(Math.random() * (animations.bonus.length - 1)) ];
|
||||
var id = Math.round(Math.random() * 10000);
|
||||
$("#actors").addSprite("bonus" + id,
|
||||
$.extend(
|
||||
{
|
||||
posx: alienX + (alienWidth - bonus.animation.width) / 2,
|
||||
posy: alienY
|
||||
}, bonus.animation));
|
||||
$("#bonus" + id).addClass("bonus");
|
||||
$("#bonus" + id)[0].bonus = bonus;
|
||||
},
|
||||
|
||||
alienShotCollision : function() {
|
||||
if( !Game.running ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$(".alienShot").each(function(i,e) {
|
||||
var posy = $(this).y();
|
||||
if( posy > PLAYGROUND_HEIGHT ) {
|
||||
this.remove();
|
||||
return;
|
||||
}
|
||||
var weapon = $(this)[0].weapon;
|
||||
$(this).y(weapon.directionY * weapon.speed, true);
|
||||
$(this).x(weapon.directionX * weapon.speed, true);
|
||||
// var collisions = $(this).collision("#ship,."+$.gQ.groupCssClass);
|
||||
try {
|
||||
var collisions = $(this).collision("#actors,#hero,#ship");
|
||||
if( collisions.length > 0 ) {
|
||||
Game.hit();
|
||||
this.remove();
|
||||
}
|
||||
}catch(e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
226
demo/sis/js/spaceinvaders-ui.js
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*global jQuery */
|
||||
|
||||
var PLAYGROUND_WIDTH = 448,
|
||||
PLAYGROUND_HEIGHT = 544,
|
||||
MODAL_WIDTH = 300,
|
||||
REFRESH_RATE = 15,
|
||||
HUD_HEIGHT = 70,
|
||||
|
||||
ROWS = 5,
|
||||
ALIENS = 11,
|
||||
|
||||
ALIENS_WIDTH = 24,
|
||||
ALIENS_HEIGHT = 17,
|
||||
|
||||
START_Y = 40;
|
||||
|
||||
var animations = WORLD.farm;
|
||||
|
||||
|
||||
function explose( div, explosion, step, callback ) {
|
||||
if( step < explosion.length - 2 ) {
|
||||
div.setAnimation( explosion[step].animation, function() {
|
||||
explose( div, explosion, step + 1, callback );
|
||||
});
|
||||
} else {
|
||||
div.setAnimation( explosion[step].animation, callback);
|
||||
}
|
||||
};
|
||||
|
||||
function explosionBig( div, callback ) {
|
||||
explose(div, EXPLOSIONS.BIG, 0, callback );
|
||||
};
|
||||
|
||||
function explosionSmall( div, callback ) {
|
||||
explose(div, EXPLOSIONS.SMALL, 0, callback );
|
||||
};
|
||||
|
||||
function displayModal(data) {
|
||||
var score = data.score.toString();
|
||||
$.playground()
|
||||
.addGroup( "modal_pane", {width: MODAL_WIDTH, height: data.end ? 190 : 140, posx: (PLAYGROUND_WIDTH - MODAL_WIDTH ) /2, posy: (PLAYGROUND_HEIGHT - (140 ))/2})
|
||||
.addSprite("scoreLbl", {width: 180, height: 32, posx: 10, posy: data.end ? 50 : 10})
|
||||
.addSprite("scoreNbr", {width: score.length * 32, height: 32, posx: (MODAL_WIDTH - 10 - score.length * 32), posy: data.end ? 50 : 10})
|
||||
.end();
|
||||
if( data.end ) {
|
||||
var width = (data.end.length - 1 ) * 16 + 32;
|
||||
$("#modal_pane").addSprite("gameSt", {width: width, height: 32, posx: (MODAL_WIDTH - width) / 2, posy: 10});
|
||||
$("#gameSt").append(data.end).lettering();
|
||||
}
|
||||
|
||||
if( data.bonus ) {
|
||||
var bonus = data.bonus.toString(),
|
||||
total = data.wave_score.toString();
|
||||
$("#modal_pane")
|
||||
.addSprite("totalLbl", {width: 180, height: 32, posx: 10, posy: data.end ? 130 : 90})
|
||||
.addSprite("totalNbr", {width: total.length * 32, height: 32, posx: (MODAL_WIDTH - 10 - total.length * 32), posy: data.end ? 130 : 90})
|
||||
.addSprite("bonusLbl", {width: 180, height: 32, posx: 10, posy: data.end ? 90 : 50})
|
||||
.addSprite("bonusNbr", {width: bonus.length * 32, height: 32, posx: (MODAL_WIDTH - 10 - bonus.length * 32), posy: data.end ? 90 : 50})
|
||||
;
|
||||
$("#totalLbl").append("Wave").lettering();
|
||||
$("#totalNbr").append(total).lettering();
|
||||
$("#bonusLbl").append("Bonus").lettering();
|
||||
$("#bonusNbr").append(bonus).lettering();
|
||||
}
|
||||
|
||||
$("#modal_pane").addClass( "modal" );
|
||||
$("#scoreLbl").append("Score").lettering();
|
||||
$("#scoreNbr").append(score).lettering();
|
||||
}
|
||||
|
||||
function hideModal() {
|
||||
$("#modal_pane").remove();
|
||||
}
|
||||
|
||||
function updateWeaponLoad( load ) {
|
||||
"use strict";
|
||||
var HTMLDiv = $("#weapon_load");
|
||||
HTMLDiv.removeClass().addClass("weapon_level");
|
||||
if( load > 2/3) {
|
||||
HTMLDiv.addClass("good");
|
||||
} else {
|
||||
if( load > 1/3) {
|
||||
HTMLDiv.addClass("middle");
|
||||
} else {
|
||||
HTMLDiv.addClass("bad");
|
||||
}
|
||||
}
|
||||
HTMLDiv.width( (load * 100) + "%" );
|
||||
}
|
||||
|
||||
function updateLevel(level) {
|
||||
var strLevel = level.toString();
|
||||
var div = $("#level");
|
||||
div.w(strLevel.length * 32);
|
||||
div.x( PLAYGROUND_WIDTH / 2 - 10 - strLevel.length * 32);
|
||||
div.empty().append(strLevel).lettering();
|
||||
}
|
||||
|
||||
$(function(){
|
||||
"use strict";
|
||||
|
||||
//Playground Sprites
|
||||
$("#playground").playground({height: PLAYGROUND_HEIGHT, width: PLAYGROUND_WIDTH, keyTracker: true});
|
||||
|
||||
$.playground({refreshRate: 60})
|
||||
.addGroup("background", {posx: 0, posy: HUD_HEIGHT, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.addSprite( "background1", {animation: animations.backgrounds.farm.background1.animation, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.addSprite( "background2", {animation: animations.backgrounds.farm.background2.animation, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.addSprite("ground", {posx: 0, posy : PLAYGROUND_HEIGHT - HUD_HEIGHT - 20, width: PLAYGROUND_WIDTH, height: 20})
|
||||
.end()
|
||||
.addGroup("actors", {posx: 0, posy: HUD_HEIGHT, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.addGroup("hero", {
|
||||
width: 48,
|
||||
height: 60,
|
||||
posx: (PLAYGROUND_WIDTH - 48) / 2,
|
||||
posy: PLAYGROUND_HEIGHT - HUD_HEIGHT - 50
|
||||
})
|
||||
.end()
|
||||
/* .addSprite("alienA", $.extend({posx : 50, posy : 300}, ALIENS[0]))
|
||||
.addSprite("alienB", $.extend({posx : 50, posy : 400}, ALIENS[1]))
|
||||
.addSprite("alienC", $.extend({posx : 50, posy : 500}, ALIENS[2]))
|
||||
*/ .addSprite("explosion", {
|
||||
width: 64,
|
||||
height: 64,
|
||||
posx: 100,
|
||||
posy: 100
|
||||
})
|
||||
.end()
|
||||
.addGroup( "shipShots", {posx: 0, posy: HUD_HEIGHT, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.end()
|
||||
.addGroup( "aliensShots", {posx: 0, posy: HUD_HEIGHT, width: PLAYGROUND_WIDTH, height: PLAYGROUND_HEIGHT - HUD_HEIGHT})
|
||||
.end()
|
||||
.addGroup( "hud", {width: PLAYGROUND_WIDTH, height: HUD_HEIGHT, posx: 0, posy: 0})
|
||||
.addSprite( "current_weapon", $.extend({posx: 10, posy: 40}, animations.weapons.gun))
|
||||
.addGroup("weapon_bar", {
|
||||
posx : 50,
|
||||
posy : 40,
|
||||
width : 100,
|
||||
height : 10
|
||||
})
|
||||
.addSprite("weapon_load", {
|
||||
width : 100,
|
||||
height : 10
|
||||
})
|
||||
.end()
|
||||
.addGroup("scoreboard", {
|
||||
posx: 10,
|
||||
posy: 2,
|
||||
width: 6 * 32,
|
||||
height: 32
|
||||
})
|
||||
.addSprite( "subScoreboard", {
|
||||
width: 6 * 32,
|
||||
height: 32
|
||||
})
|
||||
.end()
|
||||
.addGroup("lives", {
|
||||
posx: PLAYGROUND_WIDTH - 100,
|
||||
posy: 32,
|
||||
width: 100,
|
||||
height: 32
|
||||
})
|
||||
.addSprite("life2", animations.life)
|
||||
.addSprite("life1", $.extend({posx: 32}, animations.life))
|
||||
.addSprite("life0", $.extend({posx: 64}, animations.life))
|
||||
.end()
|
||||
.addGroup("levelGrp", {
|
||||
posx: PLAYGROUND_WIDTH / 2,
|
||||
posy: 2,
|
||||
width: PLAYGROUND_WIDTH / 2,
|
||||
height: 16
|
||||
})
|
||||
.addSprite("levelLbl", {
|
||||
width: 32 + 5 * 16,
|
||||
posx: 10
|
||||
})
|
||||
.addSprite("level", {
|
||||
width : 64,
|
||||
posx: 32 + 7 * 16,
|
||||
height: 32
|
||||
})
|
||||
.end()
|
||||
.end()
|
||||
;
|
||||
|
||||
$("#ground").css("background-color", "brown");
|
||||
$("#levelLbl").append("Level").lettering();
|
||||
$("#level").append("0").lettering();
|
||||
$("#scoreboard").addClass("scoreboard");
|
||||
$("#subScoreboard").addClass("subScoreboard");
|
||||
var hud = $("#hud");
|
||||
|
||||
// Controls
|
||||
$.playground().registerCallback(Game.control, REFRESH_RATE);
|
||||
$.playground().registerCallback(Game.alienControl, REFRESH_RATE);
|
||||
|
||||
// Collisions management
|
||||
$.playground().registerCallback(Game.bonusCollision, REFRESH_RATE);
|
||||
$.playground().registerCallback(Game.heroShotCollision, REFRESH_RATE);
|
||||
$.playground().registerCallback(Game.alienShotCollision, REFRESH_RATE);
|
||||
|
||||
// Refresh playground
|
||||
$.playground().registerCallback(function(){
|
||||
updateWeaponLoad(Game.ship.weapon.load / Game.ship.weapon.max_load);
|
||||
if( Game.running ) {
|
||||
Game.ship.move();
|
||||
$(".bonus").each( function(index, bonus) {
|
||||
var posy = $(this).y();
|
||||
if( posy < Game.ship.y + 10 ) {
|
||||
$(this).y(3, true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
}, REFRESH_RATE);
|
||||
});
|
||||
83
demo/sis/js/tools.js
Normal file
@@ -0,0 +1,83 @@
|
||||
function heriter(destination, source) {
|
||||
function initClassIfNecessary(obj) {
|
||||
if( typeof obj["_super"] == "undefined" ) {
|
||||
obj["_super"] = function() {
|
||||
var methodName = arguments[0];
|
||||
var parameters = arguments[1];
|
||||
return this["__parent_methods"][methodName].apply(this, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
if( typeof obj["__parent_methods"] == "undefined" ) {
|
||||
obj["__parent_methods"] = {};
|
||||
}
|
||||
}
|
||||
|
||||
for (var element in source) {
|
||||
if( typeof destination[element] != "undefined" ) {
|
||||
initClassIfNecessary(destination);
|
||||
destination["__parent_methods"][element] = source[element];
|
||||
} else {
|
||||
destination[element] = source[element];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function distance(point1, point2) {
|
||||
return Math.sqrt(Math.pow(point2.x - point1.x, 2) + Math.pow(point2.y - point1.y, 2));
|
||||
}
|
||||
|
||||
function normalize(vector) {
|
||||
var norm = Math.sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||
if (norm == 0)
|
||||
return {
|
||||
x : 0,
|
||||
y : 0
|
||||
};
|
||||
|
||||
var x = vector.x / norm;
|
||||
var y = vector.y / norm;
|
||||
return {
|
||||
x : x,
|
||||
y : y
|
||||
}
|
||||
}
|
||||
|
||||
function angle(vector1, vector2) {
|
||||
if ((vector1.x == 0 && vector1.y == 0)
|
||||
&& (vector1.x == 0 && vector1.y == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vector1.x == 0 && vector1.y == 0) {
|
||||
return Math.acos(vector2.x
|
||||
/ Math.sqrt(vector2.x * vector2.x + vector2.y * vector2.y));
|
||||
}
|
||||
|
||||
if (vector2.x == 0 && vector2.y == 0) {
|
||||
return Math.acos(vector1.x
|
||||
/ Math.sqrt(vector1.x * vector1.x + vector1.y * vector1.y));
|
||||
}
|
||||
|
||||
var product = vector1.x * vector2.x + vector1.y * vector2.y,
|
||||
alpha = Math.acos(product
|
||||
/ (Math.sqrt(vector1.x * vector1.x + vector1.y * vector1.y) * Math
|
||||
.sqrt(vector2.x * vector2.x + vector2.y * vector2.y))),
|
||||
sign = normalize(vector1).y > normalize(vector2).y ? -1 : 1;
|
||||
|
||||
return sign * alpha;
|
||||
}
|
||||
|
||||
|
||||
function getAliensMidHeight() {
|
||||
var higherAlien = Math.max.apply( null,
|
||||
$(".alien").map(function() {
|
||||
return $(this).y();
|
||||
}).get() ),
|
||||
lowerAlien = Math.min.apply( null,
|
||||
$(".alien").map(function() {
|
||||
return $(this).y();
|
||||
}).get() );
|
||||
|
||||
return (higherAlien + lowerAlien) / 2;
|
||||
}
|
||||