Skip to content
TheChatArchiveThe Chat Archive
Hunyuanhunyuan-turbos-20250416· TencentHugging Face LMArena Human Preference 140K

Напиши код гри на андроїд, жанр: Перевезення вантажу в 2д стилі Що має бути:…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro’s answer.
  1. User

    Напиши код гри на андроїд, жанр: Перевезення вантажу в 2д стилі Що має бути: 1.Згенерована графіка. 2.Різновидність вантажу. 3.Приборна панель з спідометро і тахометром,а також коробка передач. 4.Пропрацьована можель вантажівки. 5.Локації які знінюються. 6.Вибір вантажівок. 7.Меню.

  2. Hunyuan Assistant

    Ось приклад базового прототипу 2D-гри для Android на Java із використанням фреймворку LibGDX — популярного інструменту для розробки кроссплатформених 2D-ігор. Цей прототип включає:

    ✅ Генеровану графіку
    ✅ Різновиди вантажу
    ✅ Приборну панель (спідометр, тахометр, КПП)
    ✅ Просту модель вантажівки
    ✅ Змінювані локації
    ✅ Вибір вантажівок
    ✅ Меню


    📁 Структура проєкту

    core/
    ├── assets/
    │   ├── images/
    │   │   ├── truck1.png
    │   │   ├── truck2.png
    │   │   ├── cargo1.png
    │   │   ├── cargo2.png
    │   │   ├── background1.png
    │   │   └── gauge_background.png
    │   └── fonts/
    │       └── font.fnt
    ├── com.mygame.game/
    │   ├── GameScreen.java
    │   ├── MenuScreen.java
    │   ├── Truck.java
    │   ├── Cargo.java
    │   ├── Location.java
    │   ├── Dashboard.java
    │   ├── GameWorld.java
    │   └── MyGame.java
    desktop/
    android/ (автоматично створюється Android Studio)
    

    1️⃣ MyGame.java – Головний клас гри

    package com.mygame.game;
    
    import com.badlogic.gdx.Game;
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.g2d.BitmapFont;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    
    public class MyGame extends Game {
        public static final int V_WIDTH = 800;
        public static final int V_HEIGHT = 480;
        
        public SpriteBatch batch;
        public BitmapFont font;
    
        @Override
        public void create () {
            batch = new SpriteBatch();
            font = new BitmapFont();
            setScreen(new MenuScreen(this));
        }
    
        @Override
        public void render () {
            super.render();
        }
    
        @Override
        public void dispose () {
            batch.dispose();
            font.dispose();
        }
    }
    

    2️⃣ MenuScreen.java – Головне меню

    package com.mygame.game;
    
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.Screen;
    import com.badlogic.gdx.graphics.GL20;
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.scenes.scene2d.Stage;
    import com.badlogic.gdx.scenes.scene2d.ui.*;
    import com.badlogic.gdx.utils.viewport.StretchViewport;
    
    public class MenuScreen implements Screen {
        final MyGame game;
        private Stage stage;
    
        public MenuScreen(MyGame game) {
            this.game = game;
            stage = new Stage(new StretchViewport(MyGame.V_WIDTH, MyGame.V_HEIGHT));
            Gdx.input.setInputProcessor(stage);
    
            Skin skin = new Skin(Gdx.files.internal("uiskin.json")); // можна замінити на простий TextButtonStyle
    
            Table table = new Table();
            table.setFillParent(true);
            stage.addActor(table);
    
            TextButton playButton = new TextButton("Start Game", skin);
            TextButton exitButton = new TextButton("Exit", skin);
    
            playButton.addListener(e -> {
                if (e.isHandled()) game.setScreen(new GameScreen(game));
                return true;
            });
    
            exitButton.addListener(e -> {
                Gdx.app.exit();
                return true;
            });
    
            table.add(playButton).pad(20);
            table.row();
            table.add(exitButton).pad(20);
        }
    
        @Override
        public void render(float delta) {
            Gdx.gl.glClearColor(0.2f, 0.2f, 0.5f, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            stage.act(delta);
            stage.draw();
        }
    
        // ... інші методи інтерфейсу Screen
    }
    

    ⚠️ Для кнопок потрібен uiskin.json. Для тесту можна використати простий TextButton без стилів.


    3️⃣ GameScreen.java – Основний екран гри

    package com.mygame.game;
    
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.Screen;
    import com.badlogic.gdx.graphics.GL20;
    import com.badlogic.gdx.graphics.OrthographicCamera;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    
    public class GameScreen implements Screen {
        final MyGame game;
        OrthographicCamera camera;
        SpriteBatch batch;
        GameWorld world;
    
        public GameScreen(MyGame game) {
            this.game = game;
            camera = new OrthographicCamera();
            camera.setToOrtho(false, MyGame.V_WIDTH, MyGame.V_HEIGHT);
            batch = new SpriteBatch();
            world = new GameWorld(batch, camera);
        }
    
        @Override
        public void render(float delta) {
            Gdx.gl.glClearColor(0, 0, 0, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
            world.update(delta);
            world.render();
    
            batch.setProjectionMatrix(camera.combined);
            batch.begin();
            world.getDashboard().render(batch);
            batch.end();
        }
    
        // ... інші методи інтерфейсу Screen
    }
    

    4️⃣ GameWorld.java – Логіка світу

    package com.mygame.game;
    
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.graphics.OrthographicCamera;
    
    public class GameWorld {
        private Truck truck;
        private Location currentLocation;
        private Cargo cargo;
        private Dashboard dashboard;
        private SpriteBatch batch;
        private OrthographicCamera camera;
    
        public GameWorld(SpriteBatch batch, OrthographicCamera camera) {
            this.batch = batch;
            this.camera = camera;
    
            truck = new Truck("truck1.png");
            cargo = new Cargo("cargo1.png");
            truck.loadCargo(cargo);
    
            currentLocation = new Location("background1.png");
            dashboard = new Dashboard();
        }
    
        public void update(float delta) {
            truck.update(delta);
            dashboard.update(truck);
        }
    
        public void render() {
            batch.begin();
            currentLocation.render(batch);
            truck.render(batch);
            cargo.render(batch);
            batch.end();
        }
    
        public Dashboard getDashboard() {
            return dashboard;
        }
    }
    

    5️⃣ Truck.java – Модель вантажівки

    package com.mygame.game;
    
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.math.Vector2;
    
    public class Truck {
        Texture texture;
        Vector2 position;
        float speed;
        float rpm;
        String gear;
    
        public Truck(String texturePath) {
            texture = new Texture(texturePath);
            position = new Vector2(100, 200);
            speed = 0;
            rpm = 0;
            gear = "N";
        }
    
        public void update(float delta) {
            // Просте моделювання руху
            position.x += speed * delta;
            rpm = speed * 20;
            if (speed > 0) gear = "D";
            else gear = "R";
        }
    
        public void render(SpriteBatch batch) {
            batch.draw(texture, position.x, position.y);
        }
    
        public void loadCargo(Cargo cargo) {
            // Логіка завантаження
        }
    
        public float getSpeed() { return speed; }
        public float getRpm() { return rpm; }
        public String getGear() { return gear; }
    
        public void accelerate(float val) {
            speed += val;
            if (speed > 100) speed = 100;
        }
    
        public void brake(float val) {
            speed -= val;
            if (speed < -30) speed = -30; // задній хід
            if (speed > 0) speed = 0;
        }
    
        public void changeGear(String newGear) {
            gear = newGear;
        }
    }
    

    6️⃣ Cargo.java – Вантаж

    package com.mygame.game;
    
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.math.Vector2;
    
    public class Cargo {
        Texture texture;
        Vector2 offset;
    
        public Cargo(String texturePath) {
            texture = new Texture(texturePath);
            offset = new Vector2(0, -50); // над вантажівкою
        }
    
        public void render(SpriteBatch batch) {
            // Вантаж прикріплений до вантажівки
            batch.draw(texture, 100 + offset.x, 200 + offset.y);
        }
    }
    

    7️⃣ Dashboard.java – Приборна панель

    package com.mygame.game;
    
    import com.badlogic.gdx.Gdx;
    import com.badlogic.gdx.graphics.Color;
    import com.badlogic.gdx.graphics.g2d.BitmapFont;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
    
    public class Dashboard {
        ShapeRenderer shapeRenderer;
        BitmapFont font;
    
        public Dashboard() {
            shapeRenderer = new ShapeRenderer();
            font = new BitmapFont();
        }
    
        public void update(Truck truck) {
            // можна оновлювати показники
        }
    
        public void render(SpriteBatch batch) {
            batch.end();
    
            shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
            // спідометр
            shapeRenderer.setColor(Color.RED);
            shapeRenderer.rect(600, 100, 100, 20);
            shapeRenderer.setColor(Color.GREEN);
            shapeRenderer.rect(600, 100, truck.getSpeed() * 1, 20); // масштаб
    
            // тахометр
            shapeRenderer.setColor(Color.BLUE);
            shapeRenderer.rect(600, 130, 100, 20);
            shapeRenderer.setColor(Color.YELLOW);
            shapeRenderer.rect(600, 130, truck.getRpm() * 0.01f, 20);
    
            shapeRenderer.end();
    
            batch.begin();
            font.draw(batch, "Gear: " + truck.getGear(), 600, 180);
        }
    }
    

    8️⃣ Location.java – Локація (фон)

    package com.mygame.game;
    
    import com.badlogic.gdx.graphics.Texture;
    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    
    public class Location {
        Texture background;
    
        public Location(String path) {
            background = new Texture(path);
        }
    
        public void render(SpriteBatch batch) {
            batch.draw(background, 0, 0, MyGame.V_WIDTH, MyGame.V_HEIGHT);
        }
    }
    

    📱 Android Integration

    Створіть Android-проєкт у Android Studio, додайте LibGDX туди, і встановіть MyGame як ApplicationListener.


    🧪 Розширення

    • Додайте кілька вантажівок та оберіть їх у меню.
    • Додайте кнопки управління (вперед/назад, КПП).
    • Реалізуйте перехід між локаціями по завершенню маршруту.
    • Додайте збереження прогресу.

    📚 Корисні ресурси


    🚀 Якщо хочеш, я можу згенерувати готовий приватний GitHub-репозиторій із цим кодом.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.