Sub's coding pool party

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Ah cool thanks for the feedback. I might have put the wrong link in the original post. I edited it to be Shadi's link, which I'm pretty sure doesn't have the missing .dll thing happening with it.

yteah i just had to download all teh C++ stuff n what not. well anyways

the game. u need to add instant drop button. i know right now u have down arrow doing that ... but it's not good cuz u accidently do it that way. slow down teh down arrow drop just a tad (very little bit not much at all) and add SPACE bar as instant drop. game will b much better. btw the whole adding something for a line being cleared is an overrated feature, tetris is quite cool without it. but anyways ... maybe add some combo bonuses ... say if u clear 4 lines with 1 drop .... and if u clear lines with consecutively from drop to drop. well anyways. i got pretty damn far. random generator not too bad. but could use a little tweak ....
I'll add spacebar as an instant drop. I'll also add a phantom shape at the bottom, I'm thinking a shape with black boxes that are like 40% or 20% transparent, which will show you where the dropped shape will land.

As for adding bonuses if you get more than one line at a time, I wanted to do that, I'm not sure why I didn't. It would be really easy to do, too. I'll make it so it'll double if you get two lines, tripple for three, etc.

and u need menu n what not .... and option to play easier mode n harder mode (basically speeds up or down)
Not going to add a menu because it'd be a pain for me. I could add difficulty though. I'm not sure, maybe the block will drop quicker for every 5 lines you clear.

OOO and add feature to SAVE a block in que .... i always loved that feature >< hehehe
I could do that pretty easy, I don't see why not. I'm not sure where I'd put it on the interface though.

AND u ur missing a block shape. u need to make the reflection of the TEAL block.

and u need a HOW TO PLAY section

and PLEASE PLEASE PLEASE .... add a pause button ><
There is a pause button, press backspace. I gotta make a visual button you can click on with your mouse, but yeah, I had to add a pause button to figure out why a bug was happening so it's in there.

Not going to add a how to play, it's Tetris!

I have the reflection of the teal block in there, but for some reason, the random number generator almost never picks it. That really bothers me, so I'm going to find a random number generator library that gives out a more even distribution of numbers and just use that library.

Thanks for the feedback, was incredibly kind of you.
 
Last edited:
Member
Discord Member
Joined
Mar 23, 2011
Messages
304
Best answers
0
Ah cool thanks for the feedback. I might have put the wrong link in the original post. I edited it to be Shadi's link, which I'm pretty sure doesn't have the missing .dll thing happening with it.



I'll add spacebar as an instant drop. I'll also add a phantom shape at the bottom, I'm thinking a shape with black boxes that are like 40% or 20% transparent, which will show you where the dropped shape will land.

As for adding bonuses if you get more than one line at a time, I wanted to do that, I'm not sure why I didn't. It would be really easy to do, too. I'll make it so it'll double if you get two lines, tripple for three, etc.



Not going to add a menu because it'd be a pain for me. I could add difficulty though. I'm not sure, maybe the block will drop quicker for every 5 lines you clear.


I could do that pretty easy, I don't see why not. I'm not sure where I'd put it on the interface though.



There is a pause button, press backspace. I gotta make a visual button you can click on with your mouse, but yeah, I had to add a pause button to figure out why a bug was happening so it's in there.

Not going to add a how to play, it's Tetris!

I have the reflection of the teal block in there, but for some reason, the random number generator almost never picks it. That really bothers me, so I'm going to find a random number generator library that gives out a more even distribution of numbers and just use that library.

Thanks for the feedback, was incredibly kind of you.

np man. but the HOW TO PLAY for me was just at least the keys commands. like up arrow is rotate down is drop left right space bar is instant drop backspace is pause. just some text to let us know before we play. was fumbling around for keys first time i tried it.

oh i was wondering. u know how when u go left n right. it goes one space and when u hold it it pauses there for a second. i was wondering if u could tweak that time to b a little less (the pause before it just moves a **** load fast, should b same as the down one right? not sure how u coded that part) like sometimes im nearly at the top .... and i lose cuz of that pause time. it doesn't move in time. i know some tetris versions have a grace period. give u like a second extra when its right on top of something n against it, that part is probably hard to code >< not sure. but just having it b able to move left n right with a less pause would do wonders


and to add the save a block thing. u can just either put it under the lines thing or just move the lines score down a little. ^_^

and also i know u mentioned u would b adding the clearing more than 1 line thing. but what about in consecutive drops.
like say u clear 1 line with a block and on the IMMEDIATE next block u clear another line. basically it's called chaining in tetris. ull have to find a good balance for it though. maybe make it a multiplier of the total score.

ex:

u got 1 line for 400 points
and the immediate next drop u get another line for 400 points.
it would multiply by 2 then. so instead of 400 total its 800 total.

another example

you get 4 lines in 1 drop = 1600X4 (multiplier from 4)
you get 4 lines in 2nd drop = 1600X4 (multiplier from 4)

you have 12800 ... but since it's 2 drops in a row. it is now 25600

and no i am not saying u should use these exact multipliers (can use 1.5 then increase the increments by however much u want, doesnt need to keep doubling, you can go 1.5/2/2.5/3.0 or 1.5/2.5/3.5 n what not). but something along the lines like that. have to reward skill moves, chaining and multiple lines

yeah hardest time i had was figuring out how to pause >< i had to go do something n i was like 104 lines in .... was epic fail >< hahaha
 
Last edited:

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Right now, if you hold down a key for .400 of a second, it'll go fast in whatever direction you hold it down. It takes .600 of a second for a block to naturally drop down one line. It looks like the timer for a shape to move down doesn't get reset when you spawn a new shape, though, which is probably why you didn't have enough time to move. I'll make it reset everytime a new shape is spawned.

If I get finished with everything else I want to do with it and I still have energy to throw in a controls menu, I'll do it. I don't know, though.

I fixed the scoring system last night and yeah, chaining is in there now. So if you get 2 lines, you'll get more points than you would for 1 line, and then if those 2 lines cause another line to clear, you'll get even more points for that. I think I just doubled the value for 2 lines at once, tripled for 3 lines at once, etc, and then if you chained, added the new points to the lines you just cleared and doubled that.

I'm not sure what key to make the hold shape. Shift maybe?
 
Last edited:

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
I added in a phantom shape at the bottom that will show you where the block will fall. Also added in spacebar as an instant drop, score now resets when you reset the game, and scoring system will give you bonus points for getting more than one line at once and for chaining. Also, apparently the game ended whenever you put a block at the top height. Now fixed it so that the game will only end if a block spawns on an existing block. Also made it not restart automatically when the game is over and you pressed enter during the previous game. You now need to press enter on the game over screen in order to restart it. Trying to make it bugless.



https://rapidshare.com/files/3144589545/SubTetris.7z

Still want to make the random number generator not suck, make the game gradually increase in difficulty, add block holding, and probably buttons which pauses and restarts the game, and a few other things.
 
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Mar 13, 2005
Messages
3,877
Best answers
0
Sub you are learning quite quick. Congrats man. Keep going and you might be the next lead coder for Activision or so man. I gotta say I still can't get passed the "Hello World" coding.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Eh, I know there are a ton of problems with how I wrote this, but all I can do is try to do better on the next thing I make.

edit: Thanks though
 
Last edited:
Member
Discord Member
Joined
Mar 23, 2011
Messages
304
Best answers
0
sweet man. im gonna start playing again when i ge home ^_^
 
Active Member
✔️ HL Verified
💻 Oldtimer
Joined
Mar 13, 2005
Messages
3,877
Best answers
0
Badly written code is better then coding that doesn't work.
 
Member
✔️ HL Verified
Discord Member
Joined
Oct 16, 2006
Messages
379
Best answers
0
Location
the Netherlands
Hey Sub,

Good thing you started with another project :)

I will not comment on any of the SDL stuff or the way you made tetris as I haven't got the experience with either.
I will however comment on your structure, or the lack of structure in your code.

Do you want to code C or C++ ? You've got to make a decision as you're currently using C tricks(having global headers and defining some functions later on) and almost object oriented programming.
The classes you did make where also not really the way to go on some points.
Take Shape for example, methods like handle_input, GetIfKeyHeldDown, SpawnNewShapeIfNeeded, SpawnNextShapeInSidebar, CheckGameOver, GetRestart, SetRestart do not really belong there.
You have to ask yourself, what IS a shape, what defines a 'shape'? In my book it should only be able to draw something on a certain point on the screen, which has basics like position, scale and rotation.

Also, try to break the code up into more objects, Text fields for example, if the library doesn't have a oneliner to create a textfield, create the class yourself.

Try to avoid methods which are larger than 15 logical lines of code(LLOC). The more LLOC you have, the greater the complexity will be, which in term is more difficult debugging, hard to read for other developers and can generally break down faster.
Having that said, remove that functionality from Main! In my opinion Main is a sacred place where you shouldn't do any else except initialising your game class and allowing it to loop.
On a side note, the coding conventions for C++ state that methods should not start upper case.
Actually, there's more than one coding convention, but whenever you begin a project, just make a choise which conventions you want to follow.
I find this one nice, but I don't agree on all points, http://geosoft.no/development/cppstyle.html

I haven't check your memory usage yet, or played the game, but remember, for every object you instantiate(using new, arrays, or mallocs) you have to delete them.

Also, throw in a fps meter, if your FPS isn't stable, there's a method which gives your CPU a hard time, which you can locate and fix.

Create methods and classes that fits it's description, nothing more. A 'draw' method should only draw something, not change it's position, rotation or check collisions for example.

Anyway, good luck, try to revamp this one so we can take a look at it again.

PHew long post! Anyway, it's almost time for beer as it is Queensday in good ol Holland CHEERS
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Hey Sub,

Good thing you started with another project :)

I will not comment on any of the SDL stuff or the way you made tetris as I haven't got the experience with either.
I will however comment on your structure, or the lack of structure in your code.

Do you want to code C or C++ ? You've got to make a decision as you're currently using C tricks(having global headers and defining some functions later on) and almost object oriented programming.
The classes you did make where also not really the way to go on some points.
Take Shape for example, methods like handle_input, GetIfKeyHeldDown, SpawnNewShapeIfNeeded, SpawnNextShapeInSidebar, CheckGameOver, GetRestart, SetRestart do not really belong there.
You have to ask yourself, what IS a shape, what defines a 'shape'? In my book it should only be able to draw something on a certain point on the screen, which has basics like position, scale and rotation.

Also, try to break the code up into more objects, Text fields for example, if the library doesn't have a oneliner to create a textfield, create the class yourself.

Try to avoid methods which are larger than 15 logical lines of code(LLOC). The more LLOC you have, the greater the complexity will be, which in term is more difficult debugging, hard to read for other developers and can generally break down faster.
Having that said, remove that functionality from Main! In my opinion Main is a sacred place where you shouldn't do any else except initialising your game class and allowing it to loop.
On a side note, the coding conventions for C++ state that methods should not start upper case.
Actually, there's more than one coding convention, but whenever you begin a project, just make a choise which conventions you want to follow.
I find this one nice, but I don't agree on all points, http://geosoft.no/development/cppstyle.html

I haven't check your memory usage yet, or played the game, but remember, for every object you instantiate(using new, arrays, or mallocs) you have to delete them.

Also, throw in a fps meter, if your FPS isn't stable, there's a method which gives your CPU a hard time, which you can locate and fix.

Create methods and classes that fits it's description, nothing more. A 'draw' method should only draw something, not change it's position, rotation or check collisions for example.

Anyway, good luck, try to revamp this one so we can take a look at it again.

PHew long post! Anyway, it's almost time for beer as it is Queensday in good ol Holland CHEERS
Thank you for the feedback, I greatly appreciate it! I've read that I should avoid globals if possible, but I wasn't sure how to to the SDL stuff without having global variables. Should I just have initialized them in main and passed them to whatever functions they were used in? The same thing goes for the constants such as screen height and screen width, should I have declared them in main and passed them to whatever functions they were needed in, or maybe defined them in each .cpp file they're in? They're constants, so I'm not sure if it would be harmful to have them as globals.

It would have made a lot of sense to separate the code into more classes, so I'll try to work on that. I'm sick of Tetris at this point so I don't think I'm going to revamp this program, but I think the next thing I'm going to do is Solitaire. I'll focus on having a more logical program structure, more restrictive functions, and using main only for initializing and running functions. I'll also try to follow the naming conventions from that link, although there are almost 100 rules on there so we'll see how well that goes.

I made this after reading the tutorials from this site [http://lazyfoo.net/SDL_tutorials/index.php]. The sample programs on there are literally just moving a dot around a screen, and it uses around the same amount of memory (6 - 14% CPU usage) as the sample tutorials, so I'm hoping I didn't mess anything up too badly, although it wouldn't surprise me if I've done something terribly wrong in that area. At one point in making the program, I tried to create a function that doubled the size of a dynamic array if it was about to run out of room. If I understand correctly, I passed in a pointer by value, assigned it to memory allocated inside the array, which ended up being leaked memory as soon as the function ended...

On a final note, even though I'm half-convinced you just made it up, happy Queensday! :D
 
Member
✔️ HL Verified
Discord Member
Joined
Oct 16, 2006
Messages
379
Best answers
0
Location
the Netherlands
You can get rid of globals by using good structured classes.

The CPU usage is proberly due to the fact that you didn't cap your game loop. Try implementing this game loop delay with SDL_ticks and SDL_delay; http://www.koonsolo.com/news/dewitters-gameloop/

On a side note; If you wish to know some design patterns(the way we construct classes in certain cases) you should check out http://sourcemaking.com/. It has alot of C++ example with a before and after situation. But I must say, putting design patterns in game doesn't necessarily make them better or faster.

PS. Queensday is very much real, especially the next morning. http://en.wikipedia.org/wiki/Koninginnedag
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
Do you want to code C or C++ ? You've got to make a decision as you're currently using C tricks(having global headers and defining some functions later on) and almost object oriented programming.
The classes you did make where also not really the way to go on some points.
Take Shape for example, methods like handle_input, GetIfKeyHeldDown, SpawnNewShapeIfNeeded, SpawnNextShapeInSidebar, CheckGameOver, GetRestart, SetRestart do not really belong there.
You have to ask yourself, what IS a shape, what defines a 'shape'? In my book it should only be able to draw something on a certain point on the screen, which has basics like position, scale and rotation.
I agree. You might not even want the Shape to draw itself (should milk un-cow itself?). If you make a dedicated shape drawer, you can easily switch to a different shape drawer at a later stage (e.g. from OpenGL to DirectX, from 2D to 3D, ...). For some reading on the topic I highly recommend getting a copy of this:
http://www.amazon.com/Fundamentals-Object-Oriented-Design-Meilir-Page-Jones/dp/020169946X (it's only 5$ for a 2nd hand version; although the title might make you think differently, this is a book on OO design, not so much on UML).
Try to avoid methods which are larger than 15 logical lines of code(LLOC). The more LLOC you have, the greater the complexity will be, which in term is more difficult debugging, hard to read for other developers and can generally break down faster.
Meh, I wouldn't say lines of code, or 15 per function is a strict goal. Many lines of code does not make your function hard to read per se. Code could become hard to read if you have many nested ifs and fors. Normally I write relatively long functions and start splitting them up at a later stage if my head hurts when trying to understand them, or if part of the function can be reused for some other function. So, split if your head hurts, of if you find yourself copy-pasting code :)

On a side note; If you wish to know some design patterns(the way we construct classes in certain cases) you should check out http://sourcemaking.com/. It has alot of C++ example with a before and after situation. But I must say, putting design patterns in game doesn't necessarily make them better or faster.
Every programmer should have a design patterns book on his desk. I have this one: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612, which is the classic work, but maybe not the most readable thing on the topic. If you are a somewhat experienced programmer, you already know all these patterns and all this does is give you a nice vocabulary to talk with other coders. I'm not really sure what this will bring you when you're not an experienced programmer though. At best it will help increase your learning rate, at worst it will all go over your head.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Thanks for the advice Harsens. I just ordered both of those books, although I have a feeling that they're going to go over my head. I'll give it a try, though.

Writing solitaire right now. I have all the SDL Surfaces pointers in an SDLGraphics class, as well as all the other graphic functions like drawSprite, clearScreen, and all that fun stuff. Trying to keep everything where it belongs.
 
Last edited:
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
You might also want to take a look at the head first series:
http://www.headfirstlabs.com/
This might or might not be a learning style you like and the books are quite expensive so I suggest borrowing one first, or at least look at the website a bit and download some example pdfs before buying.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
I received both of those books in the mail, looked over the UML Object Oriented Design one and it seems doable and easy to understand. I have a 99.5% done version of Solitaire and a 99.5% done version of Conway's Game of Life [http://en.wikipedia.org/wiki/Conway's_Game_of_Life], once I'm done with them I'll give the books a read.

The Game of Life program has a bug in it where it miscounts how many neighbors each cell has so the patterns it produces right now are completely off, but it still produces some cool stuff. This



made this for example

 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
So I've made Conway's Game of Life [http://en.wikipedia.org/wiki/Conway's_Game_of_Life]. It's more or less done, with the exception of a pretty obvious memory leak in the drawing of text stuff, and the red cells are kind of messed up right now. They'll flash green for a brief moment every turn and they won't move onto a square that a green occupied previously. I know how to fix the red cell stuff, and I think I will, but I'm throwing this out there for now.

As for the memory leak, well, I wrote all the menu stuff last night and had like no sleep when writing that. I'm not really sure how to make that go away, but I think I can figure it out if I spend like a little time on it. Anyways,

http://www.mediafire.com/?blyu37ygs5uabz3

oaopeaado.jpg


main.cpp
http://pastebin.com/tGxm3Z1n

board.h
http://pastebin.com/MzWHNJ2w

constants.h
http://pastebin.com/hxQRkH5w

input.h
http://pastebin.com/9VqDZfWj

menu.h
http://pastebin.com/rr3yNPX1

sdl_graphics.h
http://pastebin.com/8A74BvDN

simulation_rules.h
http://pastebin.com/PtQJjyMX

timer.h
http://pastebin.com/HyT4pHRd

board.cpp
http://pastebin.com/p9Yh1XEF

input.cpp
http://pastebin.com/tp0JWUNb

menu.cpp
http://pastebin.com/kfNKCPNs

sdl_graphics.cpp
http://pastebin.com/shMu4p7p

simulation_rules.cpp
http://pastebin.com/sUWyA0gS

timer.cpp
http://pastebin.com/Phajhpji
 
Last edited:
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
I quickly skimmed over board.h and board.cpp. One of the things you could work on is the "problem of naming things", which is the hardest problem in programming. Some suggestions:
WhichOne => index
resetIsCellOccupied => resetAllCellOccupations
setSwitcher => flipSwitcher
SwitcherValue(bool) => setSwitcher(bool)
These kinda small name changes make you able to more easily read your programs months after you wrote them.

You might consider moving the definition of NUMBER_OF_CELLS_ON_GRID to board.h, since it seems a property of the board?

Currently you use the boolean Switcher as an integer index into IsCellOccupied which bad style and might even be somewhat dangerous since true is not necessarily equal to 1 in C++. Consider either making Switcher an integer, or making some function to get an index from Switcher.
 

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Thanks for the input. Naming things is surprisingly hard, I'll often pause and think for a few minutes on what the best name would be for a variable / function. I often wonder if it's better to have a longer name that is more descriptive, or a shorter name that's less descriptive but easier to remember and type.

Once again, thanks for the input. I appreciate any advice I get, because I feel like I have no idea what I'm doing and I'm just banging my head against the wall until everything is mostly working.
 
Last edited:

sub

Active Member
💻 Oldtimer
Joined
Jun 18, 2003
Messages
5,961
Best answers
0
Location
New York
Making Drug Wars. Made a really quick mockup of what the final UI will roughly look like.

ZC6vj.png

Things would be properly spaced out on the final version, I just kind of did that by eye. The goal of the game is to get out of debt and make a certain amount of money before the end of the game by buying and selling drugs. It's a turn based game, with each turn representing a day, and with the price of drugs changing each day. Clicking on the map would take you to that part of New York and advance the day by one. You'd occasionally get messages in the message log which state that the price of whatever drug will increase / decrease in certain areas, but that information won't always be correct. Next to the inventory it says button toggle -- that's basically going to be a button which toggles between the drugs in your inventory and the items (such as weapons and vehicles) in your inventory.

---
For comparison, here are some screenshots of some existing drug war games

o2bNt.jpg

1.jpg

49234_large.jpeg

I borrowed heavily from the second one, but there are some changes.

Anyway, I was planning on making the game with MFC, but it turns out that you need to pay in order to use MFC. I looked at QT and a ton of other GUI options out there, even some that were made specifically for SDL which is what I've been using, but in the end I decided that what I want to do is not really that complex, I'm going to try to make it without any UI libraries.

The only thing at the moment that I can see giving me a hard time is the mechanics for changing location. There are 5 locations on the map, and I want it to work so that if you click on one of the areas, you'll go to that area and advance the day. This means that I'm going to need to figure out how to get the pixel color for the xy coordinates where the mouse clicks, and if that color matches one of the five colors, move to that area and advance the day. I'm just not sure how to do that, but it can't be too bad I don't think.
 
Last edited:
Just a nice person :)
✔️ HL Verified
Joined
Jul 17, 2009
Messages
262
Best answers
0
Location
The Netherlands / HOLLAND!
This looks good. Reading through this would help some people like me as well.
Thanks for sharing :)

EDIT:
Also, I'm mainly programming in C#. So this is new for me as well.
 

Users who are viewing this thread

Top Bottom