Commit 8ab94f53 authored by Luboš Horáček's avatar Luboš Horáček Committed by Matyáš Latner

#52 Strelnice základ

- assets
- model
- vypocet pozic
parent b31bba8d
......@@ -6,5 +6,6 @@ gen
bin
*.log
local.properties
/.classpath
/.project
.classpath
.project
temp
......@@ -30,7 +30,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:glEsVersion='0x00020000'/>
<uses-feature android:glEsVersion="0x00020000" />
<application
android:name="Tablexia"
......@@ -77,6 +77,11 @@
android:name="cz.nic.tablexia.game.games.bankovniloupez.BankovniloupezActivity"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape" />
<activity
android:name="cz.nic.tablexia.game.games.strelnice.StrelniceActivity"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape" >
</activity>
</application>
</manifest>
</manifest>
\ No newline at end of file
......@@ -19,33 +19,191 @@
package cz.nic.tablexia.game.games.strelnice;
import java.io.IOException;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.RotationByModifier;
import org.andengine.entity.scene.background.SpriteBackground;
import org.andengine.entity.sprite.Sprite;
import android.os.Bundle;
import android.util.Log;
import cz.nic.tablexia.game.GameActivity;
import cz.nic.tablexia.game.games.GamesDefinition;
import cz.nic.tablexia.game.games.strelnice.events.GameOverListener;
import cz.nic.tablexia.game.games.strelnice.media.GfxManager;
import cz.nic.tablexia.game.games.strelnice.media.MfxManager;
import cz.nic.tablexia.game.games.strelnice.media.TextureType;
import cz.nic.tablexia.util.ScalingHelper;
public class StrelniceActivity extends GameActivity {
private static final String TAG = StrelniceActivity.class.getSimpleName();
public static final String BASE_DIR = "strelnice/";
private static final int CAMERA_WIDTH = 1280;
private static final int WATCH_HAND_ZINDEX = 51;
private static final int WATCH_ZINDEX = 51;
private static final int FRAME_ZINDEX = 50;
private static final int WAVE1_ZINDEX = 40;
private static final int WAVE2_ZINDEX = 30;
private static final int WAVE3_ZINDEX = 20;
private static final int FLOWERS_WAVE1_ZINDEX = 35;
private static final int FLOWERS_WAVE2_ZINDEX = 25;
private static final int FLOWERS_WAVE3_ZINDEX = 15;
private float cameraHeight;
private boolean baseInitDone; // info,jestliuz bylo nainicializova (replay uz nebude znovu davat pozadi atd)
private GfxManager gfxManager;
private MfxManager mfxManager;
private Sprite watchHand;
public StrelniceActivity() {
super(GamesDefinition.STRELNICE);
// TODO Auto-generated constructor stub
}
private static final String TAG = StrelniceActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO
if (savedInstanceState != null) {
try {
// TODO restore state
Log.i(TAG, "State restored");
} catch (Exception e) {
Log.e(TAG, "Error saving state" + e.getMessage());
}
}
}
@Override
public Camera onCreateCamera() {
float scale = displaySize.x / (float) displaySize.y;
cameraHeight = (CAMERA_WIDTH / scale);
return new Camera(0, 0, CAMERA_WIDTH, cameraHeight);
}
/**
* Zapneme si podporu zvuku a zvukových efektů
*/
@Override
public EngineOptions onCreateEngineOptions() {
EngineOptions engineOptions = super.onCreateEngineOptions();
engineOptions.getAudioOptions().setNeedsSound(true).setNeedsMusic(true);
return engineOptions;
}
@Override
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws IOException {
gfxManager = new GfxManager(getTextureManager(), getAssets(), this);
gfxManager.loadTextures();
// load zvuku
mfxManager = new MfxManager(getMusicManager(), getSoundManager(), this);
mfxManager.loadSounds();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
protected void initGame() {
super.initGame();
// TODO games
// TODO generate data
if (!baseInitDone) {
Sprite background = new Sprite(camera.getWidth() / 2, camera.getHeight() / 2, camera.getWidth(), camera.getHeight(), gfxManager.get(TextureType.POZADI).second, getVertexBufferObjectManager());
scene.setBackground(new SpriteBackground(background));
Sprite frame = new Sprite(camera.getWidth() / 2, camera.getHeight() / 2, camera.getWidth(), camera.getHeight(), gfxManager.get(TextureType.FRAME).second, getVertexBufferObjectManager());
frame.setZIndex(FRAME_ZINDEX);
scene.attachChild(frame);
float watchWidth = (int) camera.getWidth() / 5;
float watchHeight = ScalingHelper.getHeightFromWidth(gfxManager.get(TextureType.WATCH).second.getWidth(), gfxManager.get(TextureType.WATCH).second.getHeight(), watchWidth);
Sprite watch = new Sprite(watchWidth / 2, watchHeight / 2, watchWidth, watchHeight, gfxManager.get(TextureType.WATCH).second, getVertexBufferObjectManager());
watch.setZIndex(WATCH_ZINDEX);
scene.attachChild(watch);
float watchHandWidth = gfxManager.get(TextureType.WATCH_HAND).second.getWidth() * ScalingHelper.getScale(gfxManager.get(TextureType.WATCH).second.getWidth(), watchWidth);
float watchHandHeight = ScalingHelper.getHeightFromWidth(gfxManager.get(TextureType.WATCH_HAND).second.getWidth(), gfxManager.get(TextureType.WATCH_HAND).second.getHeight(), watchHandWidth);
float watchCenterOffsetX = TextureType.WATCH_CENTER_X_OFFSET * ScalingHelper.getScale(gfxManager.get(TextureType.WATCH).second.getWidth(), watchWidth);
float watchCenterOffsetY = TextureType.WATCH_CENTER_Y_OFFSET * ScalingHelper.getScale(gfxManager.get(TextureType.WATCH).second.getWidth(), watchWidth);
watchHand = new Sprite((watchWidth / 2) + watchCenterOffsetX, ((watchHeight / 2) + (watchHandHeight / 2)) + watchCenterOffsetY, watchHandWidth, watchHandHeight, gfxManager.get(TextureType.WATCH_HAND).second, getVertexBufferObjectManager());
watchHand.setRotationCenter(0.5f, 0.12f);
watchHand.setZIndex(WATCH_HAND_ZINDEX);
scene.attachChild(watchHand);
// TODO add waves
Sprite wave1 = new Sprite(camera.getWidth() / 2, camera.getHeight() / 2, camera.getWidth(), camera.getHeight(), gfxManager.get(TextureType.WAVE_1).second, getVertexBufferObjectManager());
wave1.setZIndex(WAVE1_ZINDEX);
scene.attachChild(wave1);
Sprite wave2 = new Sprite(camera.getWidth() / 2, (camera.getHeight() / 2) + (camera.getHeight() / 5), camera.getWidth(), camera.getHeight(), gfxManager.get(TextureType.WAVE_2).second, getVertexBufferObjectManager());
wave2.setZIndex(WAVE2_ZINDEX);
scene.attachChild(wave2);
scene.sortChildren();
baseInitDone = true;
}
}
@Override
protected void showGame() {
super.showGame();
scene.registerUpdateHandler(new TimerHandler(1f, false, new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
// START HRY
IEntityModifier gameTimer = new RotationByModifier(60, 360);
gameTimer.addModifierListener(new GameOverListener() {
@Override
public void startGame() {
// TODO zvuk začátku?
}
@Override
public void gameOver() {
// TODO Auto-generated method stub
gameComplete();
}
});
watchHand.registerEntityModifier(gameTimer);
}
}));
}
@Override
public CharSequence getVictoryText(int progress) {
// TODO Auto-generated method stub
return null;
return "";
}
@Override
public String[] getVictorySpeech() {
// TODO Auto-generated method stub
return null;
return new String[0];
}
@Override
public CharSequence getStatsText() {
// TODO Auto-generated method stub
return null;
return "";
}
@Override
......
/**
*
*/
package cz.nic.tablexia.game.games.strelnice.events;
import org.andengine.entity.IEntity;
import org.andengine.util.modifier.IModifier;
import org.andengine.util.modifier.IModifier.IModifierListener;
/**
* @author lhoracek
*
*/
public abstract class GameOverListener implements IModifierListener<IEntity> {
@Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
startGame();
}
@Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
gameOver();
}
abstract public void startGame();
abstract public void gameOver();
}
/**
*
*/
package cz.nic.tablexia.game.games.strelnice.generator;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.game.games.strelnice.model.Flower;
/**
* @author lhoracek
*/
public class FlowerManager {
private List<Flower> flowers = new ArrayList<Flower>();
public FlowerManager() {
// TODO Auto-generated constructor stub
}
public List<Flower> getFlowers() {
return flowers;
}
}
/*******************************************************************************
* Tablexia
*
* Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 cz.nic.tablexia.game.games.strelnice.media;
import java.io.IOException;
import java.util.HashMap;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.bitmap.AssetBitmapTexture;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import android.util.Pair;
import com.testflightapp.lib.TestFlight;
import cz.nic.tablexia.game.games.strelnice.StrelniceActivity;
/**
* @author lhoracek
*/
public class GfxManager extends HashMap<TextureType, Pair<Texture, TextureRegion>> {
private static final String TAG = GfxManager.class.getSimpleName();
private static final String TEXTURE_DIR = StrelniceActivity.BASE_DIR + "gfx/";
private final TextureManager textureManager;
private final AssetManager assetManager;
public GfxManager(TextureManager textureManager, AssetManager assetManager, Context context) {
super();
this.textureManager = textureManager;
this.assetManager = assetManager;
}
public void loadTextures() {
for (TextureType textureType : TextureType.values()) {
String path = TEXTURE_DIR + textureType.getResource();
try {
Log.v(TAG, "Loading texture " + textureType.getResource());
BitmapTexture texture = new AssetBitmapTexture(textureManager, assetManager, path);
texture.load();
TextureRegion textureRegion = TextureRegionFactory.extractFromTexture(texture);
put(textureType, new Pair<Texture, TextureRegion>(texture, textureRegion));
} catch (IOException e) {
Log.e(TAG, "Error loading texture " + path);
TestFlight.log("Error loading texture " + path);
}
}
}
}
/*******************************************************************************
* Tablexia
*
* Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 cz.nic.tablexia.game.games.strelnice.media;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.andengine.audio.music.Music;
import org.andengine.audio.music.MusicFactory;
import org.andengine.audio.music.MusicManager;
import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundFactory;
import org.andengine.audio.sound.SoundManager;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import com.testflightapp.lib.TestFlight;
import cz.nic.tablexia.game.games.strelnice.StrelniceActivity;
/**
* @author lhoracek
*/
public class MfxManager {
private static final String TAG = MfxManager.class.getSimpleName();
private static final String SOUNDS_DIR = StrelniceActivity.BASE_DIR + "mfx/";
public static final String SOUNDS_EXTENSION = ".mp3";
private Map<SoundType, Music> musics = new HashMap<SoundType, Music>();
private Map<SoundType, Sound> sounds = new HashMap<SoundType, Sound>();
private MusicManager musicManager;
private SoundManager soundManager;
private Context context;
public MfxManager(MusicManager musicManager, SoundManager soundManager, Context context) {
super();
this.musicManager = musicManager;
this.soundManager = soundManager;
this.context = context;
SoundFactory.setAssetBasePath(SOUNDS_DIR);
MusicFactory.setAssetBasePath(SOUNDS_DIR);
}
/**
* Nahrat zvuky, ktere jsou oznacene jako eage, a nactou se automaticky, ostatni zvuky se nactou az ve chvili prvniho prehrani
*/
public void loadSounds() {
for (SoundType sound : SoundType.values()) {
if (sound.isEager()) {
loadSound(sound);
}
}
}
private void loadSound(SoundType sound) {
// if (sound.getSoundClass() == SoundClass.SOUND) {
// try {
// Sound soundInstance = SoundFactory.createSoundFromAsset(soundManager, context, sound.getResource() + SOUNDS_EXTENSION);
// sounds.put(sound, soundInstance);
// } catch (final IOException e) {
// Log.e(TAG, "Error loading sound " + e.getMessage() + " - resource " + sound.getResource());
// TestFlight.log("Error loading sound " + e.getMessage() + " - resource " + sound.getResource());
// }
// } else {
// try {
// Log.v(TAG, "Loading sound " + sound.getResource());
// Music music = MusicFactory.createMusicFromAsset(musicManager, context, sound.getResource() + SOUNDS_EXTENSION);
// musics.put(sound, music);
// } catch (final IOException e) {
// Log.e(TAG, "Error loading sound " + e.getMessage() + " - resource: " + sound.getResource());
// TestFlight.log("Error loading sound " + e.getMessage() + " - resource " + sound.getResource());
// }
// }
}
public void playSound(SoundType sound) {
playSound(sound, null);
}
/**
* Prehraje zvuk z enumu, ktery muze byt preloadovan
*
* @param sound
* @param onCompletionListener
*/
public void playSound(SoundType sound, OnCompletionListener onCompletionListener) {
// if (sound.getSoundClass() == SoundClass.SOUND) {
// sounds.get(sound).play();
// } else {
// if (musics.get(sound) == null) {
// loadSound(sound);
// }
// Music music = musics.get(sound);
// if (onCompletionListener != null) {
// music.setOnCompletionListener(onCompletionListener);
// }
// music.play();
// }
}
/**
* Prehraje zvuk z assetu definovany nazvem souboru
*
* @param sound
* @param onCompletionListener
*/
public void playSound(String sound, final OnCompletionListener onCompletionListener) {
playSound(sound, onCompletionListener, false);
}
/**
* Prehraje zvuk z assetu definovany nazvem souboru, pokud je parametr isRetry true, tak uz se nepokusi prehrat pri chybe znovu
*
* @param sound
* @param onCompletionListener
*/
public void playSound(String sound, final OnCompletionListener onCompletionListener, boolean isRetry) {
try {
Music music = MusicFactory.createMusicFromAsset(musicManager, context, sound + SOUNDS_EXTENSION);
music.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (onCompletionListener != null) {
onCompletionListener.onCompletion(mp);
}
mp.release();
}
});
music.play();
} catch (final IOException e) {
TestFlight.log("Error loading sound " + e.getMessage() + " - resource " + sound);
if (!isRetry) {
playSound(sound, onCompletionListener, true);
}
}
}
}
/*******************************************************************************
* Tablexia
*
* Copyright (C) 2013 CZ NIC z.s.p.o. <podpora at nic dot cz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 cz.nic.tablexia.game.games.strelnice.media;
/**
* @author lhoracek
*/
public enum SoundType {
SOUND_ERROR("error", SoundClass.SOUND, true); //
public enum SoundClass {
SOUND, MUSIC;
}
private SoundType(String resource, SoundClass soundClass, boolean eager) {