CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: aetios on November 16, 2014, 01:46:15 PM

Title: Tetris
Post by: aetios 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 :|
Title: Re: Tetris
Post by: pimathbrainiac 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.
Title: Re: Tetris
Post by: aetios 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.
Title: Re: Tetris
Post by: Dream of 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?
Title: Re: Tetris
Post by: aetios 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 -.-)
Title: Re: Tetris
Post by: Dream of 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.

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
Title: Re: Tetris
Post by: novenary on November 17, 2014, 05:47:39 PM
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
Title: Re: Tetris
Post by: Dream of Omnimaga 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
Title: Re: Tetris
Post by: pimathbrainiac on November 17, 2014, 06:11:22 PM

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.
Title: Re: Tetris
Post by: aetios 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.
Title: Re: Tetris
Post by: pimathbrainiac on November 17, 2014, 07:10:46 PM
okay. I'll debug it later, because I'm still at school.
Title: Re: Tetris
Post by: novenary on November 17, 2014, 07:18:39 PM
Apparently aeTIos just got my solution working so yay. :D

Edit : Well, almost. :P
Title: Re: Tetris
Post by: aetios 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.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 17, 2014, 09:43:25 PM
By the way, do you think animated backgrounds (like Tetris for the GBC) would be possible?
Title: Re: Tetris
Post by: novenary on November 17, 2014, 11:30:31 PM
Yup, definitely. It would just need the backgrounds to be done. :P
Title: Re: Tetris
Post by: Dream of Omnimaga on November 18, 2014, 03:15:17 AM
I guess backgrounds from Supersonic Ball or perhaps other ones I made could be modified then re-used. Also I tried this game when it was posted secretly and it's quite cool so far. :) How do you make blocks fall down instantly, though?
Title: Re: Tetris
Post by: aetios on November 18, 2014, 12:18:59 PM
Animated backgrounds are definitely possible.I have been thinking about a scoring mechanism, nad I came up with the following:
There's a base line score of current_level*2. If you fill multiple lines at once, you get a +1x multiplier on this base score per line. e.g. if you are level 9 and make a tetris, you get a whopping 18+36+54+72=180 points :0 On top of that if you keep cleaning lines in subsequent turns your base line score goes up by (current_level-1)/3+1 points per turn (current level / 3 rounded up). If you make a tetris, you get a permanent score multiplier bonus of +0.2. Clearing the screen gives you +0.1 score multiplier. Insta-dropping will award you 0.5x the distance dropped in score.

Thoughts? Suggestions?
Title: Re: Tetris
Post by: novenary on November 18, 2014, 01:21:04 PM
Quote from: DJ Omnimaga on November 18, 2014, 03:15:17 AM
I guess backgrounds from Supersonic Ball or perhaps other ones I made could be modified then re-used. Also I tried this game when it was posted secretly and it's quite cool so far. :) How do you make blocks fall down instantly, though?
You don't. It's currently unimplemented. :P
Quote from: aeTIos on November 18, 2014, 12:18:59 PM
Animated backgrounds are definitely possible.I have been thinking about a scoring mechanism, nad I came up with the following:
There's a base line score of current_level*2. If you fill multiple lines at once, you get a +1x multiplier on this base score per line. e.g. if you are level 9 and make a tetris, you get a whopping 18+36+54+72=180 points :0 On top of that if you keep cleaning lines in subsequent turns your base line score goes up by (current_level-1)/3+1 points per turn (current level / 3 rounded up). If you make a tetris, you get a permanent score multiplier bonus of +0.2. Clearing the screen gives you +0.1 score multiplier. Insta-dropping will award you 0.5x the distance dropped in score.

Thoughts? Suggestions?
Sounds good to me. :)
I'd make clearing the screen more rewarding though since it's way harder than doing a tetris lol.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 18, 2014, 05:08:10 PM
How does one clear the entire screen instantly, though? O.O


I like the ideas otherwise, though. Just make sure that above level 9 you don't get like 300000 pts for each Tetris or something like in the NES tool-assisted speed-run.
Title: Re: Tetris
Post by: novenary on November 18, 2014, 05:20:29 PM
Well, there's copying stuff to the screen and actually drawing. The latter requires a lot of calculations, especially with transparency where you need to test every pixel.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 18, 2014, 10:56:29 PM
Oh I meant clearing the entire screen as in clearing lines during gameplay. I was confused because you can't clear the entire screen instantly with just 1 vertical block. It takes like 4 or 5 :P
Title: Re: Tetris
Post by: Keoni29 on November 19, 2014, 12:20:35 AM
Does it have mode B? (Clearing a certain amt of lines with a screen filled with random blocks at the beginning)
Title: Re: Tetris
Post by: aetios on November 19, 2014, 06:57:48 AM
No, because there's no mode select screen yet :P I plan to add it, though. It's quite a classic. Anyways I made quite a bit of progress yesterday: I added a scoring system :D It's not quite finished yet (I still have to add certain situation checks) but it's already very playable.
Download beta 0.0.1 here: https://dl.dropboxusercontent.com/u/64788231/tetris001.tns The version numbers after this will be determined using a 1d4+2d10 dice roll :P
Title: Re: Tetris
Post by: Dream of Omnimaga on November 19, 2014, 05:33:42 PM
I tried last night copy and the score leaves traces behind digits when updated.
Title: Re: Tetris
Post by: aetios on November 19, 2014, 06:29:16 PM
Yeah, that's because the screen isn't wiped on update. It only re-draws the tilemap :)
Title: Re: Tetris
Post by: novenary on November 19, 2014, 06:42:26 PM
Quote from: aeTIos on November 19, 2014, 06:57:48 AM
The version numbers after this will be determined using a 1d4+2d10 dice roll :P
Haha yes do that. I'm sure you'll beat Firefox/Chrome version numbers really fast. :P
Title: Re: Tetris
Post by: Dream of Omnimaga on November 19, 2014, 11:24:08 PM
By the way, you should really implement Next block feature so we know what block is about to appear, like in other Tetris games :P
Title: Re: Tetris
Post by: novenary on November 19, 2014, 11:42:49 PM
I think it's already implemented but not sure. In the code I mean, no visual output yet.
Title: Re: Tetris
Post by: aetios on November 20, 2014, 11:29:45 PM
Quote from: Streetwalrus on November 19, 2014, 11:42:49 PM
I think it's already implemented but not sure. In the code I mean, no visual output yet.
This is not entirely true. Sure I can know what block is next up, but I will have to generate 2 bags at a time because eventually I want to give a next 5 blocks preview. I also want to add the ability to put a piece on hold, and I want to add a drop shadow (this will make insta-dropping a lot easier)
Title: Re: Tetris
Post by: novenary on November 21, 2014, 09:44:32 PM
Wow that sounds ambitious. At first we were trying to recreate the gameboy classic lol.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 22, 2014, 12:12:24 AM
Ooh 5 blocks preview and drop shadow would be nice. I think that's what ThePenguin77's Tetris did, right? Or maybe it was another Tetris game?

Being able to put a piece on hold should probably be a game mode, though, for people who want to go with a full challenge with the original rules.  But it's up to you I guess.
Title: Re: Tetris
Post by: aetios on November 22, 2014, 10:37:35 PM
Quote from: DJ Omnimaga on November 22, 2014, 12:12:24 AM
Ooh 5 blocks preview and drop shadow would be nice. I think that's what ThePenguin77's Tetris did, right? Or maybe it was another Tetris game?

Being able to put a piece on hold should probably be a game mode, though, for people who want to go with a full challenge with the original rules.  But it's up to you I guess.

Yep, and he on his part recreated Tetris Marathon which is still one of the best tetrises made so far IMO.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 23, 2014, 07:31:02 AM
Yeah I like that game mode. 

On a side note, in your game, I notice that the starting speed is very high compared to the NES version. Is this intentional?
Title: Re: Tetris
Post by: novenary on November 23, 2014, 12:24:53 PM
I made it that way because I wanted it to be fast for testing. :P The engine allows for adjustable speed thankfully so yeah. ;)
Title: Re: Tetris
Post by: Dream of Omnimaga on November 24, 2014, 03:14:03 PM
Ah ok good lol. Because I felt for novice players they will find this version much harder than other versions if the speed remains like this. :P That said, the Windows 3.1 Tetris was like this too, IIRC, in addition to lacking the ability to make blocks fall line by line (you could only make them fall instantly)
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on November 25, 2014, 09:35:00 AM
I don't know for features but I'd like to see three of them implemented :
- instant fall with a button (with UP)
- Holding a piece
- Having a cooldown before then piece blocks itself when it touches the other blocks. (In Tetris DS the cool down reset each team you rotate)

Yeah I came ffrom Tetris DS and it was my favorite port. I destroy its marathon in no time! :p
Title: Re: Tetris
Post by: novenary on November 26, 2014, 12:51:26 PM
The first two are planned, the last one is easy enough to do with three lines of code. :P
Title: Re: Tetris
Post by: aetios on November 26, 2014, 12:59:46 PM
actually I wanted to implement #3 too but I don't want to reset it. Instead I wanted to add a bit to the timer every time you rotate :)

Don't expect too much progress on this for the rest of the week. I have a test coming up and I have to study like mad because I wanna get a good score.
Title: Re: Tetris
Post by: Dream of Omnimaga on November 26, 2014, 11:52:24 PM
Good luck in your test aeTIos!
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on November 27, 2014, 07:01:55 AM
Have fun! And if you're bored in the test, heh, you have tour Tetris! ;)
Title: Re: Tetris
Post by: novenary on November 27, 2014, 08:38:20 AM
Good luck with your test but don't tire yourself out. :)
Title: Re: Tetris
Post by: aetios on November 27, 2014, 07:07:04 PM
Quote from: Eiyeron on November 27, 2014, 07:01:55 AM
Have fun! And if you're bored in the test, heh, you have your Tetris! ;)
Eh, I can't use my Nspire :P Thanks everyone :)
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on November 28, 2014, 07:18:43 AM
That's not a calculator, it's a game console
Title: Re: Tetris
Post by: novenary on November 28, 2014, 08:29:43 AM
Quote from: Eiyeron on November 28, 2014, 07:18:43 AM
That's not a calculator, it's a game console
I definitely agree.
Title: Re: Tetris
Post by: aetios on December 01, 2014, 04:31:00 PM
Bah. Not true, I use my CX for lab data analysis all the time :) It's a really good machine, you just have to use it for what it's intended for - which is data gathering and analysis. I might do a post about how to actually use the Nspire the way it's intended.
Anyways I have my test tonight. Thanks for all thesupport already, I hope it all goes well ^^'
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on December 01, 2014, 04:39:46 PM
Quote from: aeTIos on December 01, 2014, 04:31:00 PM
Bah. Not true, I use my CX for lab data analysis all the time :) It's a really good machine, you just have to use it for what it's intended for - which is data gathering and analysis. I might do a post about how to actually use the Nspire the way it's intended.
Anyways I have my test tonight. Thanks for all thesupport already, I hope it all goes well ^^'

How to use your nspire when not playing nDoom on it. :blah:
Title: Re: Tetris
Post by: aetios on December 06, 2014, 07:52:24 AM
Haha. Anyway let's get back on topic. I passed my test with an 80% score so that'll be all right. Been really busy with school and all that stuff lately, that's why I haven't made much progress on this :|
Title: Re: Tetris
Post by: novenary on December 06, 2014, 08:29:03 AM
/me pats aeTIos in the back

I hope you can do stuff this week.
Also you should change your avatar.
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on December 06, 2014, 08:49:39 AM
Agreed, when I'm not thinking about Rick, I think you're Rune 112. ><"

Nice grade you got there! Hope that will alleviate you from some stress!
Title: Re: Tetris
Post by: Dream of Omnimaga on December 06, 2014, 12:03:11 PM
Quote from: aeTIos on December 06, 2014, 07:52:24 AM
Haha. Anyway let's get back on topic. I passed my test with an 80% score so that'll be all right. Been really busy with school and all that stuff lately, that's why I haven't made much progress on this :|
I thought your test was finished a few days ago O.O

Good job though :)

Also what about a walrii-themed Tetris? :P
Title: Re: Tetris
Post by: novenary on December 06, 2014, 07:01:07 PM
Waltriis ? :P
Title: Re: Tetris
Post by: Dream of Omnimaga on December 07, 2014, 03:53:24 AM
I was more thinking of WalriiTris or something like that, or Tetris Walrii Edition :P
Title: Re: Tetris
Post by: novenary on December 07, 2014, 03:57:15 PM
Sounds fun anyway. :P Maybe have the pieces look like weird lobsters and when you destroy a row, have Walrii eat it as the animation. :P
Title: Re: Tetris
Post by: Dream of Omnimaga on December 07, 2014, 06:39:02 PM
Oh I like the latter idea. :D for the first good luck making such Tetris game look good, though :P
Title: Re: Tetris
Post by: novenary on December 09, 2014, 12:08:33 AM
Yeah lol it would probably look really weird. :P
Title: Re: Tetris
Post by: Dream of Omnimaga on December 09, 2014, 06:22:31 AM
I'M thinking that maybe it should still use blocks in such case, but on the blocks, there would be lobster claws or legs drawn on them.
Title: Re: Tetris
Post by: Duke "Tape" Eiyeron on December 09, 2014, 06:25:07 AM
You could do something like Puyo Puyo, making same color blocks merge!
Title: Re: Tetris
Post by: Dream of Omnimaga on December 31, 2014, 02:01:21 AM
Bug report:

The game doesn't run in Nspire_emu, no matter what version of Ndless you use. It will just say This document format is not supported.
Title: Re: Tetris
Post by: aetios on January 03, 2015, 12:42:43 PM
Quote from: DJ Omnimaga on December 31, 2014, 02:01:21 AM
Bug report:

The game doesn't run in Nspire_emu, no matter what version of Ndless you use. It will just say This document format is not supported.
Huh, that's weird. I never tested on emulators, though, so I can't really give support x.x I remember seeing pimath play Testris (pun intended) on an emulator, though, somewhere in november on HCWP. I should get things going but I'm kinda stuck on where to continue work on this :\
Title: Re: Tetris
Post by: Dream of Omnimaga on January 04, 2015, 05:08:28 AM
Well the other night, I was trying both  nKaruga and Tetris with both the Ndless build I had and the latest. nKaruga would run perfectly in both, while Tetris would say the format is not supported. Are you sure you didn't compile it only for one specific version of Ndless? I know the old version I had on emulator was not the same as on my calc (my calc is still a few versions behind, yet it ran both games fine). Anyway I hope you continue working on this. It would be nice to see a full-fledged  C Tetris clone for the Nspire that isn't an emulator game.
Title: Re: Tetris
Post by: aetios on January 05, 2015, 11:35:10 AM
I did some work on this last weekend, and I added support for piece previewing. Haven't tested the latest build yet, though.
Title: Re: Tetris
Post by: Dream of Omnimaga on January 05, 2015, 05:02:41 PM
Cool to hear. :D you shoukd make a screenshot when you have a chance, since I can't run the game in nspire_emu. (It only works on the real calc)
Title: Re: Tetris
Post by: Keoni29 on January 05, 2015, 09:42:35 PM
Yeah I'd like to see a screenshot of the latest version as well. When was the last time we had a preview of this game? A year ago or so? :trollface:
Title: Re: Tetris
Post by: Dream of Omnimaga on January 06, 2015, 12:12:35 AM
I think it was in May, but you posted some versions after CodeWalrus got a forum.


Also I just realized I forgot to include the game in the CW Youtube video D: (although maybe it would have looked out of place with the animated screenshots, since Tetris was filmed with a camera.)
Title: Re: Tetris
Post by: novenary on January 12, 2015, 10:04:28 AM
I'm going to take a look at this this weekend. Is the source on github up to date ?
Title: Re: Tetris
Post by: aetios on January 19, 2015, 11:01:39 AM
The github sauce is up to date. This game is progressing slowly but I'm still adding features :)
Title: Re: Tetris
Post by: Dream of Omnimaga on January 19, 2015, 03:04:11 PM
Glad you are still working of this. I was sad to see Illusiat and Pokespire die simultaneously D:
Title: Re: Tetris
Post by: aetios on January 19, 2015, 04:11:37 PM
Quote from: DJ Omnimaga on January 19, 2015, 03:04:11 PM
Glad you are still working of this. I was sad to see Illusiat and Pokespire die simultaneously D:
We might still do something with illusiat, but probably not on calc.
Title: Re: Tetris
Post by: Dream of Omnimaga on January 19, 2015, 05:09:02 PM
Oh i meant that this particular calc project is still one. I would like to see a non-c remake of Illusiat 11 for the PC in SNES style