summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/TankOnTank.java
blob: f6036d8259a481087c8005d0d74e1b05b4f281d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package ch.asynk.tankontank;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

import ch.asynk.tankontank.screens.LoadScreen;
import ch.asynk.tankontank.game.Ctrl;
import ch.asynk.tankontank.game.Config;
import ch.asynk.tankontank.game.battles.Factory;

public class TankOnTank extends Game
{
    public AssetManager manager;
    public Factory factory;
    public Skin skin;
    public Ctrl ctrl;
    public Config config;

    public static void debug(String msg)
    {
        debug("", msg);
    }

    public static void debug(String dom, String msg)
    {
        Gdx.app.debug(dom, msg);
    }

    @Override
    public void create ()
    {
        Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG);
        debug("TankOnTank", "create() [" + Gdx.graphics.getWidth() + ";" + Gdx.graphics.getHeight() + "]");

        manager = new AssetManager();
        factory = new Factory(this);
        skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
        config = new Config();

        this.setScreen(new LoadScreen(this));
    }

    public void loadAssets()
    {
        debug("TankOnTank", "  load assets : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
        manager.load("data/map_a.png", Texture.class);
        manager.load("data/map_b.png", Texture.class);
        manager.load("data/hud.atlas", TextureAtlas.class);
        manager.load("data/units.atlas", TextureAtlas.class);
        manager.load("data/unit-overlays.atlas", TextureAtlas.class);
        manager.load("data/hex-overlays.atlas", TextureAtlas.class);
        manager.load("data/shots.png", Texture.class);
        manager.load("data/explosions.png", Texture.class);
        manager.load("sounds/move.mp3", Sound.class);
        manager.load("sounds/attack.mp3", Sound.class);
        manager.load("sounds/shot.mp3", Sound.class);
        manager.load("sounds/short_shot.mp3", Sound.class);
        manager.load("sounds/explosion.mp3", Sound.class);
        manager.load("sounds/explosion_short.mp3", Sound.class);
        manager.load("sounds/promote.mp3", Sound.class);
    }

    public void unloadAssets()
    {
        debug("TankOnTank", "unload assets : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
        debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
        manager.unload("data/map_a.png");
        manager.unload("data/map_b.png");
        manager.unload("data/hud.atlas");
        manager.unload("data/units.atlas");
        manager.unload("data/unit-overlays.atlas");
        manager.unload("data/hex-overlays.atlas");
        manager.unload("data/shots.png");
        manager.unload("data/explosions.png");
        manager.unload("sounds/move.mp3");
        manager.unload("sounds/attack.mp3");
        manager.unload("sounds/shot.mp3");
        manager.unload("sounds/short_shot.mp3");
        manager.unload("sounds/explosion.mp3");
        manager.unload("sounds/explosion_short.mp3");
        manager.unload("sounds/promote.mp3");
        debug("TankOnTank", "diagnostics:\n" + manager.getDiagnostics() );
    }

    public void onLoaded()
    {
        factory.assetsLoaded();
    }

    // @Override
    // public void render ()
    // {
    //     Gdx.gl.glClearColor(0, 0, 0, 1);
    //     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    //     super.render();
    // }

    // @Override
    // public void resize(int width, int height)
    // {
    //     debug("TankOnTank", "resize(" + width + ", " + height + ")");
    //     super.resize(width, height);
    // }

    @Override
    public void dispose()
    {
        debug("TankOnTank", "dispose()");
        getScreen().dispose();
        factory.dispose();
        unloadAssets();
    }

    // @Override
    // public void pause()
    // {
    //     debug("TankOnTank", "pause()");
    // }

    // @Override
    // public void resume()
    // {
    //     debug("TankOnTank", "resume()");
    // }
}