Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
- import com.badlogic.gdx.math.Vector3;
- import com.mygdx.game.states.GameStateManager;
- public class MyGdxGame extends ApplicationAdapter {
- //private OrthographicCamera cam;
- //private ShapeRenderer sr;
- private Vector3 pos;
- //public static final int WIDTH= 400;
- //public static final int HEIGHT=800;
- public static final String TITLE= "Helikopter";
- private GameStateManager gsm;
- private SpriteBatch batch;
- private Texture texture;
- private Sprite sprite;
- float speedX = 3f;
- float speedY = 3f;
- private String yourScoreName;
- BitmapFont yourBitmapFontName;
- @Override
- public void create () {
- yourScoreName = "x: 0" + "y: 0" ;
- yourBitmapFontName = new BitmapFont();
- //Gdx.gl.glClearColor(255, 255, 1,1);
- batch = new SpriteBatch();
- texture = new Texture("heli1.png");
- sprite = new Sprite(texture);
- pos = new Vector3(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2, 0);
- sprite.flip(true,false);
- //cam= new OrthographicCamera();
- //gsm = new GameStateManager();
- //cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- //cam.update();
- //gsm.push(new MenuState(gsm));
- /*sr = new ShapeRenderer();
- cam = new OrthographicCamera();
- // størrelse på hvor mye man vil se av skjermen
- cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- pos = new Vector3(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2, 0);
- */
- }
- @Override
- public void render () {
- Gdx.gl.glClearColor(1, 0, 1, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- //gsm.update(Gdx.graphics.getDeltaTime());
- //gsm.render(batch);
- if (pos.x > Gdx.graphics.getWidth() - texture.getWidth() / 2 || pos.x < 0 + texture.getWidth() / 2) {
- sprite.flip(true, false);
- speedX = -speedX;
- }
- if (pos.y > Gdx.graphics.getHeight() - texture.getHeight() / 2 || pos.y < 0 + texture.getHeight() / 2) {
- speedY = -speedY;
- }
- pos.x += speedX;
- pos.y += speedY;
- yourScoreName = "x:" + pos.x + "y:" + pos.y;
- batch.begin();
- batch.draw(sprite,
- pos.x - sprite.getWidth() / 2,
- pos.y - sprite.getHeight()/2);
- yourBitmapFontName.setColor(1.0f, 1.0f, 1.0f, 1.0f);
- yourBitmapFontName.draw(batch, yourScoreName, 500, 450);
- batch.end();
- /*//Logic
- cam.update();
- if (Gdx.input.isTouched()){
- pos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
- cam.unproject(pos);
- }
- // Drawing
- Gdx.gl.glClearColor(1,1,1,1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- sr.begin(ShapeRenderer.ShapeType.Filled);
- sr.setColor(Color.PINK);
- sr.circle(pos.x, pos.y, 30);
- sr.end();
- */
- }
- @Override
- public void dispose () {
- batch.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement