Back to project page googol.
The source code is released under:
MIT License
If you think the Android project googol listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.martinb.googol.Objects; /*from ww w . j a va2 s . c om*/ import java.util.ArrayList; import java.util.Collections; import java.util.List; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; import com.martinb.googol.Control.Assets; import com.martinb.googol.Screens.Screen; public class World { final int MAX_CHARACTERS = 100; Screen screen; Vector2 size; Vector2 screenSize; OrthographicCamera camera; SpriteBatch batch; Assets assets; List<Character> characters; /* * Stores all characters in actual game, renders them, redirects input to them, etc. * Size is 100 on the smaller axis, and is greater than 100 on the another */ public World(Screen screen) { this.screen = screen; this.screenSize = screen.getScreenSize(); camera = new OrthographicCamera(); batch = new SpriteBatch(); assets = new Assets(); assets.load(); size = calculateSize(screenSize); configureCamera(size); characters = new ArrayList<Character>(); characters.add(new Character(0, 0, 10, 10, assets.test, 1, this)); characters.add(new Character(50, 0, 10, 10, assets.test, 2, this)); characters.add(new Character(77, 88, 10, 10, assets.test, .5f, this)); characters.add(new Character(20, 20, 10, 10, assets.test, 0, this)); characters.add(new Character(20, 27, 10, 10, assets.test, 0, this)); characters.add(new Character(20, 35, 10, 10, assets.test, 0, this)); } public void render(float delta) { for (int i = 0; i < characters.size(); i++) { characters.get(i).update(delta); } Collections.sort(characters, new CharacterDepthComparator()); Gdx.gl.glClearColor(1, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); for (Character c : characters) { renderCharacter(c); } batch.end(); } public void resize(int width, int height) { this.screenSize = screen.getScreenSize(); size = calculateSize(screenSize); configureCamera(size); } public void dispose() { } void renderCharacter(Character character) { batch.draw(character.texture, character.x, character.y, character.width, character.height); } /** * Configure camera with the defined size */ void configureCamera(Vector2 size) { camera.setToOrtho(false, size.x, size.y); camera.update(); batch.setProjectionMatrix(camera.combined); } /** * Returns a Vector2 that is 100 on the smaller axis, and is greater than 100 on the another maintaining aspect ratio */ Vector2 calculateSize(Vector2 screenSize) { size = new Vector2(); if (screenSize.x > screenSize.y) { size.y = 100; size.x = (screenSize.x / screenSize.y) * 100; } else { size.x = 100; size.y = (screenSize.y / screenSize.x) * 100; } return size; } }