mirror of
https://github.com/ysoftdevs/pf2016.git
synced 2026-03-29 05:22:07 +02:00
level selector with 2 levels
This commit is contained in:
56
index.html
56
index.html
@@ -7,29 +7,11 @@
|
|||||||
<meta name="description" content="PF 2016 greeting - puzzle game - set direction for ball" />
|
<meta name="description" content="PF 2016 greeting - puzzle game - set direction for ball" />
|
||||||
|
|
||||||
<script src="js/kiwi-js-v1.4.0/kiwi.js"></script>
|
<script src="js/kiwi-js-v1.4.0/kiwi.js"></script>
|
||||||
|
<script src="js/app/level-selector.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var levelSelectorState = new Kiwi.State('levelSelector');
|
|
||||||
|
|
||||||
levelSelectorState.preload = function() {
|
|
||||||
this.addSpriteSheet('button', './data/images/gfx64/button.png', 128, 64 );
|
|
||||||
}
|
|
||||||
|
|
||||||
levelSelectorState.create = function() {
|
|
||||||
this.text = new Kiwi.GameObjects.Textfield( this, "Start", 66, 60, "#000", 32, 'normal', 'Impact' );
|
|
||||||
this.sprite = new Kiwi.GameObjects.Sprite(this, this.textures.button, 50, 50);
|
|
||||||
this.sprite.input.onUp.add( this.buttonReleased, this );
|
|
||||||
this.addChild( this.sprite );
|
|
||||||
this.addChild( this.text );
|
|
||||||
}
|
|
||||||
|
|
||||||
levelSelectorState.buttonReleased = function() {
|
|
||||||
game.states.switchState('state');
|
|
||||||
}
|
|
||||||
|
|
||||||
var state = new Kiwi.State('state');
|
var state = new Kiwi.State('state');
|
||||||
|
|
||||||
state.preload = function() {
|
state.preload = function() {
|
||||||
@@ -110,9 +92,6 @@ state.create = function() {
|
|||||||
//Prevent the down key from scrolling the page
|
//Prevent the down key from scrolling the page
|
||||||
this.keyboard.addKey(Kiwi.Input.Keycodes.DOWN, true);
|
this.keyboard.addKey(Kiwi.Input.Keycodes.DOWN, true);
|
||||||
|
|
||||||
this.keyboard.onKeyDownOnce.add(this.keyDownOnce, this);
|
|
||||||
this.keyboard.onKeyUp.add(this.keyUp, this);
|
|
||||||
|
|
||||||
this.stageState = 'init';
|
this.stageState = 'init';
|
||||||
|
|
||||||
this.myButton = new Kiwi.GameObjects.Textfield( this, "Start", 9*64+16, 60, "#000", 32, 'normal', 'Impact' );
|
this.myButton = new Kiwi.GameObjects.Textfield( this, "Start", 9*64+16, 60, "#000", 32, 'normal', 'Impact' );
|
||||||
@@ -123,8 +102,8 @@ state.create = function() {
|
|||||||
this.addChild( this.myButton );
|
this.addChild( this.myButton );
|
||||||
}
|
}
|
||||||
|
|
||||||
state.buttonReleased = function() {
|
state.buttonReleased = function(sprite) {
|
||||||
if (this.stageState == 'init') {
|
if (this.stageState == 'init') {
|
||||||
this.myButton.text = '...';
|
this.myButton.text = '...';
|
||||||
this.activateScene();
|
this.activateScene();
|
||||||
} else if (this.stageState == 'stop') {
|
} else if (this.stageState == 'stop') {
|
||||||
@@ -134,7 +113,6 @@ state.buttonReleased = function() {
|
|||||||
} else if (this.stageState == 'complete') {
|
} else if (this.stageState == 'complete') {
|
||||||
game.states.switchState('levelSelector');
|
game.states.switchState('levelSelector');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state.resetCharacter = function () {
|
state.resetCharacter = function () {
|
||||||
@@ -277,34 +255,8 @@ state.updateCharacterMovement = function () {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//When the key is pressed
|
|
||||||
state.keyDownOnce = function(keyCode, key) {
|
|
||||||
if( keyCode === this.rightKey.keyCode ){
|
|
||||||
this.rightPressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( keyCode === this.leftKey.keyCode ){
|
|
||||||
this.leftPressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//When the key is released
|
|
||||||
state.keyUp = function(keyCode, key) {
|
|
||||||
|
|
||||||
if( keyCode === this.rightKey.keyCode ){
|
|
||||||
this.rightPressed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( keyCode === this.leftKey.keyCode ){
|
|
||||||
this.leftPressed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var game = new Kiwi.Game(null, 'PF 2016', levelSelectorState);
|
var game = new Kiwi.Game(null, 'PF 2016', levelSelectorState);
|
||||||
|
game.levelIndex = 0;
|
||||||
game.states.addState(state);
|
game.states.addState(state);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
21
js/app/level-selector.js
Normal file
21
js/app/level-selector.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
var levelSelectorState = new Kiwi.State('levelSelector');
|
||||||
|
|
||||||
|
levelSelectorState.preload = function() {
|
||||||
|
this.addSpriteSheet('button', './data/images/gfx64/button.png', 128, 64 );
|
||||||
|
}
|
||||||
|
|
||||||
|
levelSelectorState.create = function() {
|
||||||
|
for (var i=0; i!=2; i++) {
|
||||||
|
var text = new Kiwi.GameObjects.Textfield( this, "Level " + (i+1).toString(), 66+i*140, 60, "#000", 32, 'normal', 'Impact' );
|
||||||
|
var sprite = new Kiwi.GameObjects.Sprite(this, this.textures.button, 50+i*140, 50);
|
||||||
|
sprite.levelIndex = i;
|
||||||
|
sprite.input.onUp.add( this.buttonReleased, this );
|
||||||
|
this.addChild( sprite );
|
||||||
|
this.addChild( text );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
levelSelectorState.buttonReleased = function(sprite) {
|
||||||
|
game.levelIndex = sprite.levelIndex;
|
||||||
|
game.states.switchState('state');
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user