#### Archived

This topic is now archived and is closed to further replies.

# 05.05 - (A) Home Stretch Assistance

## Recommended Posts

I''ve created this post in order to try and guage people''s progress for Blocks ''n Lines. If you''re working on completing the game project, but have some questions, here''s the place to post them. I''ll keep a close eye on this particular topic and try and help everyone out as quickly as possible. You''ll know when you''ve completed your project when it somewhat resembles a simple Tetris clone. Game pieces fall, one after the other, until a new piece cannot lower into the play area any longer. Completed lines are removed from the play area, and some score is assigned. At your discretion, you may choose to gradually increase the piece''s falling speed as their score increases -- it''s up to you. Show the player''s score somewhere on the display using simple GDI calls (as was used in the original BASECODE). When you can play a complete game from beginning to end and have a final score, you''re done with this part of the project, and can sign-in at the next topic (05.05 (B)). See you there!

##### Share on other sites

1. How can I play a track ? ( .mp3 or .waw ) in the game?
2. I made a function that deletes completed rows but I am not very happy with it. 3 for''s and not any briliant ideea.
But it does it''s work . So please give me if you can somme advices .... on that piece og program
( should I post my function ? )
3. How can I implement the mouse functions ( I am tring to make a Menu more not so KISS )

##### Share on other sites
MAD_Mask: The MMIO library (WINMM.LIB) is what we''ve been using for loading WAV files, and DirectSound to play them. For MP3 music, you''ll have to turn to DirectShow, as it can make use of codecs such as MPEG-3. For WAV files, it is also possible to stream them with DirectSound, but that''s something to be left for a later article. Just be patient; we''ll be exploring in-game music inevitibly.

For a line completion algorithm, I''ll let you in on what I originally used (generally speaking): I had a separate, temporary play area array that I used to copy the ''levels'' of the play area line-by-line from bottom to top (unless a line was completed, in which case it was tallied and discarded). When my algorithm was complete, the temporary play area array contained the new representation of the play area. Then, this can be swapped (using pointers) or copied back to the original play area data structure, and you''re all set.

As for using the mouse, that involves setting up the mouse via DirectInput and keeping track of its position. I''m sure will be looking at this in an upcoming article as well, but there''s nothing stopping you from reading up on it in the SDK documentation.

Teej

##### Share on other sites

I have a problem : I tried to change the path for the soud file to open. It compiles OK but it gives me an "DS init error -6."
I should mention that in basecode1 I made 3 DS objects and
But in basecode3b I just replaced "Sample.wav" with "Tauru06.wav"
( and I aded that file to the project ... )
So whay it works in basecode1 but not in basecode3?

Teej great job ...btw .

##### Share on other sites

I have another problem now ( + the last post ( see above ) )
How can make a version of the game that I can move to other compiuters?

##### Share on other sites
If you look in the InitTerm.cpp file, error -6 is after loading the file, so the filename is not the problem, maybe you are not using the right codec, I can't really help though as I don't know DirectSound (yet).

With your second problem all you have to do is compile the release version (build->set active configuration - it makes a smaller and faster file) copy the exe file from the release folder, and dump it in a folder, then copy all the bitmaps and wavs and whatever else you have and dump them in the same folder as well.
Remember - you need DirectX 7 on the PC you are testing it on.

Edited by - TheTramp on July 29, 2001 4:58:18 PM

##### Share on other sites
TheTramp : thanks for the advice on the compile issue.
Everybody:
I figured out that the problem is not from loading the file, but
I even "copy - paste" the DS_Init function from basecode1 (where it worked just fine with other wav files ) but in "MyTitres" (that''s my version of tetris ) it won''t work .
And I''d realy like to include somme nice sounds in the game ..so pls "F1" me.

##### Share on other sites
Optimization

My question today stems from an answer that I received recently about arrays that turned out to concern performance issues. With this in mind, I started looking at the various basecodes. I realized that ClearBackground() clears our background every frame (no duh). Currently, I have a new Clear() function that clears the whole screen to my background image (that already has the black backgrounds where I need them such as my scoreboard, next piece and game area) and did away with ClearBackground() in these sections of code. I haven''t seen any performance change, but I''ve begun to wonder - is it faster to clear the whole background, or just certain RECTS?

videns

##### Share on other sites
have you tried using Tauru06.wav in basecode1? I think the problem might be that it is not a PCM wav file, open it in Sound Recorder and do save as then choose PCM wav file.

##### Share on other sites
Yes I tried to put Tauru06.wav in basecode1 and it worked.And I
tried other wav files to in basecode1 and they worked but not in
basecode3c.Uff I tried to look in SDK docs but I didn''t understend very much.... even the samples files are sooooo big ..
..

##### Share on other sites

Best thing to do would be to try to figure out what the CreateSoundBuffer function returns when you try it. That would help us greatly in finding the problem.

Piotyr
Software Engineer by day, Game developer by night

The early bird may get the worm, but the second mouse gets the cheese.

##### Share on other sites
Ok, I am learning more from SDk hellp and I am hoping that I''ll be ok .Thanks for tring hellping me. I''ll try and tell you more about my problem...
Btw, what PCM wav file means? I know what a wav file is but ,
for what stands PCM?
And what about "Sound Recorder" where and what is that?
bye now

##### Share on other sites
Here is the defintion of PCM according to atomica.com.

(Pulse Code Modulation) A technique for converting analog signals into digital form that is widely used by the telephone companies in their T1 circuits. Every minute of the day, millions of telephone conversations, as well as data transmissions via modem, are converted into digital via PCM for transport over high-speed intercity trunks. In North America and Japan, PCM samples the analog waves 8,000 times per second and converts each sample into an 8-bit number, resulting in a 64 Kbps data stream (a single DS0 channel). The sampling rate is twice the 4 kHz bandwidth required for a toll-quality conversation.

Hope this helps

- Clash
- www.zeroinfinity.net
- A New World, Built By New Minds

##### Share on other sites

Yes , I made it. My game has sounds... and realy nice ones from
Shogun and AOE2.... it is cool.
I hope that this interactive tutorialis not over because I am filing that I have so much to learn and this forum ( read Teej and others )is very good in teaching peoples like me.

Oh , my problem was that there was a missing line in my DS_Init.

##### Share on other sites

Yes , I made it. My game has sounds... and realy nice ones from
Shogun and AOE2.... it is cool.
I hope that this interactive tutorialis are not over because I am filing that I have so much to learn and this forum ( read Teej and others )is( are) very good in teaching peoples like me.

Oh , my problem was that there was a missing line in my DS_Init.

##### Share on other sites
I'm having a little trouble with the line checking thing function something.
It doesnt work
Any knows whats wrong with it, I cant figure it out.

  void CheckingLine(){ int CheckingLine, x, y, fullX; for(y = 0; y < PLAYAREA_HEIGHT; y++) { for(x = 0; x < PLAYAREA_WIDTH; x++) { if(G.PlayArea[x][y] != 0) CheckingLine += 1; if(CheckingLine <= PLAYAREA_WIDTH) { fullX = x; continue; } } } if(CheckingLine <= PLAYAREA_WIDTH) { // Time to remove the line... for(y = 0; y < PLAYAREA_WIDTH; y++) { G.PlayArea[fullX][y] = 0; } // ...and to move the rest down for(y = 0; y < PLAYAREA_WIDTH; y++) { for (x = fullX - 1; y < PLAYAREA_WIDTH; x--) // Checking from top to bottom // and no need to check below the line { if (G.PlayArea[x][y] != 0) { G.PlayArea[x + 1][y] = G.PlayArea[x][y]; G.PlayArea[x][y] = 0; } } } } return;}

I have a new problem now, cause when I try to run the game and press 1 to start, my game quits!

Edited by - Unini on August 6, 2001 5:28:56 PM

##### Share on other sites
Unini, i''m having a bit of trouble with your for loops first off.

for(y = 0; y > PLAYAREA_WIDTH; y++)

So, y starts at 0, and continues while y > PLAYAREA_WIDTH...

well, since 0 is probably not higher, you''re never even going to get into your for loop. You need to change the middle parameter of your for loops to be the conditional which must be TRUE, so it should probably be y < PLAYAREA_WIDTH.

That''s just for starters, fix that and then see if you can''t figure out the rest.

##### Share on other sites
I updated my the code above to my new (yet unworking) code

But I found the solution (I think) as soon as I posted this, but havnt had the time to reply.
if(G.PlayArea[x][y] == 1) ...
should be
if(G.PlayArea[x][y] != 0) ...
cause there can also be 2, 3, 4 etc. and I forgot about that

And another mistake I made is that in my loops I had X as PLAYAREA_HEIGHT and that should we PLAYAREA_WIDE.

Edited by - Unini on August 6, 2001 5:23:59 PM

##### Share on other sites
Unini : Sorry if I can't give you complete help at this moment -- I'm about to leave for the day, but here goes (from what I can see glancing at the code):

1. CheckingLine needs to be initialized to 0. Since it's a local (stack) variable, only God knows what the value actually is...

2. CheckingLine, it would seem, will end up being == PLAYAREA_WIDTH, and that's how you'll know when you have a complete line

3. I don't quite see what you're doing with fullX. It seems that you're confusing x and y in your code -- you'd want to remove the rows where CheckingLine == PLAYAREA_WIDTH, and not remove columns...

4. Your function is structured in such a way that only one line can be processed. In reality, there may be multiple completed lines in the play area, so you should remove lines AS you scan the array

I can see what you were trying to do, and part of the confusion you may be facing has to do with ARRAY[x][y] versus ARRAY[y][x]. If you plug in the values like so [y][x], then you can think of x and y in the correct way (i.e. x goes across and y goes down). Here's my quick shot at an algorithm along your lines:

• For each row in the play area, starting from the top
• look from left to right, counting the number of blocks in the row

• if the number of blocks in the current row is equal to the total number of 'spaces' in a row of the play area
• copy the contents of the row above the current row INTO the current row

• continue copying row n - 1 into row n until you're at the top of the play area (i.e. you're done)

• check all of the rows in the play area for complete lines

Hope that helps...

Teej

Edited by - Teej on August 9, 2001 5:03:11 PM

##### Share on other sites
I am back from a brief vacantion at the country side !!!
So , what''s cooking dock? (read Teej ).
Could you find somme time and continue this wanderfull tutorial?
Ah , and I have a question :
Could you ( or somme one give me an input on DirectSound?
The ideea is that I am reading the SDK documentation but is
soooo big and is hard tu understand all from begining even more to applay . I had the same problem with DirectDraw but Teej''s tutorial hellped me to understand the basics , to have a fundations and now is easyer for me to understand DD.
For DirectSound , well , I tried to make a function that has
2 parameters : a LPDIRECTSOUNDBUFFER object and a path to a wav
file in the HDD, and that function should init that sound(wav).
Well I didn''t succed and the SDK docs didn''t hellped much ( streams chuks and all that .... I am not even shore how to translate those words in romanian ).
So a base start well explained ( like DirecDraw ) will be nce and handy

##### Share on other sites
teej....if got a big problem, i cant seem to access your download website. it has been 3 weeks now, and i fear that i willnot be able to follow your lessons.
HELP.

thanks

sorry to have post this question in this section.....it just that im heavent got any reply yet.......and i need help...

check out 00.00

• ### Forum Statistics

• Total Topics
628329
• Total Posts
2982104

• 22
• 9
• 9
• 13
• 11