Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
345 additions
and
3 deletions.
There are no files selected for viewing
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
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
142 changes: 142 additions & 0 deletions
142
Unsealed/src/net/k3rnel/unsealed/screens/CharSelectScreen.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* Unsealed: Whispers of Wisdom. | ||
* | ||
* Copyright (C) 2012 - Juan 'Nushio' Rodriguez | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 of | ||
* the License as published by the Free Software Foundation | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
package net.k3rnel.unsealed.screens; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.Input; | ||
import com.badlogic.gdx.InputMultiplexer; | ||
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; | ||
import com.badlogic.gdx.graphics.g2d.TextureRegion; | ||
import com.badlogic.gdx.scenes.scene2d.InputEvent; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Button; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Image; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Label; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Skin; | ||
import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||
import com.badlogic.gdx.scenes.scene2d.utils.Align; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; | ||
import com.badlogic.gdx.utils.Scaling; | ||
|
||
import net.k3rnel.unsealed.Unsealed; | ||
import net.k3rnel.unsealed.story.chapter1.Chapter1_1; | ||
import net.k3rnel.unsealed.story.chapter2.Chapter2_1; | ||
import net.k3rnel.unsealed.story.chapter3.Chapter3_1; | ||
|
||
public class CharSelectScreen extends AbstractScreen { | ||
|
||
private Table table; | ||
|
||
public CharSelectScreen(Unsealed game) { | ||
super(game); | ||
} | ||
|
||
@Override | ||
protected boolean isGameScreen() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void show() { | ||
super.show(); | ||
|
||
// retrieve the custom skin for our 2D widgets | ||
Skin skin = super.getSkin(); | ||
|
||
// create the table actor and add it to the stage | ||
table = super.getTable(); | ||
if(Unsealed.DEBUG) | ||
table.debug(); | ||
table.setWidth(stage.getWidth()); | ||
table.setHeight(stage.getHeight()); | ||
table.pad(10).defaults().spaceBottom(10); | ||
|
||
Label titleLabel = new Label("Select your character", skin); | ||
table.padTop(40); | ||
table.add(titleLabel).expandX().align(Align.center).colspan(4); | ||
table.row(); | ||
table.row(); | ||
table.add(); | ||
Label chapterLabel = new Label("Lidia Terius",skin); | ||
chapterLabel.setAlignment(Align.center); | ||
table.add(chapterLabel).align(Align.center); | ||
chapterLabel = new Label("Lemond Phaunt",skin); | ||
chapterLabel.setAlignment(Align.center); | ||
table.add(chapterLabel).align(Align.center); | ||
table.add(); | ||
table.row(); | ||
AtlasRegion charRegion = getAtlas().findRegion( "char-sprites/lidia_spritesheet" ); | ||
TextureRegion[][] charTextures = charRegion.split(64,64); | ||
|
||
Image chapterImage = new Image(charTextures[2][0]); | ||
chapterImage.setScaling(Scaling.stretch); | ||
chapterImage.scale(1f); | ||
chapterImage.setOrigin(chapterImage.getWidth()/2,chapterImage.getHeight()/2); | ||
Button chapterButton = new Button(skin); | ||
chapterButton.add(chapterImage); | ||
chapterButton.addListener(new ClickListener() { | ||
@Override | ||
public void clicked(InputEvent event, float x, float y) { | ||
game.setScreen( new Chapter1_1( game ) ); | ||
|
||
} | ||
}); | ||
table.add().height(128).width(32); | ||
table.add(chapterButton).height(128).width(128); | ||
charRegion = getAtlas().findRegion( "char-sprites/lidia_spritesheet" ); | ||
charTextures = charRegion.split(64,64); | ||
|
||
Image chap2Screen = new Image(charTextures[2][0]); | ||
chap2Screen.setScaling(Scaling.stretch); | ||
chap2Screen.scale(1f); | ||
chap2Screen.setOrigin(chap2Screen.getWidth()/2,chap2Screen.getHeight()/2); | ||
final Button chap2Button = new Button(skin); | ||
chap2Button.add().left().bottom(); | ||
chap2Button.addListener(new ClickListener() { | ||
|
||
@Override | ||
public void clicked(InputEvent event, float x, float y) { | ||
game.setScreen( new Chapter2_1( game ) ); | ||
|
||
} | ||
}); | ||
chap2Button.size(128,128); | ||
table.add(chap2Button).height(128).width(128); | ||
table.add(); | ||
|
||
|
||
Gdx.input.setInputProcessor(new InputMultiplexer(this,stage)); | ||
} | ||
|
||
/** | ||
* On key press | ||
*/ | ||
@Override | ||
public boolean keyUp(int keycode) { | ||
switch(keycode) { | ||
case Input.Keys.BACK: | ||
game.setScreen(new MenuScreen(game)); | ||
return true; | ||
case Input.Keys.ESCAPE: | ||
game.setScreen(new MenuScreen(game)); | ||
return true; | ||
|
||
} | ||
return false; | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
Unsealed/src/net/k3rnel/unsealed/utils/SimpleDirectionGestureDetector.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package net.k3rnel.unsealed.utils; | ||
|
||
import com.badlogic.gdx.input.GestureDetector; | ||
/** | ||
* @author lycying@gmail.com | ||
*/ | ||
public class SimpleDirectionGestureDetector extends GestureDetector{ | ||
public interface UnsealedDirectionListener{ | ||
void onLeftRight(); | ||
void onRightRight(); | ||
void onUpRight(); | ||
void onDownRight(); | ||
void onTapRight(); | ||
|
||
void onLeftLeft(); | ||
void onRightLeft(); | ||
void onUpLeft(); | ||
void onDownLeft(); | ||
void onTapLeft(); | ||
} | ||
|
||
public SimpleDirectionGestureDetector(UnsealedDirectionListener unsealedDirectionListener) { | ||
super(new DirectionGestureListener(unsealedDirectionListener)); | ||
} | ||
private static class DirectionGestureListener extends GestureAdapter { | ||
UnsealedDirectionListener directionListener; | ||
boolean right; | ||
public DirectionGestureListener(UnsealedDirectionListener directionListener){ | ||
this.directionListener = directionListener; | ||
} | ||
|
||
@Override | ||
public boolean touchDown(float x, float y, int pointer, int button) { | ||
if(x>400){ | ||
right = true; | ||
}else{ | ||
right = false; | ||
} | ||
return super.touchDown(x, y, pointer, button); | ||
} | ||
@Override | ||
public boolean tap(float x, float y, int count, int button) { | ||
if(right){ | ||
directionListener.onTapRight(); | ||
}else{ | ||
directionListener.onTapLeft(); | ||
} | ||
return super.tap(x, y, count, button); | ||
} | ||
@Override | ||
public boolean longPress(float x, float y) { | ||
if(!right) | ||
directionListener.onTapLeft(); | ||
return super.longPress(x, y); | ||
} | ||
@Override | ||
public boolean fling(float velocityX, float velocityY, int button) { | ||
|
||
if(Math.abs(velocityX)>Math.abs(velocityY)){ | ||
if(velocityX>0){ | ||
if(right) | ||
directionListener.onRightRight(); | ||
else | ||
directionListener.onRightLeft(); | ||
}else{ | ||
if(right) | ||
directionListener.onLeftRight(); | ||
else | ||
directionListener.onLeftLeft(); | ||
} | ||
}else{ | ||
if(velocityY>0){ | ||
if(right) | ||
directionListener.onDownRight(); | ||
else | ||
directionListener.onDownLeft(); | ||
}else{ | ||
if(right) | ||
directionListener.onUpRight(); | ||
else | ||
directionListener.onUpLeft(); | ||
} | ||
} | ||
return super.fling(velocityX, velocityY, button); | ||
} | ||
} | ||
} |