* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Tetris  (Read 8165 times)

0 Members and 1 Guest are viewing this topic.

Offline aeTIos

  • Dabbler in C
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Tetris
« on: November 16, 2014, 01:46:15 pm »
I've been working on our Tetris clone a bit today. Struggling with C, but trying to learn :|


ceci n'est pas une signature

Offline pimathbrainiac

  • Full User
  • Original 5
  • Join Date: Nov 2014
  • Location:
  • Posts: 420
  • Post Rating Ratio: +2/-1
  • Formerly Banned CW Co-Founder Turned News Editor
    • pimathbrainiac
  • Gender: Other
Re: Tetris
« Reply #1 on: November 16, 2014, 01:47:26 pm »
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!

Offline aeTIos

  • Dabbler in C
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Re: Tetris
« Reply #2 on: November 16, 2014, 01:54:43 pm »
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

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18622
  • Post Rating Ratio: +95/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: Tetris
« Reply #3 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?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline aeTIos

  • Dabbler in C
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Re: Tetris
« Reply #4 on: November 17, 2014, 01:57:23 pm »
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

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18622
  • Post Rating Ratio: +95/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: Tetris
« Reply #5 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.

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-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Streetwalrus

  • Professional slacker
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2903
  • Post Rating Ratio: +20/-0
  • ƎW∀⅁ ƎH⊥
  • Gender: Male
Re: Tetris
« Reply #6 on: November 17, 2014, 05:47:39 pm »
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.

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.

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
« Last Edit: November 17, 2014, 05:50:26 pm by Streetwalrus »
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen



Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18622
  • Post Rating Ratio: +95/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: Tetris
« Reply #7 on: November 17, 2014, 05:49:46 pm »
Ah ok lol I thought you just used shapes like in every HP Prime Tetris clone :P
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline pimathbrainiac

  • Full User
  • Original 5
  • Join Date: Nov 2014
  • Location:
  • Posts: 420
  • Post Rating Ratio: +2/-1
  • Formerly Banned CW Co-Founder Turned News Editor
    • pimathbrainiac
  • Gender: Other
Re: Tetris
« Reply #8 on: November 17, 2014, 06:11:22 pm »
Code: [Select]
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!

Offline aeTIos

  • Dabbler in C
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Re: Tetris
« Reply #9 on: November 17, 2014, 06:21:47 pm »
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

Offline pimathbrainiac

  • Full User
  • Original 5
  • Join Date: Nov 2014
  • Location:
  • Posts: 420
  • Post Rating Ratio: +2/-1
  • Formerly Banned CW Co-Founder Turned News Editor
    • pimathbrainiac
  • Gender: Other
Re: Tetris
« Reply #10 on: November 17, 2014, 07:10:46 pm »
okay. I'll debug it later, because I'm still at school.
Well, I'm bach here too!

Offline Streetwalrus

  • Professional slacker
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2903
  • Post Rating Ratio: +20/-0
  • ƎW∀⅁ ƎH⊥
  • Gender: Male
Re: Tetris
« Reply #11 on: November 17, 2014, 07:18:39 pm »
Apparently aeTIos just got my solution working so yay. :D

Edit : Well, almost. :P
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen



Offline aeTIos

  • Dabbler in C
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Ede, NL
  • Posts: 1049
  • Post Rating Ratio: +12/-0
  • hi
    • r_vdijk
    • /u/aetios
    • aetios
  • Gender: Male
Re: Tetris
« Reply #12 on: November 17, 2014, 08:57:57 pm »
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

Offline xlibman

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Original 5
  • CodeWalrus Supporter
  • *
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 18622
  • Post Rating Ratio: +95/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • DJ Omnimaga music store
  • Gender: Male
Re: Tetris
« Reply #13 on: November 17, 2014, 09:43:25 pm »
By the way, do you think animated backgrounds (like Tetris for the GBC) would be possible?
  • Calculators owned: TI-57, 73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX (semi-broken), HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Streetwalrus

  • Professional slacker
  • Super User
  • Original 5
  • Join Date: Nov 2014
  • Location: Israel
  • Posts: 2903
  • Post Rating Ratio: +20/-0
  • ƎW∀⅁ ƎH⊥
  • Gender: Male
Re: Tetris
« Reply #14 on: November 17, 2014, 11:30:31 pm »
Yup, definitely. It would just need the backgrounds to be done. :P
  • Calculators owned: TI-80, HP 40G, TI-84 Plus rev G (yay 128k RAM), TI-83 Plus Silver Edition (broken LCD), TI-82 Stats.fr (black), TI-Nspire CX rev C (yay Nlaunchy), TI-83+ SE ViewScreen



 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games