Java tutorial
// Copyright 2012 Anton Holm, Arez Arazu, Gustav Larsson // // 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 net.dat.killemall.screens; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; // Skrm visas nr spelaren har avklarat alla fiendeniver. public class WinScreen implements Screen, InputProcessor { //Hmtar tillten strsta storlek fr hjd och bredd float x = Gdx.graphics.getWidth(); float y = Gdx.graphics.getHeight(); private int width, height; //Hmtar aktuell spritebatch private SpriteBatch spriteBatch; private Texture winScreenTexture; private Game KEAGame; //En konstruktor fr en GameScreen med koppling till aktuellt spel // krvs fr att kunna hnvisa korrekt mellan olika Screens i applikationen. public WinScreen(Game ga) { KEAGame = ga; } @Override public void render(float delta) { spriteBatch.begin(); spriteBatch.draw(winScreenTexture, 0, 0, x, y); spriteBatch.end(); } // Om telefonen vrids t ngot hll eller om upplsningen // p annat vis frndras s ndras ven maximalt tilltna // storlek p innehll p skrmen. Hr frndras tabellens // storlek fr att ritas inne i skrmen korrekt. @Override public void resize(int width, int height) { this.width = width; this.height = height; } @Override public void show() { //Hmtar aktuella sprites frn skapad spritebatch. spriteBatch = new SpriteBatch(); winScreenTexture = new Texture(Gdx.files.internal("images/win.png")); // Fr att kunna hantera att spelaren rr p skrmen och koppla detta // Till handlingar stts en inputprocessor p denna Screen Gdx.input.setInputProcessor(this); } @Override public void hide() { // TODO Auto-generated method stub } @Override public void pause() { // TODO Auto-generated method stub } @Override public void resume() { // TODO Auto-generated method stub } // Nr denna Screen verges r sumpas aktuell spritebatch. @Override public void dispose() { spriteBatch.dispose(); winScreenTexture.dispose(); } @Override public boolean keyDown(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyUp(int keycode) { // TODO Auto-generated method stub return false; } @Override public boolean keyTyped(char character) { // TODO Auto-generated method stub return false; } @Override public boolean touchDown(int x1, int y1, int pointer, int button) { // If-satsen avgr var p skrmen som spelaren trycker genom att rama in vissa pixlar i //x-led och y-led, nr spelaren rr skrmen inom dessa byts skrmen till //Main Menu if (x1 > (width / 2 - width / 6) && x1 < (width / 2 - width / 6) + width / 3 && y1 > (y - ((height / 4) + height / 8)) && y1 < (y - (height / 4))) { KEAGame.setScreen(new MainMenuScreen(KEAGame)); } return true; } @Override public boolean touchUp(int x, int y, int pointer, int button) { // TODO Auto-generated method stub return false; } @Override public boolean touchDragged(int x, int y, int pointer) { // TODO Auto-generated method stub return false; } @Override public boolean touchMoved(int x, int y) { // TODO Auto-generated method stub return false; } @Override public boolean scrolled(int amount) { // TODO Auto-generated method stub return false; } }