9front - general discussion about 9front
 help / color / mirror / Atom feed
From: PeacefulGena <PeacefulGena@protonmail.com>
To: "9front@9front.org" <9front@9front.org>
Subject: [9front] Invitation for testing a new game for 9front: Jetpack Game
Date: Fri, 21 Jul 2023 22:24:58 +0000	[thread overview]
Message-ID: <PREjZMEoZN1OtA3gUXPkOJn1g5O70pBiqEEuAPGczh56Zz_1ShipwBlXmALt12LrZFNdgjMrvKkxHTeCy2a0P36xYth1Kj4WHEGrKoeqYqQ=@protonmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2279 bytes --]

Dear 9front community,

I hope this message finds you all well. As a newcomer to this group, this is my first actual interaction with you, the 9front community. I've been a silent observer for over two years now, using 9front in a virtual machine and admiring the dedication and innovation that has brought this project to where it is today.

Today, I have some exciting news to share with you all.

I've been working with OpenAI's language model, ChatGPT, to develop a new game for the 9front OS. This unique project is a testament to the capabilities of AI models in coding. Every bit of the game code was written by ChatGPT, and it's been a fascinating journey watching it come to fruition.

The game is a simple yet enjoyable one, where a player, represented by a square, must navigate through obstacles and gather coins while moving along the y-axis. The game dynamics involve acceleration, maximum speed, and movement based on the state of the up arrow key. Obstacles and coins continuously appear from the right side of the screen, and the game ends if the player collides with an obstacle. However, if the player collides with a coin, their score increases.

Currently, the game is still in its testing phase, and this is where I need your help. Due to my limited hardware capacity, I've been running the game in a virtual machine environment where it's not performing at its best. I'm reaching out to this community to ask for your help in testing this game on a bare metal installation of 9front.

If the game runs smoothly and the community finds it interesting, I'm looking forward to submitting it for inclusion in the 9front OS. Your feedback and suggestions would be invaluable for fine-tuning the game dynamics and squashing any bugs that might surface.

I believe that this game, if successfully implemented, could add another fun component to our beloved 9front OS. Please let me know if you're interested in being a part of this testing process.

I will gladly share the source code with anyone willing to test it and look forward to your feedback.

Thank you for considering this request. I'm eager to hear your thoughts and excited about the potential for this unique collaboration between AI and human programming!

Best regards,

Gena

[-- Attachment #2: jetpack.c --]
[-- Type: text/plain, Size: 8987 bytes --]

#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>

enum {
    WINDOW_WIDTH = 800,
    WINDOW_HEIGHT = 600,
    PLAYER_SIZE = 20,
    PLAYER_SPEED = 5,
    BULLET_SPEED = 50,
    OBSTACLE_SPEED = 3,
    NUM_OBSTACLES = 2,
    ZAPPER_HEIGHT = 50,
    SAW_RADIUS = 50,
    NUM_COINS = 20,
    COIN_RADIUS = 10,
    FLOOR_AND_CEILING_HEIGHT = 50,
    UPARROW = 'j',
};

typedef enum { ZAPPER_WALL, SAW_BLADE } ObstacleType;

typedef struct Obstacle {
    ObstacleType type;
    int x, y, exist;
} Obstacle;

typedef struct SawBlade {
    Obstacle obstacle;
    int radius;
    double angle;
} SawBlade;

typedef struct Coin {
    int x, y, exist;
} Coin;

typedef struct Bullet {
    int x, y, exist;
} Bullet;

Obstacle* obstacles[NUM_OBSTACLES];
int playerX = -PLAYER_SIZE, playerY = WINDOW_HEIGHT / 2 - PLAYER_SIZE / 2;
int upPressed = 0, spacePressed = 0, gameStarted = 0;
int currentSpeed = 0;
int maxSpeed = 15;
int acceleration = 1;
int deceleration = 1;
int gameOver = 0;
int coinCounter = 0;
Bullet bullet;
Coin coins[NUM_COINS];

void eresized(int new)
{
    if (new && getwindow(display, Refnone) < 0)
        sysfatal("can't reattach to window");
}

void drawPlayer(void)
{
    Rectangle r;

    r = Rect(playerX, playerY, playerX + PLAYER_SIZE, playerY + PLAYER_SIZE);
    draw(screen, r, display->black, nil, ZP);
}

void drawObstacles(void)
{
    Rectangle r;

    for (int i = 0; i < NUM_OBSTACLES; i++) {
        if (obstacles[i]->exist == 0)
            continue;

        switch (obstacles[i]->type) {
        case ZAPPER_WALL:
            r = Rect(obstacles[i]->x, obstacles[i]->y, obstacles[i]->x + WINDOW_WIDTH, obstacles[i]->y + ZAPPER_HEIGHT);
            draw(screen, r, display->black, nil, ZP);
            break;
        case SAW_BLADE: {
            SawBlade* sawBlade = (SawBlade*)obstacles[i];
            int x = sawBlade->obstacle.x + sawBlade->radius * cos(sawBlade->angle);
            int y = sawBlade->obstacle.y + sawBlade->radius * sin(sawBlade->angle);
            fillellipse(screen, Pt(x, y), sawBlade->radius, sawBlade->radius, display->black, ZP);
            break;
        }
        }
    }
}

void drawCoins(void)
{
    Point c;

    for (int i = 0; i < NUM_COINS; i++) {
        if (coins[i].exist == 0)
            continue;

        c = Pt(coins[i].x, coins[i].y);
        fillellipse(screen, c, COIN_RADIUS, COIN_RADIUS, display->white, ZP);
    }
}

void drawFloorAndCeiling(void)
{
    Rectangle r;

    r = Rect(0, 0, WINDOW_WIDTH, FLOOR_AND_CEILING_HEIGHT);
    draw(screen, r, display->black, nil, ZP);

    r = Rect(0, WINDOW_HEIGHT - FLOOR_AND_CEILING_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT);
    draw(screen, r, display->black, nil, ZP);
}

void redraw(void)
{
    draw(screen, screen->r, display->white, nil, ZP);

    drawFloorAndCeiling();
    drawPlayer();
    drawObstacles();
    drawCoins();
}

void init(void)
{
    // Initialize obstacles
    Obstacle* zapperWall = malloc(sizeof(Obstacle));
    if (zapperWall) {
        zapperWall->type = ZAPPER_WALL;
        zapperWall->x = WINDOW_WIDTH;
        zapperWall->y = nrand(WINDOW_HEIGHT - ZAPPER_HEIGHT);
        zapperWall->exist = 1;
        obstacles[0] = zapperWall;
    }

    SawBlade* sawBlade = malloc(sizeof(SawBlade));
    if (sawBlade) {
        sawBlade->obstacle.type = SAW_BLADE;
        sawBlade->obstacle.x = WINDOW_WIDTH;
        sawBlade->obstacle.y = nrand(WINDOW_HEIGHT - SAW_RADIUS);
        sawBlade->obstacle.exist = 1;
        sawBlade->radius = SAW_RADIUS;
        sawBlade->angle = 0;
        obstacles[1] = (Obstacle*)sawBlade;
    }

    // Initialize coins
    for (int i = 0; i < NUM_COINS; i++) {
        coins[i].exist = 1;
        coins[i].x = WINDOW_WIDTH + (nrand(WINDOW_WIDTH));
        coins[i].y = nrand(WINDOW_HEIGHT - COIN_RADIUS);
    }
}

int checkCollision(void)
{
    for (int i = 0; i < NUM_OBSTACLES; i++) {
        if (obstacles[i]->exist == 1) {
            switch (obstacles[i]->type) {
            case ZAPPER_WALL:
                if (playerX < obstacles[i]->x + WINDOW_WIDTH &&
                    playerX + PLAYER_SIZE > obstacles[i]->x &&
                    playerY < obstacles[i]->y + ZAPPER_HEIGHT &&
                    playerY + PLAYER_SIZE > obstacles[i]->y)
                    return 1;
                break;
            case SAW_BLADE: {
                SawBlade* sawBlade = (SawBlade*)obstacles[i];
                if ((playerX - obstacles[i]->x) * (playerX - obstacles[i]->x) + (playerY - obstacles[i]->y) * (playerY - obstacles[i]->y) <= (sawBlade->radius + PLAYER_SIZE) * (sawBlade->radius + PLAYER_SIZE))
                    return 1;
                break;
            }
            }
        }
    }

    // Check collision with coins
    for (int i = 0; i < NUM_COINS; i++) {
        if (coins[i].exist == 1) {
            if (playerX < coins[i].x + COIN_RADIUS &&
                playerX + PLAYER_SIZE > coins[i].x &&
                playerY < coins[i].y + COIN_RADIUS &&
                playerY + PLAYER_SIZE > coins[i].y) {
                coins[i].exist = 0;
                coinCounter++;
            }
        }
    }

    return 0;
}

void main(void)
{
    Event e;
    Mouse m;

    if (initdraw(0, 0, "Jetpack Game") < 0)
        sysfatal("initdraw failed: %r");
    einit(Emouse | Ekeyboard);
    eresized(0);

    init();

    for (;;) {
        while (ecanread(Emouse | Ekeyboard)) {
            switch (event(&e)) {
                case Ekeyboard:
                    if (e.kbdc == UPARROW) {
                        upPressed = 1;
                        gameStarted = 1;
                    } else if (e.kbdc == -UPARROW) { // Arrow up released
                        upPressed = 0;
                    } else if (e.kbdc == 'q') {
                        exits(0);
                    }
                    break;
                case Emouse:
                    m = e.mouse;
                    if (m.buttons == 4) {
                        exits(0);
                    }
                    break;
            }
        }

        if (gameStarted) {
            if (upPressed) {
                if (currentSpeed < maxSpeed && playerY > FLOOR_AND_CEILING_HEIGHT)
                    currentSpeed += acceleration;

                playerY -= currentSpeed;

                if (bullet.exist == 0) {
                    bullet.exist = 1;
                    bullet.x = playerX;
                    bullet.y = playerY + PLAYER_SIZE;
                }
            } else {
                if (currentSpeed > 0 && playerY < WINDOW_HEIGHT - FLOOR_AND_CEILING_HEIGHT - PLAYER_SIZE) {
                    currentSpeed -= deceleration;
                    playerY -= currentSpeed;
                } else {
                    if (playerY < WINDOW_HEIGHT - FLOOR_AND_CEILING_HEIGHT - PLAYER_SIZE) {
                        currentSpeed -= deceleration;
                        playerY -= currentSpeed;
                    }
                }
            }

            if (bullet.exist) {
                bullet.y += BULLET_SPEED;
                if (bullet.y >= WINDOW_HEIGHT)
                    bullet.exist = 0;
            }

            for (int i = 0; i < NUM_OBSTACLES; i++) {
                if (obstacles[i]->exist == 1) {
                    obstacles[i]->x -= OBSTACLE_SPEED;

                    switch (obstacles[i]->type) {
                    case ZAPPER_WALL:
                        if (obstacles[i]->x < -WINDOW_WIDTH) {
                            obstacles[i]->x = WINDOW_WIDTH;
                            obstacles[i]->y = nrand(WINDOW_HEIGHT - ZAPPER_HEIGHT);
                        }
                        break;
                    case SAW_BLADE: {
                        SawBlade* sawBlade = (SawBlade*)obstacles[i];
                        sawBlade->angle += 0.05;
                        if (obstacles[i]->x < -SAW_RADIUS) {
                            obstacles[i]->x = WINDOW_WIDTH;
                            obstacles[i]->y = nrand(WINDOW_HEIGHT - SAW_RADIUS);
                        }
                        break;
                    }
                    }

                    if (checkCollision())
                        gameOver = 1;
                }
            }

            if (gameOver == 0)
                redraw();
            else {
                print("Game Over! Final score: %d\n", coinCounter);
                exits(0);
            }
        } else {
            playerX += PLAYER_SPEED;
            if (playerX >= WINDOW_WIDTH / 2 - PLAYER_SIZE / 2)
                gameStarted = 1;

            redraw();
        }

        sleep(16); // update approximately every 16 ms or about 60 times per second
    }
}

             reply	other threads:[~2023-07-21 22:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 22:24 PeacefulGena [this message]
2023-07-22 13:31 ` Csepp
2023-07-22 14:10   ` Jacob Moody
2023-07-22 15:13     ` qwx
2023-07-22 21:01       ` PeacefulGena
2023-07-22 21:21         ` qwx
2023-07-22 16:28 ` ori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='PREjZMEoZN1OtA3gUXPkOJn1g5O70pBiqEEuAPGczh56Zz_1ShipwBlXmALt12LrZFNdgjMrvKkxHTeCy2a0P36xYth1Kj4WHEGrKoeqYqQ=@protonmail.com' \
    --to=peacefulgena@protonmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).