ウチツクシ

やったゲームのこと(大体STG)とか作ったゲームのこと

Star: The Gathering ソースコード

整理前のコードは http://codetter.com/?p=1037
制限時間と☆の速度と円の広がる速さなどを変えてます。

; HSP 3.4β2
#packopt name "START"
#packopt hide 1
#define GAMETITLE "Star: The Gathering"
    sz = 32
    buffer 1, sz, sz
    font msgothic, sz, 16
    color
    boxf
    color 255, 255, 255
    mes "☆"
    gsel 0, 1
    title GAMETITLE
    celdiv 1, , , sz / 2, sz / 2
    font "arial", 24, 16
    starNum = 100
    ddim starPosX, starNum
    ddim starPosY, starNum
    ddim starPosX, starNum
    ddim starVelY, starNum
    ddim gstarPosX, starNum
    ddim gstarPosY, starNum
*init
    dim gstarLife, starNum
    repeat starNum
        genStar cnt
    loop
    circleSize = 0.0
    remain = 66 * 20
*mainLoop
    stick key, 256
    if (key & 256) {
        mlbDown = 1
        circleSize += 1.3
        if (circleSize > 120) {
            circleSize = 120.0
        }
    } else {
        if (mlbDown) {
            repeat starNum
                x = mousex - starPosX(cnt)
                y = mousey - starPosY(cnt)
                if (sqrt(x * x + y * y) <= circleSize) {
                    if (scene) {
                        score++
                    }
                    gstarLife(gsIdx) = 10
                    gstarPosX(gsIdx) = starPosX(cnt)
                    gstarPosY(gsIdx) = starPosY(cnt)
                    gsIdx = (gsIdx + 1) \ starNum
                    genStar cnt
                }
            loop
        }
        mlbDown = 0
        circleSize = 0.0
    }
    if (scene) {
        if (key & 128) {
            scene = 0
        }
    } else {
        if (key & 16) {
            score = 0
            scene = 1
            goto *init
        }
    }
    repeat starNum
        starPosX(cnt) += starVelX(cnt)
        starPosY(cnt) += starVelY(cnt)
        starVelX(cnt) *= 0.997
        starVelY(cnt) *= 0.997
        if (starPosX(cnt) < 0) {
            starPosX(cnt) = -starPosX(cnt)
            starVelX(cnt) = -starVelX(cnt)
        }
        if (starPosX(cnt) > 640) {
            starPosX(cnt) = 1280.0 - starPosX(cnt)
            starVelX(cnt) = -starVelX(cnt)
        }
        if (starPosY(cnt) < 0) {
            starPosY(cnt) = -starPosY(cnt)
            starVelY(cnt) = -starVelY(cnt)
        }
        if (starPosY(cnt) > 480) {
            starPosY(cnt) = 960.0 - starPosY(cnt)
            starVelY(cnt) = -starVelY(cnt)
        }
    loop
    repeat starNum
        if (gstarLife(cnt) > 0) {
            gstarLife(cnt)--
        }
    loop
    redraw 0
    color
    boxf
    gmode 5, , , 255
    repeat starNum
        pos starPosX(cnt), starPosY(cnt)
        celput 1
    loop
    repeat starNum
        if (gstarLife(cnt) > 0) {
            pos gstarPosX(cnt), gstarPosY(cnt)
            gmode 5, , , gstarLife(cnt) * 30 + 40
            s = 0.4 * (7 - gstarLife(cnt)) + 1
            celput 1, , s, s
        }
    loop
    color 255, 255, 255
    circle mousex - circleSize, mousey - circleSize, mousex + circleSize, mousey + circleSize, 0
    gmode 3, , , 180
    color
    grect 320, 15, , 200, 30
    color 255, 255, 255
    pos 270, 0
    mes strf("%3d", score)
    pos 340, 0
    mes strf("%2.1f", double(remain) / 66)
    if (scene = 0) {
        color
        grect 340, 250, , 340, 160
        color 255, 255, 255
        pos 200, 200
        mes GAMETITLE
        mes ""
        mes "Mouse Left button: gather"
        mes "Space key: start"
    }
    redraw
    await 15
    if (scene) {
        remain--
        if (remain == 0) {
            scene = 0
        }
    }
    goto *mainLoop
 
#deffunc genStar int _id
    starPosX(_id) = double(rnd(640))
    starPosY(_id) = double(rnd(480))
    starVelX(_id) = (double(rnd(50)) / 10) * (rnd(2) * 2 - 1)
    starVelY(_id) = (double(rnd(50)) / 10) * (rnd(2) * 2 - 1)
    return