Weekly Qbasic and Qb64 Lesson Topics
April 19, 2024, 05:47:31 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Simple array based game...Rotate

Pages: [1]
  Print  
Author Topic: Simple array based game...Rotate  (Read 481 times)
Unseen Machine
Post Demos
*
Posts: 46


« on: March 28, 2011, 08:28:23 pm »

Rules:

Use either mouse or arrow keys to rotate the grid.
Once your block (blue) has stopped falling you can rotate again, you do not have to wait for the other blocks to stop.
If a yellow block lands on you, you die and the game restarts.
To win make the blue block contact the red block.

You can build your own levels by creating new data blocks, 1 = wall, 2 = red block, 3 = you, 4 = enemy (max of 10), 9 = when read the program will exit.

This game is not finished and i would appreciate some feedback on what you would like to see in it, and anything else you can think of.

Graphics and GDK download (Unzip to your qb64 folder) : http://dl.dropbox.com/u/8822351/Rotate.zip

Here's the current code :
Code:
GDK_Start
GDK_Screen_SetRes Main, 800, 600, 32, 0
_TITLE "Rotate v.01"

REDIM SHARED Level(12, 12) AS INTEGER, LevelBlocks(4) AS Sprite
DIM SHARED CopyArray(12, 12) AS INTEGER
DIM RotArrows(2) AS GameObject, Mouse AS MouseState, MouseRect AS Rectangle, KB AS KeyBoardState
DIM OldKB AS KeyBoardState, OldMouse AS MouseState
DIM PlyrCol AS INTEGER, PlyrRow AS INTEGER, LevelPar AS INTEGER, CurrentLevel AS INTEGER
DIM SHARED EnemyCol(10) AS INTEGER, EnemyRow(10) AS INTEGER, EnemyCount AS INTEGER, EnemyMax AS INTEGER
DIM BlockIsFalling AS INTEGER

GDK_Sprite_New LevelBlocks(0), "GreenBlock.png", 1, 1, 1, 1
GDK_Sprite_New LevelBlocks(1), "RedBlock.png", 1, 1, 1, 1
GDK_Sprite_New LevelBlocks(2), "BlueBlock.png", 1, 1, 1, 1
GDK_Sprite_New LevelBlocks(3), "YellowBlock.png", 1, 1, 1, 1

FOR i% = 0 TO 3
    GDK_Sprite_Show LevelBlocks(i%)
    GDK_Sprite_SetAlpha LevelBlocks(i%), _RGB(255, 0, 255)
NEXT

GDK_GameObject_New RotArrows(0), "arrow.png", 1, 1, 80, 300, 0, 2 * ATN(1)
GDK_GameObject_New RotArrows(1), "arrow.png", 1, 1, 720, 300, 0, 2 * ATN(1)
GDK_Sprite_SetRotationPoint RotArrows(0).Sprite, RotArrows(0).Sprite.Width / 2, RotArrows(0).Sprite.Height / 2
GDK_Sprite_SetRotationPoint RotArrows(1).Sprite, RotArrows(1).Sprite.Width / 2, RotArrows(1).Sprite.Height / 2
GDK_Rectangle_New RotArrows(0).Rect, RotArrows(0).Vector.X - 32, RotArrows(0).Vector.Y - 32, 64, 64
GDK_Rectangle_New RotArrows(1).Rect, RotArrows(1).Vector.X - 32, RotArrows(1).Vector.Y - 32, 64, 64

LoadLevel
DropTimer# = TIMER(.001)
EnemyDropTimer# = TIMER(.001)

DO
    DO
        _LIMIT 60

        DrawBackground

        EnemyCount = 0
        FOR j% = 0 TO 11 'Row
            FOR i% = 0 TO 11 'Column
                IF Level(i%, j%) = 1 THEN
                    GDK_Sprite_DrawXY LevelBlocks(0), 150 + (i% * 40), 50 + (j% * 40), 0, 0
                ELSEIF Level(i%, j%) = 2 THEN
                    GDK_Sprite_DrawXY LevelBlocks(1), 150 + (i% * 40), 50 + (j% * 40), 0, 0
                ELSEIF Level(i%, j%) = 3 THEN
                    PlyrRow = j%
                    PlyrCol = i%
                    GDK_Sprite_DrawXY LevelBlocks(2), 150 + (i% * 40), 50 + (j% * 40), 0, 0
                ELSEIF Level(i%, j%) = 4 THEN
                    EnemyCol(EnemyCount%) = i%
                    EnemyRow(EnemyCount%) = j%
                    GDK_Sprite_DrawXY LevelBlocks(3), 150 + (i% * 40), 50 + (j% * 40), 0, 0
                    EnemyCount = EnemyCount + 1
                END IF
            NEXT
        NEXT
        GDK_GameObject_Draw RotArrows(0), 0
        GDK_GameObject_Draw RotArrows(1), 0

        IF Level(PlyrCol, PlyrRow + 1) = 0 THEN
            IF TIMER(.001) - DropTimer# >= .3 THEN
                Level(PlyrCol, PlyrRow) = 0
                Level(PlyrCol, PlyrRow + 1) = 3
                DropTimer# = TIMER(.001)
            END IF
            BlockIsFalling = -1
        ELSE
            IF Level(PlyrCol - 1, PlyrRow) = 2 THEN
                GOSUB Win
                EXIT DO
            ELSEIF Level(PlyrCol + 1, PlyrRow) = 2 THEN
                GOSUB Win
                EXIT DO
            ELSEIF Level(PlyrCol, PlyrRow + 1) = 2 THEN
                GOSUB Win
                EXIT DO
            END IF
            BlockIsFalling = 0
        END IF

        FOR i% = 0 TO EnemyMax - 1
            IF Level(EnemyCol(i%), EnemyRow(i%) + 1) = 0 THEN
                IF TIMER(.001) - EnemyDropTimer# >= .3 THEN
                    Level(EnemyCol(i%), EnemyRow(i%)) = 0
                    Level(EnemyCol(i%), EnemyRow(i%) + 1) = 4
                    EnemyDropTimer# = TIMER(.001)
                END IF
            ELSEIF Level(EnemyCol(i%), EnemyRow(i%) + 1) = 3 AND NOT BlockIsFalling THEN
                PRINT "You got crushed!"
                _DISPLAY
                SLEEP 5
                RUN
            END IF
        NEXT

        IF NOT BlockIsFalling THEN
            GDK_Mouse_GetState Mouse
            GDK_Keyboard_GetState KB
            IF Mouse.LMB AND NOT OldMouse.LMB THEN
                GDK_Rectangle_New MouseRect, Mouse.Mx, Mouse.My, 5, 5
                IF GDK_Rectangle_Intersect(MouseRect, RotArrows(0).Rect) THEN
                    RotateArray
                ELSEIF GDK_Rectangle_Intersect(MouseRect, RotArrows(1).Rect) THEN
                    RotateArray
                    RotateArray
                    RotateArray
                END IF
            END IF
            IF KB.Left AND NOT OldKB.Left THEN
                RotateArray
                RotateArray
                RotateArray
            ELSEIF KB.Right AND NOT OldKB.Right THEN
                RotateArray
            END IF
        END IF

        _DISPLAY
        CLS
        OldMouse = Mouse
        OldKB = KB

    LOOP
LOOP

Win:
PRINT "You did it."
_DISPLAY
SLEEP 5
LoadLevel
RETURN

REM $INCLUDE:'UnseenGDK.bm'

SUB DrawBackground
stepval! = 255 / 1320
FOR i% = 660 TO 0 STEP -2
    LINE (0, i%)-(800, i% + 1), _RGB(75, 75, 250 - (i% * stepval!)), BF
NEXT
END SUB


SUB LoadLevel
EnemyMax = 0
FOR j% = 0 TO 11
    FOR i% = 0 TO 11
        READ LevelBit%
        IF LevelBit% = 4 THEN EnemyMax = EnemyMax + 1
        IF LevelBit% = 9 THEN SYSTEM
        Level(i%, j%) = LevelBit%
    NEXT
NEXT
END SUB


SUB RotateArray
FOR Y% = 0 TO 11
    FOR X% = 0 TO 11
        CopyArray(X%, Y%) = Level(X%, Y%)
    NEXT
NEXT
FOR Y% = 0 TO 11
    FOR X% = 0 TO 11
        Level(11 - Y%, X%) = CopyArray(X%, Y%)
    NEXT
NEXT
END SUB


DATA 1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,0,2,0,1,0,0,0,0,0,0,1
DATA 1,0,1,0,1,0,1,0,1,4,0,1
DATA 1,0,1,0,1,0,1,0,1,1,0,1
DATA 1,0,1,0,4,0,1,0,0,1,0,1
DATA 1,0,1,1,1,1,1,1,0,1,0,1
DATA 1,0,1,0,0,3,0,0,0,1,0,1
DATA 1,0,1,0,1,1,1,1,1,1,0,1
DATA 1,0,1,0,0,0,0,0,0,0,0,1
DATA 1,0,1,1,1,1,1,1,1,1,0,1
DATA 1,0,0,0,0,0,0,0,0,0,0,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1

DATA 1,1,1,1,1,1,1,0,0,0,0,0
DATA 1,0,0,4,0,0,0,1,0,0,0,0
DATA 1,0,1,1,1,1,0,0,1,0,0,0
DATA 1,0,0,0,0,0,0,0,0,1,1,0
DATA 1,4,0,0,1,0,3,1,0,0,0,1
DATA 0,1,0,0,1,1,1,1,0,0,0,1
DATA 0,1,0,4,1,0,0,0,0,0,0,1
DATA 0,1,0,1,1,0,1,1,1,1,1,0
DATA 1,0,0,0,0,0,1,0,0,0,0,0
DATA 1,0,1,0,1,1,0,0,0,0,0,0
DATA 1,0,2,1,0,0,0,0,0,0,0,0
DATA 1,1,1,1,0,0,0,0,0,0,0,0



DATA 9,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0


Hope you like it, DarthWho gave me the idea from a game called turnabout.

Unseen
Report Spam   Logged

Share on Facebook Share on Twitter

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: March 28, 2011, 10:12:27 pm »

Thanks alot for posting this Unseen,... I like it,...
from Garry.
I just got real sleepy after playing it,...but not because I got bored, I kept trying over and over, to get the red and blue together, and also avoid being crushed,...
From Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #2 on: March 29, 2011, 12:15:42 pm »

Hi all,
    Very nice game unseen. Excellent graphics all it needs is noise (music). Another fine example of the GDK lib.
OlDosLover.
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy