From 2878f1e34c2c2e19d5b7f6fd368dbf9ec0c6277f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 15 Dec 2025 00:36:33 +0100 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D0=B3=D0=BB=D0=B0=D0=B2=D1=83?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2/2_vertical_scroll/core/build.gradle" | 5 + .../src/net/caraus/modelling/DiagonalScreen.java" | 81 ++++++++++++++ .../core/src/net/caraus/modelling/GameScreen.java" | 59 +++++++++++ .../net/caraus/modelling/HorizontalScreen.java" | 54 ++++++++++ .../src/net/caraus/modelling/MainMenuScreen.java" | 117 +++++++++++++++++++++ .../core/src/net/caraus/modelling/Modelling.java" | 21 ++++ .../src/net/caraus/modelling/VerticalScreen.java" | 54 ++++++++++ 7 files changed, 391 insertions(+) create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/build.gradle" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/DiagonalScreen.java" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/GameScreen.java" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/HorizontalScreen.java" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/MainMenuScreen.java" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/Modelling.java" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/VerticalScreen.java" (limited to 'Занимательное программирование/2/2_vertical_scroll/core') diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/build.gradle" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/build.gradle" new file mode 100644 index 0000000..c2fa637 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/build.gradle" @@ -0,0 +1,5 @@ +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + +sourceSets.main.java.srcDirs = [ "src/" ] + +eclipse.project.name = appName + "-core" diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/DiagonalScreen.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/DiagonalScreen.java" new file mode 100644 index 0000000..5828ce0 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/DiagonalScreen.java" @@ -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 iter = backgrounds.iterator(); iter.hasNext(); ) { + Rectangle background = iter.next(); + + background.x = background.x - SCREEN_WIDTH; + } + } + if (backgrounds.get(1).y >= 0) { + for (Iterator 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(); + } + } +} diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/GameScreen.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/GameScreen.java" new file mode 100644 index 0000000..c739459 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/GameScreen.java" @@ -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 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(); + } + + @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(); + } +} diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/HorizontalScreen.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/HorizontalScreen.java" new file mode 100644 index 0000000..9d35c78 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/HorizontalScreen.java" @@ -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 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(); + } + } +} diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/MainMenuScreen.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/MainMenuScreen.java" new file mode 100644 index 0000000..56136c1 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/MainMenuScreen.java" @@ -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(); + } +} diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/Modelling.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/Modelling.java" new file mode 100644 index 0000000..5949186 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/Modelling.java" @@ -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(); + } +} diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/VerticalScreen.java" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/VerticalScreen.java" new file mode 100644 index 0000000..2e56977 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/2/2_vertical_scroll/core/src/net/caraus/modelling/VerticalScreen.java" @@ -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 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(); + } + } +} -- cgit v1.2.3