
-----------------------------------
jason98wang
Sat Jan 07, 2017 2:27 pm

Problems with my tetris game
-----------------------------------
HI guys im making a tetris game but i dont know how to stack blocks on top of each other and avoid collision plz help.

-----------------------------------
Insectoid
Sun Jan 08, 2017 3:18 am

RE:Problems with my tetris game
-----------------------------------
What have you tried so far?

-----------------------------------
jason98wang
Mon Jan 09, 2017 9:42 pm

RE:Problems with my tetris game
-----------------------------------
um... everything i tried using what dot colour but it doesn't seem to work. My main problem is how the blocks will stack on top of each other and how the blocks fall down again after a row is cleared

-----------------------------------
Insectoid
Tue Jan 10, 2017 10:23 am

RE:Problems with my tetris game
-----------------------------------
There are a number of collision detection tutorials on this site that you may want to take a look at. The Turing Walkthrough may be helpful.

I suggest you start small- try to make two squares stack on top of each other before worrying about complex Tetris shapes.

-----------------------------------
jason98wang
Tue Jan 10, 2017 11:00 am

RE:Problems with my tetris game
-----------------------------------
bro helo me lol

-----------------------------------
Insectoid
Tue Jan 10, 2017 2:13 pm

RE:Problems with my tetris game
-----------------------------------
I can't help you if you won't try.

-----------------------------------
jason98wang
Wed Jan 11, 2017 10:33 am

RE:Problems with my tetris game
-----------------------------------
im currently using what dot colour to do the program but im not sure how to detect the bottom of the block

-----------------------------------
jason98wang
Thu Jan 12, 2017 7:40 pm

RE:Problems with my tetris game
-----------------------------------
currently i have been able to move the blocks around but my problem is after the blocks move the previous one isnt deleted, is there a way i can fix that?

-----------------------------------
Insectoid
Fri Jan 13, 2017 10:52 am

RE:Problems with my tetris game
-----------------------------------
It's hard to tell you what the problem is without seeing your code.

-----------------------------------
jason98wang
Sun Jan 15, 2017 1:26 am

RE:Problems with my tetris game
-----------------------------------
setscreen ("graphics:300;600")
var x : int := 90

var y : int := 600 - 30
var position : int := 1
var randBlock : int
var x_Right, x_Left, y_Bottom1, y_Bottom2, num_blocks_per_row, highscore : int
var gameover, stop : boolean
drawfillbox(300,600,-300,0,black)


%naming variables for different shapes
%This is also setting up how to draw each shape in each position

%Checking if the any blocks has reached the top row
process endgame
    for x1 : 0 .. 300
        if whatdotcolor (x1, 600) not= black then
            gameover := true
            exit when gameover
        end if
    end for
end endgame

%clearing the rows after the whole row is filled
process filledrows
    for y1 : 0 .. 600 
        num_blocks_per_row := 0
        for x1 : 0 .. 300 
            if whatdotcolor (x1, y1) not= black then
                num_blocks_per_row := num_blocks_per_row + 1
                if num_blocks_per_row = 10 then
                    drawfillbox (x1, y1, x1 + 30, y1 - 30, black)
                    % highscore := highscore + 100
                end if
            end if
        end for
    end for
end filledrows

%I-Block
var Block0 := Pic.FileNew ("Block0.bmp")
var Block1 := Pic.FileNew ("Block1.bmp")
Block0 := Pic.Scale (Block0, 30, 120)
Block1 := Pic.Scale (Block1, 120, 30)
%rotations
procedure I_Block
    if position = 1 then
        Pic.Draw (Block1, x, y, picMerge)
        x_Left := x
        x_Right := x + 120
        y_Bottom1 := y
    elsif position = 2 then
        Pic.Draw (Block0, x + 60, y - 90, picMerge)
        x_Left := x
        x_Right := x + 30
        y_Bottom1 := y
    elsif position = 3 then
        Pic.Draw (Block1, x, y, picMerge)
        x_Left := x
        x_Right := x + 120
        y_Bottom1 := y
    elsif position = 4 then
        Pic.Draw (Block0, x + 60, y - 90, picMerge)
        x_Left := x
        x_Right := x + 30
        y_Bottom1 := y
    end if
end I_Block

%L-Block
var Block2 := Pic.FileNew ("Block2.bmp")
var Block3 := Pic.FileNew ("Block3.bmp")
Block2 := Pic.Scale (Block2, 30, 60)
Block3 := Pic.Scale (Block3, 60, 30)
%rotations
procedure L_Block
    if position = 1 then
        Pic.Draw (Block2, x + 30, y - 30, picMerge)
        Pic.Draw (Block3, x + 30, y - 60, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := 60
    elsif position = 2 then
        Pic.Draw (Block2, x, y - 30, picMerge)
        Pic.Draw (Block3, x + 30, y, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 3 then
        Pic.Draw (Block2, x + 30, y - 60, picMerge)
        Pic.Draw (Block3, x, y, picMerge)
        x_Left := x
        x_Right := x + 30
        y_Bottom1 := y - 60
        y_Bottom2 := y
    elsif position = 4 then
        Pic.Draw (Block3, x, y - 30, picMerge)
        Pic.Draw (Block2, x + 60, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    end if
end L_Block

%O-Block
var Block4 := Pic.FileNew ("Block4.bmp")
Block4 := Pic.Scale (Block4, 60, 60)
procedure O_Block
    if position < 5 then
        Pic.Draw (Block4, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 30
    end if
end O_Block

%S-Block
var Block5 := Pic.FileNew ("Block5.bmp")
var Block6 := Pic.FileNew ("Block6.bmp")
Block5 := Pic.Scale (Block5, 60, 30)
Block6 := Pic.Scale (Block6, 30, 60)
%rotations
procedure S_Block
    if position = 1 then
        Pic.Draw (Block5, x, y, picMerge)
        Pic.Draw (Block5, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 2 then
        Pic.Draw (Block6, x + 60, y - 30, picMerge)
        Pic.Draw (Block6, x + 30, y - 60, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 60
        y_Bottom2 := y
    elsif position = 3 then
        Pic.Draw (Block5, x, y, picMerge)
        Pic.Draw (Block5, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 4 then
        Pic.Draw (Block6, x + 60, y - 30, picMerge)
        Pic.Draw (Block6, x + 30, y - 60, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 60
        y_Bottom2 := y
    end if
end S_Block

%T-Block
var Block7 := Pic.FileNew ("Block7.bmp")
var Block8 := Pic.FileNew ("Block8.bmp")
var Block9 := Pic.FileNew ("Block9.bmp")
var Block9copy := Pic.FileNew ("Block9copy.bmp")
Block9copy := Pic.Scale (Block9copy, 30, 30)
Block7 := Pic.Scale (Block7, 90, 30)
Block8 := Pic.Scale (Block8, 30, 90)
Block9 := Pic.Scale (Block9, 30, 30)
%rotations
procedure T_Block
    if position = 1 then
        Pic.Draw (Block9, x + 30, y, picMerge)
        Pic.Draw (Block7, x, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y
    elsif position = 2 then
        Pic.Draw (Block8, x + 30, y - 60, picMerge)
        Pic.Draw (Block9copy, x + 60, y - 30, picMerge)
        x_Left := x
        x_Right := x + 30
        y_Bottom1 := y - 60
        y_Bottom2 := y - 30
    elsif position = 3 then
        Pic.Draw (Block7, x, y, picMerge)
        Pic.Draw (Block9, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 4 then
        Pic.Draw (Block8, x + 60, y - 60, picMerge)
        Pic.Draw (Block9copy, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 60
        y_Bottom2 := y - 30
    end if
end T_Block

%Z-Block
var Block10 := Pic.FileNew ("Block10.bmp")
var Block11 := Pic.FileNew ("Block11.bmp")
Block10 := Pic.Scale (Block10, 30, 60)
Block11 := Pic.Scale (Block11, 60, 30)
%rotations
procedure Z_Block
    if position = 1 then
        Pic.Draw (Block11, x + 30, y, picMerge)
        Pic.Draw (Block11, x, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 2 then
        Pic.Draw (Block10, x + 60, y - 60, picMerge)
        Pic.Draw (Block10, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 60
        y_Bottom2 := y
    elsif position = 3 then
        Pic.Draw (Block11, x + 30, y, picMerge)
        Pic.Draw (Block11, x, y - 30, picMerge)
        x_Left := x
        x_Right := x + 90
        y_Bottom1 := y - 30
        y_Bottom2 := y
    elsif position = 4 then
        Pic.Draw (Block10, x + 60, y - 60, picMerge)
        Pic.Draw (Block10, x + 30, y - 30, picMerge)
        x_Left := x
        x_Right := x + 60
        y_Bottom1 := y - 60
        y_Bottom2 := y
    end if
end Z_Block
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
randBlock := Rand.Int (1, 6)
process falling123 (randBlock : int)
    loop
        if randBlock = 1 then
            I_Block
        elsif randBlock = 2 then
            L_Block
        elsif randBlock = 3 then
            O_Block
        elsif randBlock = 4 then
            S_Block
        elsif randBlock = 5 then
            T_Block
        elsif randBlock = 6 then
            Z_Block
        end if
    end loop
end falling123


process falling
    loop
        if whatdotcolor (x + 40, y - 30 - 30) = black or whatdotcolor (x + 70, y - 30 - 30) = black then
            if randBlock = 1 then
                delay (100)
                drawfillbox (x, y + 30, x + 120, y + 60, black)
                    y := y - 30
            elsif randBlock = 2 then
                delay (100)
                drawfillbox (x + 30, y + 30, x + 90, y + 60, black)
                drawfillbox (x + 60, y + 30, x + 90, y + 60, black)
                y := y - 30
            elsif randBlock = 3 then
                delay (100)
                drawfillbox (x + 30, y + 30, x + 90, y + 60, black)
                y := y - 30
            elsif randBlock = 4 then
                delay (100)
                drawfillbox (x, y + 30, x + 90, y + 60, black)
                y := y - 30
            elsif randBlock = 5 then
                delay (100)
                drawfillbox (x, y + 30, x + 90, y + 60, black)
                y := y - 30
            elsif randBlock = 5 then
                delay (100)
                drawfillbox (x, y + 30, x + 90, y + 60, black)
                y := y - 30
            elsif randBlock = 6 then
                delay (100)
                drawfillbox (x, y - 30, x + 90, y + 60, black)
                y := y - 30
            end if
        end if
    end loop
end falling
fork falling
%first loop where everything happens
loop
    randBlock := Rand.Int (1, 6)
    x := 90
    y := 600 - 10
    loop
        exit when y = 20
        fork falling123 (randBlock)
        var chars : array char of boolean
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) then
            if y not= 101 then
                position += 1
            end if
            y := y - 30
        end if
        if chars (KEY_RIGHT_ARROW) then
            if y not= 101 then
                x := x + 30
            end if
        end if
        if chars (KEY_LEFT_ARROW) then
            if y not= 101 then
                x := x - 30
            end if
        end if
        if chars (KEY_DOWN_ARROW) then
            %if  not= 101 then
            y := y - 30
            %end if
        end if
    end loop
end loop

-----------------------------------
jason98wang
Sun Jan 15, 2017 1:28 am

RE:Problems with my tetris game
-----------------------------------
this is my current code so far, ill private messgae you the images that you need in order to run it

-----------------------------------
Insectoid
Sun Jan 15, 2017 10:53 am

RE:Problems with my tetris game
-----------------------------------
First of all, you're using processes, which is just plain bad news, as explained [url=http://compsci.ca/v3/viewtopic.php?t=7842&start=0]here.

You need to replace all your processes with procedures. This might take some work, but it should fix a bunch of bugs automatically (even bugs you haven't discovered yet). I wouldn't even bother though, because you're probably going to end up re-writing almost the whole thing. It's easier than trying to save this.

You're making this much more complicated than it needs to be. Tetris is a simple game. It plays on a grid (10x50 or something, no?). The pieces are always lined up with the grid. Collisions are always between the cell on top hitting the cell on the bottom. You can only move left or right one cell at a time. 

But you're writing this as if the screen was the game board. So instead of moving left or right by 1, now we're moving by 30, or 60. Now instead of checking 'x-1' for collisions, we're checking x-30. Instead of 'is cell (x, y) occupied' you're asking 'is location (x-30, y-30) the right color'. This is so much more complicated!

Turing (and most other programming languages) have a convenient way to represent grids- arrays!

var grid : array (0..9, 0..49) of boolean 

Here we've created a 10x50 array to represent our game board. It's of boolean, which means every cell can be either 1 or 0. I've decided that a 0 means that cell is empty, and a 1 means that cell is full. Use a couple of loops to set every cell to 0, so the whole board is empty:

for x : 0..9
    for y : 0..49
        grid (x,  y) := 0
    end for
end for

Making something fall down is easy:

var x := 5
var y := 50

loop
    y -= 1
    delay (500)
    if y = 0 then
        grid (x, y) := 1 %this spot is now full.
        exit
    end loop
end loop

checking for collisions is easy too!

var x := 5
var y := 50

loop
    if grid (x, y-1) = 0 then %check if square below is empty
        y -= 1 %This is the same as y := y - 1
    else
        grid (x, y) := 1
        exit
    end if
    delay (500)
end loop

Look at how simple that code is! It's easy to read, it's easy to write! But we still have to draw everything! Fortunately, that's easy too!

procedure drawEverything

for x: 0..9
    for y : 0..49
        if grid (x, y) = 1 then
            Draw.FillBox (x*10, y*10, x*10+10, y*10+10, red)
        end if
    end for
end for

end drawEverything


We've scaled everything up here by 10 to draw it. Notice how we didn't have to touch any of our logic code? All we did was check if there was a 1 or zero in our grid, and draw a red box there. This means the game can look however you want. It can be flashy, plain, it can use pictures or Draw commands or even just plain text. It doesn't matter. All you need to change is the drawEverything procedure and as long as you don't touch the actual logic code, the game will still work. 

Obviously I've only given you code snippets here and you'll need to fill in the rest, but hopefully you see how simple this can be. It will save you so much time to just start over. You'll only get frustrated trying to make your current code work.

And finally, don't be discouraged. You had to screw it up this bad to learn why doing it this way is bad. If you look far enough back in my post history here (I was in grade 10 once too), you'll see me doing exactly the same thing.

-----------------------------------
jason98wang
Sun Jan 15, 2017 11:26 am

RE:Problems with my tetris game
-----------------------------------
wait sorry i dont really understand can you reexplain it to me

-----------------------------------
jason98wang
Sun Jan 15, 2017 11:28 am

RE:Problems with my tetris game
-----------------------------------
do you think ill be able to finish before wednesday if i restart?

-----------------------------------
Insectoid
Sun Jan 15, 2017 12:06 pm

RE:Problems with my tetris game
-----------------------------------
I think you will. If you don't understand my post, re-read through it until you do. The biggest take-away is separating your game logic from what's drawn on the screen. Doing that will simplify your code so much.

-----------------------------------
jason98wang
Sun Jan 15, 2017 12:14 pm

RE:Problems with my tetris game
-----------------------------------
i tried running it but it keeps on showing error during grid

-----------------------------------
jason98wang
Sun Jan 15, 2017 12:15 pm

RE:Problems with my tetris game
-----------------------------------
based on your previous experience how many lines do you think it will take for me to do it? and how many hours?

-----------------------------------
jason98wang
Sun Jan 15, 2017 12:25 pm

RE:Problems with my tetris game
-----------------------------------
var grid : array (0..9, 0..49) of boolean 
whenever i type in this code it does not work it gives me a error

-----------------------------------
jason98wang
Sun Jan 15, 2017 1:18 pm

RE:Problems with my tetris game
-----------------------------------
var grid : array 0 .. 9, 0 .. 49 of int
for x : 0 .. 9
    for y : 0 .. 49
        grid (x, y) := 0
    end for
end for

%Making something fall down is easy:

var x := 5
var y := 50

loop
    y -= 1
    delay (500)
    if y = 0 then
        grid (x, y) := 1 %this spot is now full.
        exit
    end if
end loop

%checking for collisions is easy too!

x := 5
y := 50

loop
    if grid (x, y - 1) = 0 then %check if square below is empty
        y -= 1 %This is the same as y := y - 1
    else
        grid (x, y) := 1
        exit
    end if
    delay (500)
end loop

%Look at how simple that code is! It's easy to read, it's easy to write! But we still have to draw everything! Fortunately, that's easy too!

procedure drawEverything

    for x : 0 .. 9
        for y : 0 .. 49
            if grid (x, y) = 1 then
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, red)
            end if
        end for
    end for

end drawEverything

i have changed some of the code so now it runs but however everytime it runs, nothing shows up

-----------------------------------
Insectoid
Sun Jan 15, 2017 3:21 pm

RE:Problems with my tetris game
-----------------------------------
Don't try to glue my code pieces together. That's not why I wrote them and it will not work. In fact, trying to glue pieces together like that will never work, so don't even try copy & pasting code from now on.

You are making no effort to understand the code I showed you. You need to understand it. Go back to the big post I wrote up earlier, and read through it slowly and carefully. Make sure you understand the code snippet I wrote before you move on to the next one. It isn't easy, there are no shortcuts. Don't even bother writing any code until you understand mine, because it will not work.

based on your previous experience how many lines do you think it will take for me to do it? and how many hours?

I wouldn't plan on visiting friends after school for the next few days. This will take you a long time. The more shortcuts you try to take, the longer it will take. The sooner you start doing it right, the sooner you'll get it done.


Break the problem down into pieces. I think that was the first advice I gave you and the first advice you ignored. I don't know why you ignore it, it's good advice. I've been doing this for a long time now, so you can trust me when I say these things. Try to make a game where a single box falls on top of another box. That's one of the smallest 'pieces' of the Tetris program. If you can get that working, you're well on your way to making the rest of the game.

-----------------------------------
jason98wang
Sun Jan 15, 2017 4:33 pm

RE:Problems with my tetris game
-----------------------------------
im looking at your code and i don't understand how this piece of code would makes the blocks fall. since its not redrawing the blocks or anything like that? so how would the program know to redraw the block? also isn't the only way to clear block by covering it up with the colour of the background? 



%Making something fall down is easy: 

var x := 5 
var y := 50 

loop 
y -= 1 
delay (500) 
if y = 0 then 
grid (x, y) := 1 %this spot is now full. 
exit 
end if 
end loop

-----------------------------------
jason98wang
Sun Jan 15, 2017 5:58 pm

RE:Problems with my tetris game
-----------------------------------
Also another part i don't really understand is everytime the block changes location how are you removing the previous block so it looks like the block is actually falling?

-----------------------------------
jason98wang
Sun Jan 15, 2017 6:52 pm

RE:Problems with my tetris game
-----------------------------------
Also will i be using the stuff like view.update, view.set and etc? because i have no idea what they are and how to use them

-----------------------------------
Insectoid
Sun Jan 15, 2017 10:11 pm

RE:Problems with my tetris game
-----------------------------------
im looking at your code and i don't understand how this piece of code would makes the blocks fall.

It does make the blocks fall. It doesn't draw it, because it's not supposed to. It's just supposed to make the block fall. That's what it's doing. You need a different function to draw it, somewhere else.

Don't try to remove the previous block. That's hard. It's a lot easier to just erase EVERYTHING with cls, and then re-draw only the parts we want. This is why we separate the game code from the drawing code. 

You won't be using View.Update, because it's just not worth worrying about right now.


Why don't you try to make one box land on top of another? That's easy. It's a lot better to start with easy problems before moving on to hard ones.

-----------------------------------
jason98wang
Mon Jan 16, 2017 7:46 am

RE:Problems with my tetris game
-----------------------------------
Also drawing the blocks are you doing that by physically drawing the shapes?

-----------------------------------
jason98wang
Mon Jan 16, 2017 7:52 am

RE:Problems with my tetris game
-----------------------------------
Also if you use CLS how would turing remember where the other blocks that have fallen are loaded?

-----------------------------------
jason98wang
Mon Jan 16, 2017 7:53 am

RE:Problems with my tetris game
-----------------------------------
im not trying to copy but can you show me how the blocks are going to fall i really don't understand

-----------------------------------
jason98wang
Mon Jan 16, 2017 8:38 am

RE:Problems with my tetris game
-----------------------------------
You say stacking 2 blocks on top of each other is easy,  but I just tried it for 30 minutes and I couldn't get it. Can you show me how to do it so I can understand the concept.

-----------------------------------
jason98wang
Mon Jan 16, 2017 1:05 pm

RE:Problems with my tetris game
-----------------------------------
if you do cls how are you gonna remember the location of the blocks that has fallen

-----------------------------------
jason98wang
Mon Jan 16, 2017 8:56 pm

RE:Problems with my tetris game
-----------------------------------
setscreen ("graphics:300;600")
var grid : array 0 .. 10, 0 .. 20 of int
var dely : int
var turn : int
var blockType : int
var chars : array char of boolean
dely := 500
for x : 0 .. 10
    for y : 0 .. 20
        grid (x, y) := 0
    end for
end for


%1 means block occupuy that positino
%0 means its an empty block
%Making blocks fall

var x := 10
var y := 60
turn := 1
var array_x : int := 10
var array_y : int := 20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%All the procedures of drawing and the different shapes and different turns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%L block%%%%%%%%%
procedure L_block_White
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
    Draw.FillBox (x * 10 + 60, y * 10, x * 10 + 90, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
end L_block_White

procedure L_block


    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 42)
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 42)
    Draw.FillBox (x * 10 + 60, y * 10, x * 10 + 90, y * 10 + 30, 42)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 42)
end L_block

procedure L_block_turn_1
    loop
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            cls
            dely := 200
            y := y - 1
            put y
            L_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            end if
            if chars (KEY_RIGHT_ARROW) then
                put x
                if x < 21 then
                    x := x + 1
                end if
            end if
            if chars (KEY_LEFT_ARROW) then
                if x > 21 then
                    x := x - 1
                end if
            end if
            if chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
        end loop
        array_x := round (x / 30)
        array_y := round (y / 30)


        grid (array_x, array_y) := 1   %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1
    end loop

end L_block_turn_1

%%%%%%Z block%%%%%%%%%
procedure Z_block_White
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, white)
    Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, white)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, white)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, white)
end Z_block_White

procedure Z_block
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, brightred)
    Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, brightred)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, brightred)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, brightred)
end Z_block

%%%%%%%%%%%S block%%%%%%%%%%%%
procedure S_block_White
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
    Draw.FillBox (x * 10 - 30, y * 10 - 30, x * 10, y * 10, 0)
end S_block_White

procedure S_block
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 10)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 10)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 10)
    Draw.FillBox (x * 10 - 30, y * 10 - 30, x * 10, y * 10, 10)
end S_block

%%%%%%%%J block%%%%%%%%%%%%%
procedure J_block_White
    Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 0)
end J_block_White

procedure J_block
    Draw.FillBox (x * 10 - 30, y * 10, x * 10, y * 10 + 30, 9)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 9)
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 9)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 9)
end J_block

%%%%%%%I block%%%%%%%%%%
procedure I_block_White
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
    Draw.FillBox (x * 10, y * 10 - 60, x * 10 + 30, y * 10 - 30, 0)
    Draw.FillBox (x * 10, y * 10 - 90, x * 10 + 30, y * 10 - 60, 0)
end I_block_White

procedure I_block
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 11)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 11)
    Draw.FillBox (x * 10, y * 10 - 60, x * 10 + 30, y * 10 - 30, 11)
    Draw.FillBox (x * 10, y * 10 - 90, x * 10 + 30, y * 10 - 60, 11)
end I_block

%%%%%% O block%%%%%%%%%%
procedure O_block_White
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 0)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 0)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 0)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 0)
end O_block_White

procedure O_block
    Draw.FillBox (x * 10 + 30, y * 10, x * 10 + 60, y * 10 + 30, 14)
    Draw.FillBox (x * 10, y * 10, x * 10 + 30, y * 10 + 30, 14)
    Draw.FillBox (x * 10 + 30, y * 10 - 30, x * 10 + 60, y * 10, 14)
    Draw.FillBox (x * 10, y * 10 - 30, x * 10 + 30, y * 10, 14)
end O_block

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End of procedures%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

loop
    array_x := 10
    array_y := 20
    x := 10
    y := 60
    blockType :=  Rand.Int (1, 6)
    if blockType = 1 then
        loop
            %put array_y
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            L_block_White
            dely := 200
            y := y - 1
            L_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then
                if x < 21 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then
                if x > 0 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1

    elsif blockType = 2 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            Z_block_White
            dely := 200
            y := y - 1
            Z_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then

                if x < 24 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then

                if x > 3 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1

    elsif blockType = 3 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            S_block_White
            dely := 200
            y := y - 1
            S_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then

                if x < 24 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then

                if x > 3 and array_x + 1 = 1 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1
    elsif blockType = 4 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            J_block_White
            dely := 200
            y := y - 1
            J_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then

                if x < 24 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then

                if x > 3 and array_x + 1 = 1 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1
    elsif blockType = 5 then
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = 9
            I_block_White
            dely := 200
            y := y - 1
            I_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then

                if x < 27 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then

                if x > 0 and array_x + 1 = 1 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1
    elsif blockType = 6 then

        loop
        put array_y
            exit when grid (array_x, array_y - 1) = 1 or y = 3
            O_block_White
            dely := 200
            y := y - 1
            O_block
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                %Rotate
            elsif chars (KEY_RIGHT_ARROW) then

                if x < 24 then
                    x := x + 1
                end if
            elsif chars (KEY_LEFT_ARROW) then

                if x > 0 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 15)
            array_y := round (y / 3)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 2, array_y + 1) := 1
    end if

end loop

-----------------------------------
jason98wang
Mon Jan 16, 2017 8:56 pm

RE:Problems with my tetris game
-----------------------------------
i Have tried what you told me to do but currently this is still bugging up, with the animation as well as the blocks stacking, can you help me please

-----------------------------------
Insectoid
Tue Jan 17, 2017 10:50 am

RE:Problems with my tetris game
-----------------------------------
All right, here's a bit of code to help you get started.

[code]

var grid : array 0 .. 9, 0 .. 50 of int
var blockX, blockY : int

%Here we just set the grid to all 0.
for x : 0 .. 9
    for y : 0 .. 49
        grid (x, y) := 0
    end for
    grid (x, 50) := 1 %set the bottom to all 1's, to make a floor
end for

%This checks if grid(x, y) is full or not
%a 1 means that spot is full. A 0 means that spot is taken.
function checkBlock (x : int, y : int) : int
    if grid (x, y) > 0 then
        result 1
    else
        result 0
    end if
end checkBlock

%This just draws everything. It's the only code that draws anything, and drawing things is all it does. It draws upside down, because I'm too lazy to fix it.
%It just loops over every cell in our grid array. If it finds a '1', it drawfills a red box there. Otherwise, it just draws a black box. Then it draws a green box at (blockX, blockY). 
proc drawGrid
    for x : 0 .. 9
        for y : 0 .. 50
            if checkBlock (x, y) = 1 then
                Draw.FillBox (10 * x, 10 * y, 10 * x + 10, 10 * y + 10, red)
            end if
            Draw.Box (10 * x, 10 * y, 10 * x + 10, 10 * y + 10, black)
        end for
    end for
    Draw.FillBox (10 * blockX, 10 * blockY, 10 * blockX + 10, 10 * blockY + 10, green)
end drawGrid


%That's all we need to make it work. Here's the main loop where it all comes together:

blockX := 5
blockY := 0
View.Set ("graphics:100;510")

loop
    %First, we draw everything. Doesn't have to be first. Could be last. Up to you.
    drawGrid
    
    %Here, we check if the block can move down. If it can, it does. If it can't, it sets that spot to filled (1) and then resets to the top. 
    if checkBlock (blockX, blockY + 1) = 0 then
        blockY := blockY + 1 %This moves the block down
    else
        grid (blockX, blockY) := 1 %this sets the spot to '1' ie 'occupied'
        blockY := 0 %this moves the block back to the top
    end if
    delay (10)
    cls %erase EVERYTHING. Everything will get re-drawn at the top of the loop anyway!
end loop
[/code]

It's quite flashy so if you've got epilepsy don't run it. Don't worry about that though, we can fix it later. Trying to fix that now will only cause you more problems.

Notice that the function drawGrid ONLY draws things. There is no game logic. We can change that function all we want, and the game will still work. All of the logic functions are nice and clean- things only move by 1 at a time, collision detection is one super simple line of code, etc. The game itself is easy to write, easy to read, easy to debug. The draw function might be a bit of a mess, but at least the mess is contained there instead of sprawled over the entire codebase.

-----------------------------------
jason98wang
Tue Jan 17, 2017 4:25 pm

RE:Problems with my tetris game
-----------------------------------
This is my current updated program can you help me fix the problem 
setscreen ("graphics:300;600")
var grid : array 0 .. 10, 0 .. 20 of int
var dely : int
var turn : int
var blockType : int
var rightturn, leftturn, bottom : int
var chars : array char of boolean
dely := 500
for x : 0 .. 10
    for y : 0 .. 20
        grid (x, y) := 0
    end for
end for


%1 means block occupuy that positino
%0 means its an empty block
%Making blocks fall

var x := 10
var y := 60
turn := 1
var array_x : int := 5
var array_y : int := 20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%All the procedures of drawing and the different shapes and different turns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure L_block_turn
    if turn = 1 then
        %turn 1
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 42)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 42)
        %turn 2
    elsif turn = 2 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 42)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 42)
        %turn 3
    elsif turn = 3 then
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 42)
        drawfillbox (array_x * 10 + 60, array_y * 10 - 30, array_x * 10 + 90, array_y * 10, 42)
        drawfillbox (array_x * 10 + 60, array_y * 10, array_x * 10 + 90, array_y * 10 + 30, 42)
        %turn 4
    elsif turn = 4 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 42)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 42)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 42)
    end if

end L_block_turn

procedure L_block_turn_White
    if turn = 1 then
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 0)
    elsif turn = 2 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 0)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 0)
    elsif turn = 3 then
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 + 60, array_y * 10 - 30, array_x * 10 + 90, array_y * 10, 0)
        drawfillbox (array_x * 10 + 60, array_y * 10, array_x * 10 + 90, array_y * 10 + 30, 0)
    elsif turn = 4 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 0)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 0)
    end if
end L_block_turn_White
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure J_block_turn
    %turn 1
    if turn = 1 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 9)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 9)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 9)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 9)

        %turn 2
    elsif turn = 2 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 9)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 9)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 9)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 9)

        %turn 3
    elsif turn = 3 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 9)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 9)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 9)
        drawfillbox (array_x * 10 - 30, array_y * 10, array_x * 10, array_y * 10 + 30, 9)
        %turn 4
    elsif turn = 4 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 9)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 9)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 9)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 9)
    end if
end J_block_turn

procedure J_block_turn_White
    if turn = 1 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
    elsif turn = 2 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 0)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 0)
    elsif turn = 3 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10 - 30, array_y * 10, array_x * 10, array_y * 10 + 30, 0)
    elsif turn = 4 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10, array_x * 10 + 30, array_y * 10 + 30, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 0)
    end if
end J_block_turn_White
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure I_block_turn
    %turn 1 + 3
    if turn = 1 or turn = 3 then
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 11)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 11)
        drawfillbox (array_x * 10, array_y * 10 - 90, array_x * 10 + 30, array_y * 10 - 60, 11)
        drawfillbox (array_x * 10, array_y * 10 - 120, array_x * 10 + 30, array_y * 10 - 90, 11)

        %turn 2 + 4
    elsif turn = 2 or turn = 4 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 11)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 11)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 11)
        drawfillbox (array_x * 10 + 60, array_y * 10 - 60, array_x * 10 + 90, array_y * 10 - 30, 11)
    end if
end I_block_turn

procedure I_block_turn_White

    if turn = 1 or turn = 3 then
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10, array_y * 10 - 90, array_x * 10 + 30, array_y * 10 - 60, 0)
        drawfillbox (array_x * 10, array_y * 10 - 120, array_x * 10 + 30, array_y * 10 - 90, 0)

    elsif turn = 2 or turn = 4 then
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 + 60, array_y * 10 - 60, array_x * 10 + 90, array_y * 10 - 30, 0)
    end if
end I_block_turn_White
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure O_block_turn


    drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 14)
    drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 14)
    drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 14)
    drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 14)
end O_block_turn

procedure O_block_turn_White


    drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
    drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
    drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
    drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
end O_block_turn_White


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure S_block_turn

    %turn 1 + 3
    if turn = 1 or turn = 3 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 10)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 10)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 10)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 10)
        %turn 2 + 4
    elsif turn = 2 or turn = 4 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 10)
        drawfillbox (array_x * 10, array_y * 10 - 90, array_x * 10 + 30, array_y * 10 - 60, 10)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 10)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 10)
    end if
end S_block_turn

procedure S_block_turn_White
    if turn = 1 or turn = 3 then
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 0)

    elsif turn = 2 or turn = 4 then
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10, array_y * 10 - 90, array_x * 10 + 30, array_y * 10 - 60, 0)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 60, array_x * 10, array_y * 10 - 30, 0)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 0)
    end if
end S_block_turn_White


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

procedure Z_block_turn
    %turn 1 + 3
    if turn = 1 or turn = 3 then
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, brightred)
        drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, brightred)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, brightred)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, brightred)
    elsif turn = 2 or turn = 4 then
        %turn 2 + 4
        drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, brightred)
        drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, brightred)
        drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, brightred)
        drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, brightred)
    end if 
    end Z_block_turn

    procedure Z_block_turn_White
        if turn = 1 or turn = 3 then
            drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
            drawfillbox (array_x * 10 - 30, array_y * 10 - 30, array_x * 10, array_y * 10, 0)
            drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
            drawfillbox (array_x * 10 + 30, array_y * 10 - 60, array_x * 10 + 60, array_y * 10 - 30, 0)
        elsif turn = 2 or turn = 4 then
            %turn 2 + 4
            drawfillbox (array_x * 10, array_y * 10 - 30, array_x * 10 + 30, array_y * 10, 0)
            drawfillbox (array_x * 10, array_y * 10 - 60, array_x * 10 + 30, array_y * 10 - 30, 0)
            drawfillbox (array_x * 10 + 30, array_y * 10 - 30, array_x * 10 + 60, array_y * 10, 0)
            drawfillbox (array_x * 10 + 30, array_y * 10, array_x * 10 + 60, array_y * 10 + 30, 0)
        end if
    end Z_block_turn_White




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End of procedures%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

loop
    x := 10
    y := 30
    turn := 1
    blockType := 1%Rand.Int (1, 6)
    bottom := 3
    rightturn := 23
    leftturn := 0
    if blockType = 1 then
        loop
            locate (1,1)
            put array_x," ", x
            
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            L_block_turn_White
            dely := 200
            y := y - 1
            L_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn then
                   array_x := array_x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop
        if turn = 1 then
            grid (array_x, array_y) := 1
            grid (array_x, array_y + 1) := 1
            grid (array_x + 1, array_y + 1) := 1
            grid (array_x + 2, array_y + 1) := 1

        elsif turn = 2 then
            grid (array_x, array_y) := 1
            grid (array_x + 1, array_y) := 1
            grid (array_x + 2, array_y + 1) := 1
            grid (array_x + 3, array_y + 1) := 1

        elsif turn = 3 then
            grid (array_x, array_y) := 1
            grid (array_x, array_y + 1) := 1
            grid (array_x + 1, array_y + 1) := 1
            grid (array_x + 2, array_y + 1) := 1

        elsif turn = 4 then
            grid (array_x, array_y) := 1
            grid (array_x, array_y + 1) := 1
            grid (array_x + 1, array_y + 1) := 1
            grid (array_x + 2, array_y + 1) := 1
        end if
    elsif blockType = 2 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            Z_block_turn_White
            dely := 200
            y := y - 1
            Z_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y + 1) := 1      %this spot is now full.
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x + 1, array_y) := 1
        grid (array_x + 2, array_y) := 1

    elsif blockType = 3 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            S_block_turn_White
            dely := 200
            y := y - 1
            S_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x + 1, array_y) := 1
        grid (array_x + 2, array_y + 1) := 1
        grid (array_x + 3, array_y + 1) := 1
    elsif blockType = 4 then
        %put array_y
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            J_block_turn_White
            dely := 200
            y := y - 1
            J_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn and array_x + 1 = 1 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x + 1, array_y) := 1
        grid (array_x + 2, array_y) := 1
        grid (array_x + 3, array_y - 1) := 1
    elsif blockType = 5 then
        loop
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            I_block_turn_White
            dely := 200
            y := y - 1
            I_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn and array_x + 1 = 1 then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 30)
            array_y := round (y / 6)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x, array_y + 1) := 1
        grid (array_x, array_y + 2) := 1
        grid (array_x, array_y + 3) := 1
    elsif blockType = 6 then

        loop
            exit when grid (array_x, array_y - 1) = 1 or y = bottom
            O_block_turn_White
            dely := 200
            y := y - 1
            O_block_turn
            Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                if turn  leftturn then
                    x := x - 1
                end if
            elsif chars (KEY_DOWN_ARROW) then
                dely := 50
            end if

            delay (dely)
            View.Update
            Time.Delay (5)
            array_x := round (x / 15)
            array_y := round (y / 3)
        end loop

        grid (array_x, array_y) := 1         %this spot is now full.
        grid (array_x + 1, array_y + 1) := 1
        grid (array_x, array_y + 1) := 1
        grid (array_x + 1, array_y) := 1
    end if

end loop

-----------------------------------
jason98wang
Tue Jan 17, 2017 5:30 pm

RE:Problems with my tetris game
-----------------------------------
Hi, im wordering how are you gonna rid of falling blocks? because if you use cls then won't the landed blocks reset?

-----------------------------------
Insectoid
Tue Jan 17, 2017 6:21 pm

RE:Problems with my tetris game
-----------------------------------
No, they won't. cls is a draw command. It doesn't have any effect on the game itself at all. It just draws things. 

Everything 'in the game' happens on the grid array. Every single block in the game is represented there. When you rotate something, it gets rotated in the array. When you delete a row, it is deleted from the array. Not from the screen. 

The draw procedure draws everything. It looks at the array, and the score, etc and draws them to the screen. Anything you want drawn gets drawn here. We look at cell (1,1), if it's full, we draw it. If not, we don't. Then we look at cell (1, 2), then (1, 3), and so on. It looks at everything, and decides, based on what it sees, what to draw.

Things change pretty quickly in games. What we drew to the screen isn't accurate for very long, because as soon as we drew it, we started changing things. Maybe a row got deleted, maybe the user pressed a key, maybe the score went up. We already have a procedure that looks at EVERYTHING, and decides what to draw. So instead of writing another function to erase the parts we don't want, we just erase everything and draw it all again. Maybe something changed, maybe it didn't. We don't know, and we don't have to.

-----------------------------------
jason98wang
Wed Jan 18, 2017 1:12 am

RE:Problems with my tetris game
-----------------------------------
can you fix my program? 
i
