Добавил вторую главу занимательного программирования
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
eclipse.project.name = appName + "-core"
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class DiagonalScreen extends GameScreen {
|
||||
|
||||
public DiagonalScreen(final Modelling game) {
|
||||
super(game);
|
||||
|
||||
Rectangle nextRectangle = new Rectangle();
|
||||
nextRectangle.x = -SCREEN_WIDTH;
|
||||
nextRectangle.y = 0;
|
||||
backgrounds.add(nextRectangle);
|
||||
|
||||
nextRectangle = new Rectangle();
|
||||
nextRectangle.x = 0;
|
||||
nextRectangle.y = -SCREEN_HEIGHT;
|
||||
backgrounds.add(nextRectangle);
|
||||
|
||||
nextRectangle = new Rectangle();
|
||||
nextRectangle.x = -SCREEN_WIDTH;
|
||||
nextRectangle.y = -SCREEN_HEIGHT;
|
||||
backgrounds.add(nextRectangle);
|
||||
|
||||
nextRectangle = new Rectangle();
|
||||
nextRectangle.x = 0;
|
||||
nextRectangle.y = 0;
|
||||
backgrounds.add(nextRectangle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
|
||||
camera.update();
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
float xStep = SCREEN_WIDTH / 10;
|
||||
float yStep = SCREEN_HEIGHT / 10;
|
||||
|
||||
backgrounds.get(0).x = backgrounds.get(0).x + xStep * delta;
|
||||
backgrounds.get(1).x = backgrounds.get(1).x + xStep * delta;
|
||||
backgrounds.get(2).x = backgrounds.get(2).x + xStep * delta;
|
||||
backgrounds.get(3).x = backgrounds.get(3).x + xStep * delta;
|
||||
|
||||
backgrounds.get(0).y = backgrounds.get(0).y + yStep * delta;
|
||||
backgrounds.get(1).y = backgrounds.get(1).y + yStep * delta;
|
||||
backgrounds.get(2).y = backgrounds.get(2).y + yStep * delta;
|
||||
backgrounds.get(3).y = backgrounds.get(3).y + yStep * delta;
|
||||
|
||||
if (backgrounds.get(0).x >= 0) {
|
||||
for (Iterator<Rectangle> iter = backgrounds.iterator(); iter.hasNext(); ) {
|
||||
Rectangle background = iter.next();
|
||||
|
||||
background.x = background.x - SCREEN_WIDTH;
|
||||
}
|
||||
}
|
||||
if (backgrounds.get(1).y >= 0) {
|
||||
for (Iterator<Rectangle> iter = backgrounds.iterator(); iter.hasNext(); ) {
|
||||
Rectangle background = iter.next();
|
||||
|
||||
background.y = background.y - SCREEN_HEIGHT;
|
||||
}
|
||||
}
|
||||
batch.begin();
|
||||
for (Rectangle background: backgrounds) {
|
||||
batch.draw(backgroundImage, background.x, background.y);
|
||||
}
|
||||
batch.end();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
|
||||
game.setScreen(new MainMenuScreen(game));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public abstract class GameScreen implements Screen {
|
||||
protected final Modelling game;
|
||||
|
||||
protected OrthographicCamera camera;
|
||||
protected SpriteBatch batch;
|
||||
protected Array<Rectangle> backgrounds;
|
||||
protected Texture backgroundImage;
|
||||
|
||||
static final int SCREEN_WIDTH = 609;
|
||||
static final int SCREEN_HEIGHT = 456;
|
||||
static final int STEP = 100;
|
||||
|
||||
public GameScreen(final Modelling game) {
|
||||
this.game = game;
|
||||
backgroundImage = new Texture(Gdx.files.internal("background.bmp"));
|
||||
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
batch = new SpriteBatch();
|
||||
backgrounds = new Array<Rectangle>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
backgroundImage.dispose();
|
||||
batch.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class HorizontalScreen extends GameScreen {
|
||||
|
||||
public HorizontalScreen(final Modelling game) {
|
||||
super(game);
|
||||
|
||||
Rectangle nextRectangle = new Rectangle();
|
||||
nextRectangle.x = -SCREEN_WIDTH;
|
||||
nextRectangle.y = 0;
|
||||
backgrounds.add(nextRectangle);
|
||||
|
||||
nextRectangle = new Rectangle();
|
||||
nextRectangle.x = 0;
|
||||
nextRectangle.y = 0;
|
||||
backgrounds.add(nextRectangle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
|
||||
camera.update();
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
backgrounds.get(0).x = backgrounds.get(0).x + STEP * Gdx.graphics.getDeltaTime();
|
||||
backgrounds.get(1).x = backgrounds.get(1).x + STEP * Gdx.graphics.getDeltaTime();
|
||||
|
||||
if (backgrounds.get(0).x >= 0) {
|
||||
for (Iterator<Rectangle> iter = backgrounds.iterator(); iter.hasNext(); ) {
|
||||
Rectangle background = iter.next();
|
||||
|
||||
background.x = background.x - SCREEN_WIDTH;
|
||||
}
|
||||
}
|
||||
batch.begin();
|
||||
for (Rectangle background: backgrounds) {
|
||||
batch.draw(backgroundImage, background.x, background.y);
|
||||
}
|
||||
batch.end();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
|
||||
game.setScreen(new MainMenuScreen(game));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
|
||||
public class MainMenuScreen implements Screen {
|
||||
final Modelling game;
|
||||
|
||||
BitmapFont font;
|
||||
OrthographicCamera camera;
|
||||
|
||||
private TextButton horizontalButton;
|
||||
private TextButton verticalButton;
|
||||
private TextButton crossButton;
|
||||
|
||||
private Stage stage;
|
||||
private Table table;
|
||||
|
||||
public MainMenuScreen(final Modelling game) {
|
||||
this.game = game;
|
||||
|
||||
font = new BitmapFont(); // use libGDX's default Arial font.
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, 800, 480);
|
||||
|
||||
stage = new Stage();
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
|
||||
table = new Table();
|
||||
table.setFillParent(true);
|
||||
table.setDebug(true);
|
||||
stage.addActor(table);
|
||||
|
||||
createButtons();
|
||||
}
|
||||
|
||||
private void createButtons() {
|
||||
TextButtonStyle style = new TextButtonStyle();
|
||||
style.font = font;
|
||||
|
||||
table.row().width(150);
|
||||
|
||||
horizontalButton = new TextButton("Waagerecht", style);
|
||||
horizontalButton.addListener(new ChangeListener() {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
game.setScreen(new HorizontalScreen(game));
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
table.add(horizontalButton);
|
||||
|
||||
verticalButton = new TextButton("Senkrecht", style);
|
||||
verticalButton.addListener(new ChangeListener() {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
game.setScreen(new VerticalScreen(game));
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
table.add(verticalButton);
|
||||
|
||||
crossButton = new TextButton("Diagonal", style);
|
||||
crossButton.addListener(new ChangeListener() {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
game.setScreen(new DiagonalScreen(game));
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
table.add(crossButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
|
||||
camera.update();
|
||||
game.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
stage.act(delta);
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
stage.getViewport().update(width, height, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
font.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
public class Modelling extends Game {
|
||||
public SpriteBatch batch;
|
||||
|
||||
public void create() {
|
||||
batch = new SpriteBatch();
|
||||
this.setScreen(new MainMenuScreen(this));
|
||||
}
|
||||
|
||||
public void render() {
|
||||
super.render();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
batch.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.caraus.modelling;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class VerticalScreen extends GameScreen {
|
||||
|
||||
public VerticalScreen(final Modelling game) {
|
||||
super(game);
|
||||
|
||||
Rectangle nextRectangle = new Rectangle();
|
||||
nextRectangle.x = 0;
|
||||
nextRectangle.y = -SCREEN_HEIGHT;
|
||||
backgrounds.add(nextRectangle);
|
||||
|
||||
nextRectangle = new Rectangle();
|
||||
nextRectangle.x = 0;
|
||||
nextRectangle.y = 0;
|
||||
backgrounds.add(nextRectangle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float delta) {
|
||||
ScreenUtils.clear(0, 0, 0.2f, 1);
|
||||
|
||||
camera.update();
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
backgrounds.get(0).y = backgrounds.get(0).y + STEP * Gdx.graphics.getDeltaTime();
|
||||
backgrounds.get(1).y = backgrounds.get(1).y + STEP * Gdx.graphics.getDeltaTime();
|
||||
|
||||
if (backgrounds.get(0).y >= 0) {
|
||||
for (Iterator<Rectangle> iter = backgrounds.iterator(); iter.hasNext(); ) {
|
||||
Rectangle background = iter.next();
|
||||
|
||||
background.y = background.y - SCREEN_HEIGHT;
|
||||
}
|
||||
}
|
||||
batch.begin();
|
||||
for (Rectangle background: backgrounds) {
|
||||
batch.draw(backgroundImage, background.x, background.y);
|
||||
}
|
||||
batch.end();
|
||||
|
||||
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
|
||||
game.setScreen(new MainMenuScreen(game));
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user