Join us on Discord!
You can help CodeWalrus stay online by donating here.

Tetris

Started by aetios, November 16, 2014, 01:46:15 PM

Previous topic - Next topic

0 Members and 16 Guests are viewing this topic.

aetios

I've been working on our Tetris clone a bit today. Struggling with C, but trying to learn :|
ceci n'est pas une signature

pimathbrainiac

GitHub or it didn't happen. *runs*

If you need help, contact me. Also read the n2DLib documentation. It helps. A lot.
Well, I'm bach here too!

aetios

There's a GitHub: https://github.com/Streetwalrus/tetris It's not up-to-date with my source, though, because I can't push yet (I'm not a member of the github so I can only do pull requests (I think??))
Also, thanks for the advice :) I'll poke you when I'm stuck.
ceci n'est pas une signature

Dream of Omnimaga

By the way, what are your plans for the graphics? Do you plan to stick with single color blocks or will you use textured blocks like in original Tetris games?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

aetios

I dunno, maybe we'll ship it with multiple graphics packs ^^
We made a very interesting design choice: The game is going to be played sidewards, so you have more height to use :D The controls are going to be mapped to the letter pad.
Also, I'm struggling with this code. It freezes and I have no idea why...
Code (nom, spaghetti codegnese) Select

int bag_piece()
{
int i;
if ( in_bag > 0 )
{
in_bag--;
i = bag[in_bag];
bag[in_bag] = -1;
return i;
}
while( in_bag < 7 )
{
i = rand()%7;
int z = 0;
int j;
for( j = 0; j < 7; j++)
{
if( i == bag[j] ) z++;
}
if( z == 0 )
{
bag[in_bag] = i;
in_bag++;
}

}
bag[--in_bag] = -1;
return i;
}

bag[] is the numbers 0-6 in a random order.
If in_bag > 0 it should return the piece bag[in_bag] and set bag[in_bag] to -1.
if in_bag = 0 then it should fill the bag with 0-6 in a random order and return bag[6] and set bag[6] to -1.

Any ideas? (except me learning to code better -.-)
ceci n'est pas une signature

Dream of Omnimaga

Aw, I tend to not like sideways controls because when you hold the calc it tends to tilt by itself on one side, especially bulky models like the ClickPad Nspire. D: Your choice, though.

As for graphics I was wondering since IMHO it would make no sense to release a Tetris game with Atari 2600 graphics when many other alternatives with actual sprites (like Nick's Tetris and the emulator ones) are available. Not to mention it would defeat the point of using Ndless :P
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

novenary

#6
Quote from: DJ Omnimaga on November 17, 2014, 02:27:25 AM
By the way, what are your plans for the graphics? Do you plan to stick with single color blocks or will you use textured blocks like in original Tetris games?
The game uses sprites, it's really easy to swap them out. :P

As for the algorithm, do it this way :
-put consecutive 1-7 numbers in a table and set a count (n) to 7
-pick a random 0-6 number (m)
-grab the mth non-0 number from the table and put it minus 1 in your bag
-0 that number and decrement n
-go back to step 2 until n is 0

That should do the trick.

Quote from: DJ Omnimaga on November 17, 2014, 05:45:52 PM
Aw, I tend to not like sideways controls because when you hold the calc it tends to tilt by itself on one side, especially bulky models like the ClickPad Nspire. D: Your choice, though.
We plan to make it optional.

Quote from: DJ Omnimaga on November 17, 2014, 05:45:52 PM
As for graphics I was wondering since IMHO it would make no sense to release a Tetris game with Atari 2600 graphics when many other alternatives with actual sprites (like Nick's Tetris and the emulator ones) are available. Not to mention it would defeat the point of using Ndless :P
Welp, this is our first project to mess around with Ndless, plus we had a pretty epic idea that required the speed in order not to make the game lag like mad when we generated pieces. >:D

Dream of Omnimaga

Ah ok lol I thought you just used shapes like in every HP Prime Tetris clone :P
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

pimathbrainiac


int bag_piece()
{
int i;
if (!(in_bag > 0))
{
while( in_bag < 7 )
{
i = rand()%7;
int z = 0;
int j;
for( j = 0; j < 7; j++)
{
if(i == bag[j])
{
z = 1;
in_bag--;
break;
}
}
bag[in_bag - 1] = i;
in_bag++;
}
}
in_bag--;
i = bag[in_bag - 1];
return i;
}


This should do the trick. I have to get lunch, so I'll explain it later.
Well, I'm bach here too!

aetios

pimath: erm, the code does work, it just doesn't do what it's expected to do. I got two line pieces in a row at like the third piece already. That shouldn't happen.
Street: that sounds like a really good idea, I'll try to implement that.
ceci n'est pas une signature

pimathbrainiac

okay. I'll debug it later, because I'm still at school.
Well, I'm bach here too!

novenary

Apparently aeTIos just got my solution working so yay. :D

Edit : Well, almost. :P

aetios

Got Streetwalrus' solution working, but I came up with an algorithm of my own that I'll also try to implement. For now, I pushed my implementation of streetwalrus' solution to GitHub.
ceci n'est pas une signature

Dream of Omnimaga

By the way, do you think animated backgrounds (like Tetris for the GBC) would be possible?
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

novenary

Yup, definitely. It would just need the backgrounds to be done. :P

Powered by EzPortal