Download: http://www.cemetech.net/programs/index.php?mode=file&id=969





Yes, I know, we have the assembly Tetris, and it's awesome, it really is. Kerm mentioned that a BASIC version wasn't going to work due to Pt-On being dumb with point #2, but it works fine with #1, so I've gone with that.



I've never made or even attempted to make a tetris game before, so this is just as much a test to push myself in new directions with programming as it is just to do this. It runs relatively fast, though I have plans on shoring up the code later. This was just a test run to see if it would work. And I have it set to stop at a certain point so it doesn't drop any further.

Code:


Code:
:DCS

ClrDraw
2->W:5->D:5->C:1->V:V->U:0->T
randInt(10,16->E
1+(E/|E2->E
0->Xmin:0->Ymin
264->Xmax:164->Ymax
Line(114,47,114,117,2,12
Line(148,47,148,117,2,12
Line(116,45,147,45,2,12
{22,10->dim([A]
Fill(0,[A]

randInt(1,4->V

While W=2



1->W

While W=1
If |E2fPart(E)=10:Then
If V=1 or V=2:Then
{3,0,6,0,0,3,3,3->L1:2->A:1->B:End
If V=3 or V=4:Then
{0,0,0,3,3,3,3,6->L1:1->A:2->B:End
End
If |E2fPart(E)=11:Then
If V=1 or V=3:Then
{0,0,3,0,3,3,6,3->L1:2->A:1->B:End
If V=2 or V=4:Then
{3,0,3,3,0,0,0,6->L1:1->A:2->B:End
End
If |E2fPart(E)=12:Then
If V=1:Then
{3,0,0,3,3,3,6,3->L1:2->A:1->B:End
If V=2:Then
{0,0,0,3,0,6,3,3->L1:1->A:2->B:End
If V=3:Then
{0,0,3,0,6,0,3,3->L1:2->A:1->B:End
If V=4:Then
{3,0,3,3,3,6,0,3->L1:1->A:2->B:End
End
If |E2fPart(E)=13:Then
If V>0 and V<5:Then
{0,0,3,0,3,3,0,3->L1:1->A:1->B:End
End
If |E2fPart(E)=14:Then
If V=1 or V=3:Then
{0,0,3,0,6,0,9,0->L1:3->A:0->B:End
If V=2 or V=4:Then
{0,0,0,3,0,6,0,9->L1:0->A:3->B:End
End
If |E2fPart(E)=15:Then
If V=1:Then
{0,0,0,3,3,3,6,3->L1:2->A:1->B:End
If V=2:Then
{0,0,3,0,0,3,0,6->L1:1->A:2->B:End
If V=3:Then
{0,0,3,0,6,0,6,3->L1:2->A:1->B:End
If V=4:Then
{3,0,3,3,3,6,0,6->L1:1->A:2->B:End
End
If |E2fPart(E)=16:Then
If V=1:Then
{0,3,3,3,6,3,6,0->L1:2->A:1->B:End
If V=2:Then
{0,0,0,3,0,6,3,6->L1:1->A:2->B:End
If V=3:Then
{0,0,3,0,6,0,0,3->L1:2->A:1->B:End
If V=4:Then
{0,0,3,0,3,3,3,6->L1:1->A:2->B:End
End
If T=0:Then:1->T:L1->L2:End
3->W
End
While W=3
Pt-Off((115+C*3)+L2(1),(118-D*3)+L2(2),1
Pt-Off((115+C*3)+L2(3),(118-D*3)+L2(4),1
Pt-Off((115+C*3)+L2(5),(118-D*3)+L2(6),1
Pt-Off((115+C*3)+L2(7),(118-D*3)+L2(8),1

D+1(D<19->D
4->W
End
While W=4

Pt-On((115+C*3)+L1(1),(118-D*3)+L1(2),1,|E2fPart(E
Pt-On((115+C*3)+L1(3),(118-D*3)+L1(4),1,|E2fPart(E
Pt-On((115+C*3)+L1(5),(118-D*3)+L1(6),1,|E2fPart(E
Pt-On((115+C*3)+L1(7),(118-D*3)+L1(8),1,|E2fPart(E

L1->L2
2->W
End

End:"W=2


I am very exhausted, so the code isn't pretty, not by a long shot. I'll mess with it more when I'm feeling more up to it.

I would appreciate any feed back as it sits right now. I understand that a BASIC version won't be popular, but as I said, wanting to branch and expand.

thanks in advance!
Heck, even if you end up being less than pleased with the final product, Tetris has sufficient algorithmic rigor and corner cases to be challenging and therefore worthwhile to write. I hope you at worst learn something from it, and at best succeed where I failed and create a fun, playable BASIC Tetris game. Smile It looks like you have a respectable start there, and I'm glad you're exploring a matrix-based game for your first (?) time.
I think I actually tried to do some matrix based stuff when I was working on Age of Darkness 3, but I don't remember it working out overly well, mainly for the size I think. And it was slow and hard to work with.

In regards to this, going to try to clean up all those If thens, I should be able to reduce the #->A:#->B into their own based on patterns, and save a bunch of space and get rid of all those Thens and Ends and just have the lists. Might even speed things along. And I should probably just drop the while loop surrounding the deletion part, I don't know why I added that. Was way too tired to be working on code when I wrote it lol

Edit:

Cleaned up the code a bit:


Code:
:DCS

ClrDraw
2->W:5->D:5->C:1->V:V->U:0->T
randInt(10,16->E
1+(E/|E2->E
0->Xmin:0->Ymin
264->Xmax:164->Ymax
Line(114,47,114,117,2,12
Line(148,47,148,117,2,12
Line(116,45,147,45,2,12
{22,10->dim([A]
Fill(0,[A]

randInt(1,4->V

While W=2

If |E2fPart(E)=10:Then
If V=1 or V=2
{3,0,6,0,0,3,3,3->L1
If V=3 or V=4
{0,0,0,3,3,3,3,6->L1
End
If |E2fPart(E)=11:Then
If V=1 or V=3
{0,0,3,0,3,3,6,3->L1
If V=2 or V=4
{3,0,3,3,0,0,0,6->L1
End
If |E2fPart(E)=12:Then
If V=1
{3,0,0,3,3,3,6,3->L1
If V=2
{0,0,0,3,0,6,3,3->L1
If V=3
{0,0,3,0,6,0,3,3->L1
If V=4
{3,0,3,3,3,6,0,3->L1
End
If |E2fPart(E)=13:Then
If V>0 and V<5
{0,0,3,0,3,3,0,3->L1
End
If |E2fPart(E)=14:Then
If V=1 or V=3
{0,0,3,0,6,0,9,0->L1
If V=2 or V=4
{0,0,0,3,0,6,0,9->L1
End
If |E2fPart(E)=15:Then
If V=1
{0,0,0,3,3,3,6,3->L1
If V=2
{0,0,3,0,0,3,0,6->L1
If V=3
{0,0,3,0,6,0,6,3->L1
If V=4
{0,3,3,3,3,6,0,6->L1
End
If |E2fPart(E)=16:Then
If V=1
{0,3,3,3,6,3,6,0->L1
If V=2
{0,0,0,3,0,6,3,6->L1
If V=3
{0,0,3,0,6,0,0,3->L1
If V=4
{0,0,3,0,3,3,3,6->L1
End
|E2fPart(E->Z
If max(Z={10,11,12,15,16:Then
If V=1 or V=3:Then:2->A:1->B:End
If V=2 or V=4:Then:1->A:2->B:End:End
If Z=13:Then:1->A:1->B:End
If Z=14:Then
If V=1 or V=3:Then:3->A:0->B:End
If V=2 or V=4:Then:0->A:3->B:End
End
If T=0:Then:1->T:L1->L2:End
Pt-Off((115+C*3)+L2(1),(118-D*3)+L2(2),1
Pt-Off((115+C*3)+L2(3),(118-D*3)+L2(4),1
Pt-Off((115+C*3)+L2(5),(118-D*3)+L2(6),1
Pt-Off((115+C*3)+L2(7),(118-D*3)+L2(8),1

D+1(D<19->D

Pt-On((115+C*3)+L1(1),(118-D*3)+L1(2),1,|E2fPart(E
Pt-On((115+C*3)+L1(3),(118-D*3)+L1(4),1,|E2fPart(E
Pt-On((115+C*3)+L1(5),(118-D*3)+L1(6),1,|E2fPart(E
Pt-On((115+C*3)+L1(7),(118-D*3)+L1(8),1,|E2fPart(E

L1->L2

End:"W=2


Seems to run a little faster this way. Also had to fix one of the lists, as one of the blocks were going to the wrong spot :p

I'm not overly sure there is a way to make it work smoother yet. I think for the moment, though, I'll work on getting the pieces to rotate and maybe even move them from side to side. I still haven't figured out how to set up adding the 1's appropriately to the matrix. I think I can use the current list L1 which stores the block data for the shapes, I just haven't devoted a ton of time to that thought yet.
Wow looks awesome! I wouldnt have thought that this is possible in BASIC, but you've certainly shown that it is!
Thanks! Very Happy So far, all the pieces seem to work just fine, but I'm having some issues with alignment, so that's what I'm working on here after while. I did make it so it will move left and right on the screen as it drops Very Happy
TIFreak8x, on IRC you requested some details on Tetric B, specifically how it stores pieces. The already-placed pieces are stored in a 10x20-item matrix, while the falling pieces are temporarily stored in a second matrix. While a piece is falling, the contents of that matrix are used for collision detection and for checking whether side-to-side movement and rotation results in valid piece placement. Hope this helps!
Hm, I'd probably have to see code for that to make proper sense, since I'm not overly experienced with matrices. It's alright though, since I'm using lists for pixel placement and the shapes of the pieces.

Note to future self:

Move clearing routine to below displaying routine.

Edit:



Yes, the counter is set kind of high, that will need tweaking at a later point, was just trying to get something better than a rand(50 and such. Also moves very fluidly on calc going back and forth and drops at the same time, so you don't get to hang in the air.

Edit 2:



Rotation of the pieces seems to work fairly well now.

Edit 3:

I managed to make it so that it doesn't rotate into right side border. Left side is kind of irrelevant.



What do you think? Too colorful?

On a side note, Yesterday's "It doesn't rotate into the right side border" bit was for pieces that was not the straight piece. I finally managed to make it not do that. Program currently sits at 1870 bytes.

Next up, making the piece stop moving, store that to the proper place in the matrix and generate a new piece. Could be fun!

Edit:

I like the second one much better--it looks less busy and it's more clear that it's tetris.
Thanks, that was the general consensus on IRC as well, and I have to agree that it does indeed look much clearer than the first.


Well, I've gotten the crashing to stop, the pieces hit the bottom and then a new piece shows up. Now I just need to work on making it not hit the pieces below it.
I know this is in Ti-Basic (CBasic?) and I have heard the reputed slowness.
This looks nice! Making a tetris game is always fun, but I do have one question.
Is the "board"/bounds going to stay the same? Meaning that small?
Otherwise great job! It is rare to see a tetris game implemented in basic and I give you my congrats to trying to do so.
For the moment, yes. The reason being as standard rules apply, Tetris is done in a 10x20 matrix (10x21 in this case, because otherwise it wants to error out)

Can almost think of this as Tiny Tetris Smile It was made on the 89 a long time ago, not sure if it ever hit the 83+ line or not..

Edit:

Alright, I've managed to shore up the code some, sitting at 2250 bytes. It now has pieces drop and hit the bottom, and even generate new pieces properly, but it still doesn't stop when it sees that there is a piece below it. Not really sure yet what to do to make THAT work yet. Going to crack down on it for a couple days, and if I can't come up with something, I might drop the code down on here and see if someone might be willing to give me a hand. :<
Got a bit more working this evening:



And right after I stopped that screenshot, I decided to see how it handled rotating the piece and seeing if that stacked properly:



So, what do you guys think so far? Smile

I'm going to try throwing it at my calc and 'play' as it stands right now. I know I still have to do the line fill checking, but that can wait until I'm sure every piece fits in properly and all the checking is done correctly.
http://tifreakware.net/tifreak8x/btetris/BTETRIS.8xp

It now has full collision detection and rotation.

left/right arrows to move, 2nd/alpha to flip.

I don't have the down arrow implemented yet, in this build. Need to test what little code I added to make that work.

Updated:

Down arrow now drops pieces 'faster'.

MODE now exits the program a little more cleanly.

Pieces fall the rest of the way down, need to move up the border by 1 or 2 pixels.
Just a little bit of an update. Worked out some line clearing detection last night, thanks to the tip by merthsoft on how to accomplish it Smile

I haven't figured out how to easily 0 out the line, I think I'm stuck using a For( loop to 0 out each block in a row.

I'm also not 100% sure yet on how to drop the lines above the cleared. In theory, it shouldn't be too hard, I suppose, but it is going to be a tad slow.

Also, there was talk on omnimaga about possibly using asm help, and I've given it some thought. I don't think I want this to rely on any asm, I think it will be better right now as pure BASIC. Once I get everything working, then maybe I can collaborate with someone to help optimize things and speed up the game Smile

Also, I'm going to remove my attempt at starting slow and speeding things up as you level. It's a BASIC game, and it's already kind of slow, so no need to help it be a slow game, so I'll probably be removing that portion of the code.


Woo! It looks like it's a step in the right direction Smile Just have to move the starting point over 1 block worth to fix that. And now to start work on making above pieces fall down.
Superb work, tifreak8x! I'm especially impressed that you continue to maintain quite a good speed here, despite the complexity of the code that you're adding to BTetris.
Thanks Kerm, means a lot Smile

I removed the counter bit, and it's just going to run at full speed from now on, I think. Make things a little better so people don't complain (I hope)

Still need to finish up the dropping lines after lines are cleared, and revamp the piece rotation and going right and left.
Looks nice! Great work, can't wait to try it out, and learn a few things from the code if you don't mind.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page 1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Page 1 of 5
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement