Initial commit.
This commit is contained in:
11
core/build.gradle
Normal file
11
core/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.6
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
|
||||
eclipse.project {
|
||||
name = appName + "-core"
|
||||
}
|
188
core/src/com/gamejolt/mikykr5/poukemon/GameCore.java
Normal file
188
core/src/com/gamejolt/mikykr5/poukemon/GameCore.java
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.gamejolt.mikykr5.poukemon;
|
||||
|
||||
import aurelienribon.tweenengine.Tween;
|
||||
import aurelienribon.tweenengine.TweenEquations;
|
||||
import aurelienribon.tweenengine.primitives.MutableFloat;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.gamejolt.mikykr5.poukemon.states.BaseState;
|
||||
import com.gamejolt.mikykr5.poukemon.states.MainMenuState;
|
||||
|
||||
public class GameCore extends Game {
|
||||
private static final String TAG = "GAME_CORE";
|
||||
private static final String CLASS_NAME = GameCore.class.getSimpleName();
|
||||
|
||||
public enum game_states_t {
|
||||
LOGO_SCREEN(0), MAIN_MENU(1), IN_GAME(2), QUIT(3), LOADING(4);
|
||||
|
||||
private int value;
|
||||
|
||||
private game_states_t(int value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static int getNumStates(){
|
||||
return 5;
|
||||
}
|
||||
};
|
||||
|
||||
private game_states_t currState;
|
||||
public game_states_t nextState;
|
||||
private BaseState[] states;
|
||||
|
||||
public SpriteBatch batch;
|
||||
private OrthographicCamera pixelPerfectCamera;
|
||||
|
||||
// Fade in/out effect fields.
|
||||
private Texture fadeTexture;
|
||||
private MutableFloat alpha;
|
||||
private Tween fadeOut;
|
||||
private Tween fadeIn;
|
||||
private boolean fading;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
// Set up rendering fields and settings.
|
||||
ShaderProgram.pedantic = false;
|
||||
batch = new SpriteBatch();
|
||||
batch.enableBlending();
|
||||
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
|
||||
// Prepare the fading effect.
|
||||
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
|
||||
pixmap.setColor(0, 0, 0, 1);
|
||||
pixmap.fill();
|
||||
fadeTexture = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
|
||||
alpha = new MutableFloat(0.0f);
|
||||
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
||||
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
||||
fading = false;
|
||||
|
||||
// Create application states.
|
||||
states = new BaseState[game_states_t.getNumStates()];
|
||||
|
||||
try{
|
||||
states[game_states_t.MAIN_MENU.getValue()] = new MainMenuState(this);
|
||||
}catch(IllegalArgumentException e){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the current and next states.
|
||||
currState = game_states_t.MAIN_MENU;
|
||||
nextState = null;
|
||||
this.setScreen(states[currState.getValue()]);
|
||||
states[currState.getValue()].onStateEnabled();
|
||||
|
||||
// Set initial input handler.
|
||||
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
||||
|
||||
// Set log level
|
||||
if(ProjectConstants.DEBUG){
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
}else{
|
||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
super.render();
|
||||
|
||||
// If the current state set a value for nextState then switch to that state.
|
||||
if(nextState != null){
|
||||
states[currState.getValue()].onStateDisabled();
|
||||
|
||||
if(!fadeOut.isStarted()){
|
||||
// Start the fade out effect.
|
||||
fadeOut.start();
|
||||
fading = true;
|
||||
}else{
|
||||
// Update the fade out effect.
|
||||
fadeOut.update(Gdx.graphics.getDeltaTime());
|
||||
|
||||
// When the fade out effect finishes, change to the requested state and launch the fade in effect.
|
||||
if(fadeOut.isFinished()){
|
||||
// Change to the requested state.
|
||||
if(nextState != game_states_t.QUIT){
|
||||
currState = nextState;
|
||||
nextState = null;
|
||||
states[currState.getValue()].onStateEnabled();
|
||||
setScreen(states[currState.getValue()]);
|
||||
}else{
|
||||
nextState = null;
|
||||
Gdx.app.exit();
|
||||
}
|
||||
|
||||
// Reset the fade out effect and launch the fade in.
|
||||
fadeOut.free();
|
||||
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
||||
fadeIn.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a fade in effect in progress.
|
||||
if(fadeIn.isStarted()){
|
||||
if(!fadeIn.isFinished()){
|
||||
// Update it until finished.
|
||||
fadeIn.update(Gdx.graphics.getDeltaTime());
|
||||
}else{
|
||||
// Stop and reset it when done.
|
||||
fading = false;
|
||||
fadeIn.free();
|
||||
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
||||
}
|
||||
}
|
||||
|
||||
// Render the fading sprite with alpha blending.
|
||||
if(fading){
|
||||
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
batch.begin();{
|
||||
batch.setColor(1, 1, 1, alpha.floatValue());
|
||||
batch.draw(fadeTexture, -(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
||||
batch.setColor(1, 1, 1, 1);
|
||||
}batch.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
super.dispose();
|
||||
|
||||
fadeTexture.dispose();
|
||||
}
|
||||
}
|
28
core/src/com/gamejolt/mikykr5/poukemon/ProjectConstants.java
Normal file
28
core/src/com/gamejolt/mikykr5/poukemon/ProjectConstants.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.gamejolt.mikykr5.poukemon;
|
||||
|
||||
public abstract class ProjectConstants{
|
||||
public static final int EXIT_SUCCESS = 0;
|
||||
public static final int EXIT_FAILURE = 1;
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
||||
|
||||
public static final int MENU_BUTTON_FONT_SIZE = 40;
|
||||
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:,";
|
||||
}
|
135
core/src/com/gamejolt/mikykr5/poukemon/states/BaseState.java
Normal file
135
core/src/com/gamejolt/mikykr5/poukemon/states/BaseState.java
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.gamejolt.mikykr5.poukemon.states;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.gamejolt.mikykr5.poukemon.GameCore;
|
||||
|
||||
public abstract class BaseState implements Screen, InputProcessor{
|
||||
protected GameCore core;
|
||||
protected boolean stateEnabled;
|
||||
protected OrthographicCamera pixelPerfectCamera;
|
||||
protected Vector3 win2world;
|
||||
protected Vector2 touchPointWorldCoords;
|
||||
|
||||
public BaseState(){
|
||||
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||
touchPointWorldCoords = new Vector2();
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;
|
||||
; STATE METHODS ;
|
||||
;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
public void onStateEnabled(){
|
||||
stateEnabled = true;
|
||||
Gdx.input.setInputProcessor(this);
|
||||
Gdx.input.setCatchBackKey(true);
|
||||
Gdx.input.setCatchMenuKey(true);
|
||||
}
|
||||
|
||||
public void onStateDisabled(){
|
||||
stateEnabled = false;
|
||||
Gdx.input.setInputProcessor(null);
|
||||
Gdx.input.setCatchBackKey(false);
|
||||
Gdx.input.setCatchMenuKey(false);
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;
|
||||
; SCREEN METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
@Override
|
||||
public abstract void render(float delta);
|
||||
|
||||
@Override
|
||||
public abstract void dispose();
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height){ }
|
||||
|
||||
@Override
|
||||
public void show(){ }
|
||||
|
||||
@Override
|
||||
public void hide(){ }
|
||||
|
||||
@Override
|
||||
public void pause(){ }
|
||||
|
||||
@Override
|
||||
public void resume(){ }
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;
|
||||
; HELPER METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
protected final void unprojectTouch(int screenX, int screenY){
|
||||
win2world.set(screenX, screenY, 0.0f);
|
||||
pixelPerfectCamera.unproject(win2world);
|
||||
touchPointWorldCoords.set(win2world.x, win2world.y);
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; INPUT PROCESSOR METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean keyUp(int keycode){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char character){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean mouseMoved(int screenX, int screenY){
|
||||
return false;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean scrolled(int amount){
|
||||
return false;
|
||||
};
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.gamejolt.mikykr5.poukemon.states;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
|
||||
public class LogoScreen extends BaseState {
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
264
core/src/com/gamejolt/mikykr5/poukemon/states/MainMenuState.java
Normal file
264
core/src/com/gamejolt/mikykr5/poukemon/states/MainMenuState.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.gamejolt.mikykr5.poukemon.states;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
||||
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
||||
import com.gamejolt.mikykr5.poukemon.GameCore;
|
||||
import com.gamejolt.mikykr5.poukemon.GameCore.game_states_t;
|
||||
import com.gamejolt.mikykr5.poukemon.ProjectConstants;
|
||||
|
||||
public class MainMenuState extends BaseState{
|
||||
private static final String TAG = "MAIN_MENU";
|
||||
private static final String CLASS_NAME = MainMenuState.class.getSimpleName();
|
||||
private static final String SHADER_PATH = "shaders/movingBckg/movingBckg";
|
||||
|
||||
// Helper fields.
|
||||
private float u_scaling[];
|
||||
private float u_displacement;
|
||||
|
||||
// Buttons and other GUI components.
|
||||
private TextButton startButton;
|
||||
private Rectangle startButtonBBox;
|
||||
private TextButton quitButton;
|
||||
private Rectangle quitButtonBBox;
|
||||
private Sprite background;
|
||||
|
||||
// Graphic data for the start button.
|
||||
private Texture menuButtonEnabledTexture;
|
||||
private Texture menuButtonDisabledTexture;
|
||||
private Texture menuButtonPressedTexture;
|
||||
private NinePatch menuButtonEnabled9p;
|
||||
private NinePatch menuButtonDisabled9p;
|
||||
private NinePatch menuButtonPressed9p;
|
||||
private BitmapFont font;
|
||||
|
||||
// Other graphics.
|
||||
private Texture backgroundTexture;
|
||||
private ShaderProgram backgroundShader;
|
||||
|
||||
// Button touch helper fields.
|
||||
private boolean startButtonTouched;
|
||||
private int startButtonTouchPointer;
|
||||
private boolean quitButtonTouched;
|
||||
private int quitButtonTouchPointer;
|
||||
|
||||
public MainMenuState(final GameCore core) throws IllegalArgumentException{
|
||||
super();
|
||||
|
||||
TextButtonStyle textButtonStyle;
|
||||
FreeTypeFontGenerator fontGenerator;
|
||||
FreeTypeFontParameter fontParameters;
|
||||
|
||||
if(core == null)
|
||||
throw new IllegalArgumentException(CLASS_NAME + ": Core is null.");
|
||||
|
||||
this.core = core;
|
||||
|
||||
// Create the start button background.
|
||||
menuButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
||||
menuButtonEnabled9p = new NinePatch(new TextureRegion(menuButtonEnabledTexture, 0, 0, menuButtonEnabledTexture.getWidth(), menuButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
||||
menuButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
||||
menuButtonDisabled9p = new NinePatch(new TextureRegion(menuButtonDisabledTexture, 0, 0, menuButtonDisabledTexture.getWidth(), menuButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
||||
menuButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
||||
menuButtonPressed9p = new NinePatch(new TextureRegion(menuButtonPressedTexture, 0, 0, menuButtonPressedTexture.getWidth(), menuButtonPressedTexture.getHeight()), 49, 49, 45, 45);
|
||||
|
||||
// Create the start button font.
|
||||
fontParameters = new FreeTypeFontParameter();
|
||||
fontParameters.characters = ProjectConstants.FONT_CHARS;
|
||||
fontParameters.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
|
||||
fontParameters.flip = false;
|
||||
fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
||||
font = fontGenerator.generateFont(fontParameters);
|
||||
fontGenerator.dispose();
|
||||
|
||||
// Create the buttons.
|
||||
textButtonStyle = new TextButtonStyle();
|
||||
textButtonStyle.font = font;
|
||||
textButtonStyle.up = new NinePatchDrawable(menuButtonEnabled9p);
|
||||
textButtonStyle.checked = new NinePatchDrawable(menuButtonPressed9p);
|
||||
textButtonStyle.disabled = new NinePatchDrawable(menuButtonDisabled9p);
|
||||
textButtonStyle.fontColor = new Color(Color.BLACK);
|
||||
textButtonStyle.downFontColor = new Color(Color.WHITE);
|
||||
textButtonStyle.disabledFontColor = new Color(Color.BLACK);
|
||||
|
||||
startButton = new TextButton("Start game", textButtonStyle);
|
||||
startButton.setText("Start game");
|
||||
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
|
||||
|
||||
quitButton = new TextButton("Quit", textButtonStyle);
|
||||
quitButton.setText("quit");
|
||||
quitButtonBBox = new Rectangle(0, 0, quitButton.getWidth(), quitButton.getHeight());
|
||||
|
||||
// Set buttons.
|
||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||
quitButton.setPosition(-(quitButton.getWidth() / 2), (startButton.getY() - startButton.getHeight()) - 10);
|
||||
quitButtonBBox.setPosition(quitButton.getX(), quitButton.getY());
|
||||
|
||||
// Set up the background.
|
||||
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/grass.png"));
|
||||
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||
background = new Sprite(backgroundTexture);
|
||||
background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
||||
|
||||
backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
|
||||
if(!backgroundShader.isCompiled()){
|
||||
Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
|
||||
Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
|
||||
backgroundShader = null;
|
||||
}
|
||||
|
||||
u_scaling = new float[2];
|
||||
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
||||
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||
|
||||
u_displacement = 1.0f;
|
||||
|
||||
startButtonTouched = false;
|
||||
startButtonTouchPointer = -1;
|
||||
quitButtonTouched = false;
|
||||
quitButtonTouchPointer = -1;
|
||||
|
||||
stateEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta){
|
||||
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||
core.batch.begin();{
|
||||
|
||||
// Render background.
|
||||
core.batch.disableBlending();
|
||||
drawBackground(core.batch);
|
||||
core.batch.enableBlending();
|
||||
|
||||
// Render buttons.
|
||||
startButton.draw(core.batch, 1.0f);
|
||||
quitButton.draw(core.batch, 1.0f);
|
||||
|
||||
}core.batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
menuButtonEnabledTexture.dispose();
|
||||
menuButtonDisabledTexture.dispose();
|
||||
menuButtonPressedTexture.dispose();
|
||||
backgroundTexture.dispose();
|
||||
if(backgroundShader != null) backgroundShader.dispose();
|
||||
font.dispose();
|
||||
}
|
||||
|
||||
private void drawBackground(SpriteBatch batch){
|
||||
if(backgroundShader != null){
|
||||
batch.setShader(backgroundShader);
|
||||
backgroundShader.setUniformf("u_scaling", 2.0f);
|
||||
backgroundShader.setUniformf("u_displacement", u_displacement);
|
||||
}
|
||||
background.draw(batch);
|
||||
if(backgroundShader != null) batch.setShader(null);
|
||||
u_displacement = u_displacement < 0.0f ? 1.0f : u_displacement - 0.0005f;
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; INPUT LISTENER METHODS ;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
unprojectTouch(screenX, screenY);
|
||||
|
||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && !quitButtonTouched){
|
||||
startButton.setChecked(true);
|
||||
startButtonTouched = true;
|
||||
startButtonTouchPointer = pointer;
|
||||
}else if(!quitButton.isDisabled() && quitButtonBBox.contains(touchPointWorldCoords) && !startButtonTouched){
|
||||
quitButton.setChecked(true);
|
||||
quitButtonTouched = true;
|
||||
quitButtonTouchPointer = pointer;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
unprojectTouch(screenX, screenY);
|
||||
|
||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && startButtonTouched){
|
||||
startButton.setChecked(false);
|
||||
startButtonTouched = false;
|
||||
startButtonTouchPointer = -1;
|
||||
core.nextState = game_states_t.IN_GAME;
|
||||
}else if(!quitButton.isDisabled() && quitButtonBBox.contains(touchPointWorldCoords) && quitButtonTouched){
|
||||
quitButton.setChecked(false);
|
||||
quitButtonTouched = false;
|
||||
quitButtonTouchPointer = -1;
|
||||
core.nextState = game_states_t.QUIT;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||
unprojectTouch(screenX, screenY);
|
||||
|
||||
if(!startButton.isDisabled() && startButtonTouched && pointer == startButtonTouchPointer && !startButtonBBox.contains(touchPointWorldCoords)){
|
||||
startButtonTouchPointer = -1;
|
||||
startButtonTouched = false;
|
||||
startButton.setChecked(false);
|
||||
}else if(!quitButton.isDisabled() && quitButtonTouched && pointer == quitButtonTouchPointer && !quitButtonBBox.contains(touchPointWorldCoords)){
|
||||
quitButtonTouchPointer = -1;
|
||||
quitButtonTouched = false;
|
||||
quitButton.setChecked(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode){
|
||||
if(keycode == Input.Keys.BACK){
|
||||
Gdx.app.exit();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user