Skip to content

Commit

Permalink
Gestures gestures gestures gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
Nushio committed Nov 7, 2012
1 parent 13cd39f commit f24cd09
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Unsealed/src/net/k3rnel/unsealed/DesktopLauncher.java
Expand Up @@ -30,7 +30,7 @@ public static void main( String[] args ) {
ApplicationListener listener = new Unsealed();

// define the window's title
String title = "Unsealed: Whispers of Wisdom (v1.1.1)";
String title = "Unsealed: Whispers of Wisdom (v1.1.2)";

// define the window's size
int width = 800, height = 480;
Expand Down
115 changes: 114 additions & 1 deletion Unsealed/src/net/k3rnel/unsealed/screens/BattleScreen.java
Expand Up @@ -63,6 +63,7 @@
import net.k3rnel.unsealed.story.MapCharacter;
import net.k3rnel.unsealed.story.StyledTable;
import net.k3rnel.unsealed.story.TextBox;
import net.k3rnel.unsealed.utils.SimpleDirectionGestureDetector;

public class BattleScreen extends AbstractScreen {

Expand Down Expand Up @@ -103,13 +104,60 @@ public class BattleScreen extends AbstractScreen {

public boolean disableInput = false;

// Touchpad touchpad;
// public int touchpad1Direction;
// Touchpad touchpad2;

public BattleScreen(Unsealed game, boolean scriptedBattle, String mapname) {
super(game);
if(scriptedBattle){
this.scriptedBattle = true;
act = 0;
}
this.mapname = mapname;
// touchpad = new Touchpad(0, getSkin());
// touchpad.setBounds(15, 30, 150, 150);
// touchpad1Direction = -1;
// touchpad.addListener(new ChangeListener(){
//
// @Override
// public void changed(ChangeEvent event, Actor actor) {
// System.out.println("x="+touchpad.getKnobX()+", y="+touchpad.getKnobY());
// if(touchpad.getKnobX()<55&&touchpad.getKnobY()<108&&touchpad.getKnobY()>31){
// if(touchpad1Direction!=2){
// System.out.println("Going left!");
// touchpad1Direction=2;
// buttonPress(2, true);
// }
// }else if(touchpad.getKnobX()>90&&touchpad.getKnobY()<108&&touchpad.getKnobY()>31){
//
// if(touchpad1Direction!=3){
// System.out.println("Going right!");
// touchpad1Direction=3;
// buttonPress(3, true);
// }
// }else if(touchpad.getKnobY()>80&&touchpad.getKnobX()<120&&touchpad.getKnobX()>50){
// if(touchpad1Direction!=0){
// System.out.println("Going up!");
// touchpad1Direction=0;
// buttonPress(0, true);
// }
// }else if(touchpad.getKnobY()<60&&touchpad.getKnobX()<120&&touchpad.getKnobX()>50){
// if(touchpad1Direction!=1){
// System.out.println("Going down!");
// touchpad1Direction=1;
// buttonPress(1, true);
// }
// }else{
// touchpad1Direction=-1;
// }
// }
// });
// stage.addActor(touchpad);
//
// touchpad2 = new Touchpad(20, getSkin());
// touchpad2.setBounds(630, 30, 150, 150);
// stage.addActor(touchpad2);
}
@Override
protected boolean isGameScreen() {
Expand Down Expand Up @@ -345,7 +393,72 @@ public void clicked(InputEvent arg0, float arg1, float arg2) {
Gdx.app.log(Unsealed.LOG,"Started the rest in... "+time);
time = new Date().getTime();
hud.addActor(dialog);
Gdx.input.setInputProcessor(new InputMultiplexer(this,stage,hud));
Gdx.input.setInputProcessor(new InputMultiplexer(this,stage,hud,
new SimpleDirectionGestureDetector(
new SimpleDirectionGestureDetector.UnsealedDirectionListener() {

@Override
public void onUpLeft() {
buttonPress(0,true);

}

@Override
public void onRightLeft() {
buttonPress(3,true);

}

@Override
public void onLeftLeft() {
buttonPress(2,true);

}

@Override
public void onDownLeft() {
buttonPress(1,true);

}
@Override
public void onDownRight() {
buttonPress(7, true);
buttonPress(7, false);

}
@Override
public void onLeftRight() {
buttonPress(6, true);
buttonPress(6, false);

}
@Override
public void onRightRight() {
buttonPress(8, true);
buttonPress(8, false);

}
@Override
public void onUpRight() {
buttonPress(9, true);
buttonPress(9, false);

}
@Override
public void onTapLeft() {
buttonPress(4, true);
buttonPress(4, false);

}
@Override
public void onTapRight() {
buttonPress(5, true);
buttonPress(5, false);

}
})
));

}

public void checkScene(float delta){
Expand Down
142 changes: 142 additions & 0 deletions Unsealed/src/net/k3rnel/unsealed/screens/CharSelectScreen.java
@@ -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;
}
}
2 changes: 1 addition & 1 deletion Unsealed/src/net/k3rnel/unsealed/screens/MenuScreen.java
Expand Up @@ -34,7 +34,7 @@
public class MenuScreen extends AbstractScreen {

private Table table;

public MenuScreen( Unsealed game ) {
super( game );
}
Expand Down
@@ -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);
}
}
}

0 comments on commit f24cd09

Please sign in to comment.