My Coding Journal

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Tajari
Posts: 9
Joined: July 10th, 2017, 7:42 pm

My Coding Journal

Post by Tajari » July 10th, 2017, 7:54 pm

Hi!

I thought I would start up one of these journal posts as it seems to be the done thing around here. I have been lurking here and on Discord for a while so why not formalise things up.

First, a little background. I've been interested in coding since I was around 11 or 12 and I first discovered Game Maker 3. I thought it was amazing and made tons of stupid games with drag n drop before moving on to the coding. As time went on I learnt about proper programming languages and my first attempt at learning C++/openGL began when I was around 15. I didn't go so well and as time went on and other stuff distracted me (damn you World of Warcraft!) my programming died off.

I got back into things a couple of years ago with C# and XNA but now here I am trying to fulfil my earliest ambition of learning C++ and making proper games that aren't stupid text based things. I've just finished off the beginner series and I am celebrating by writing Tetris.

It hasn't been easy, there have been times where I've cheered, cried, given up, started again, given up again and all this in the space of 2 weekends but things are finally starting to take shape. I will release the source here once it is finished but the code structure is not very structured and is starting to resemble a famous pasta dish.

I've learnt a lot, mainly that I should probably plan the structure of how I will code my games prior to going balls deep but learning is what it is all about.

My plans are to finish off Tetris, get started on intermediate and practice that shit (pointers hurt my mind). If all goes well I plan to write a pacman clone, maybe space invaders and then who knows.

My ultimate goal would be some sort of multiplayer fps like PUBG or co-op zombies.

Today I have been finishing off the code for the rotations of each piece type. Tomorrow I will do the collisions and then I'm on the home stretch.

Wish me luck!

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: My Coding Journal

Post by chili » July 11th, 2017, 3:20 am

Nice start on a journal thread here bro. Sounds like you got a solid roadmap for the future here as well; start modest but also have an ambitious long-term goal. You seem to have the right mindset about code structuring as well. It's gonna be shitty when you start out, but don't let that cockblock you from getting that practice in. Just be aware of the shittiness and try to improve it incrementally every project. Just don't seize up because you are afraid of writing some shitty code, the #1 priority is just make shit and get that experience. Revel in the feces. Become one with the poop.

Looking forward to seeing what you got bro, post a repo link when you're ready.
Chili

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: My Coding Journal

Post by Zedtho » July 11th, 2017, 5:12 pm

Awesome, I really enjoy these, am looking forward to checking out this thread!

Tajari
Posts: 9
Joined: July 10th, 2017, 7:42 pm

Re: My Coding Journal

Post by Tajari » July 15th, 2017, 4:38 pm

Hi all,

Thanks for the words of encouragement, they definitely kept me going over the last few days of constant bugs, testing, fixing, breaking something else, retesting :lol:

I think it is now in a state that I'm pretty happy with and although the code is slightly embarrassing, I have uploaded to my git at https://github.com/Xerith89/Tetris I set out to make a game using only the things I had learnt in these beginner tutorials and so that meant some pretty interesting solutions to certain problems. I'm sure that this would have been much easier and cleaner to code with knowledge of inheritance, standard library goodies like vector containers and definitely strings.

Fingers crossed the code is fairly readable but if you have any questions then just give me a shout. Mad props to Salty Tristan for his image to chilli code tool! So I thought I would run through a mini post mortem about what worked, what didn't and what I learnt for next time.

What Worked

Although the code is fairly unorganised and a bit hacky, I'm actually pretty pleased that the game works as I wanted it to. I ran in to countless bugs that felt like I was hitting a brick wall. Each time I was ready to say fuck this and move on, the solution popped into my head (usually when I was trying to sleep). I was also pretty happy with the way I implemented the line scoring counter. During my research into the best solution I was blown away by what goes in to drawing text on screen.

What Didn't work

The code itself is not my finest hour, some of the solutions I've employed are hacked together and not particularly elegant in my opinion. The structure is to blame for much of this. I set out on this project without any real planning of how I would structure my code, what classes I would need and a potential blueprint for how I would achieve what I wanted; I just opened Visual Studio and went at it and ended up with pretty much all the important code in 1 cpp file. I think if I was doing this again I would have potentially used a .h and .cpp for each piece type and then a main block controller class that handles keeping track of them all.

What I learnt

The importance of git!!! Changing a lot of code to try and fix a bug and then getting halfway through and realising it won't work and I need to undo everything but with git that was literally a couple of clicks, no dramas 8-)
Testing because changing one thing can affect a fuckload of other things that you didn't mean it to :lol:
I was a bit more structured in my testing and had excel spreadsheet scenarios and everything! :geek:
I learnt about the need of planning and structure but most of all I learnt not to give up because although game dev and programming in general can be frustrating as hell, when things go right the feeling is amazing :D

Let me know your thoughts, let me know if you find any bugs. I know there is one where you can rotate even if there isn't room to do it so your block gets stuck, it hasn't come up too much in testing and I think it would be an easy fix with a switch statement and some other logic but I think the code is long enough as is.

I'm now heading on to Intermediate and the fun that comes with pointers and strings. I'm already starting to think about my end of Intermediate game idea, hopefully access to a few more goodies with make the process a bit smoother.

Catch you guys soon

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: My Coding Journal

Post by albinopapa » July 16th, 2017, 1:17 am

I think you already realize how monolithic your Block class is and what you suggested about making each piece it's own class ( since you don't have inheritance ) would be a good idea. Nonetheless, good job.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Tajari
Posts: 9
Joined: July 10th, 2017, 7:42 pm

Re: My Coding Journal

Post by Tajari » July 16th, 2017, 7:18 am

I think you already realize how monolithic your Block class is
I certainly do, I honestly am not sure why I let it get that big and didn't decide to change the structure earlier on when it would have been easier but there we go.

Thanks for taking a look at it! :D

Today I'm starting on the pointer videos. I watched the memory theory video last night and I'm quite happy with the concepts. I plan to mess about with pointers for a few days before moving on to screems.
I've also decided on pacman for my next game project and I have started planning.

Thanks for reading.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: My Coding Journal

Post by chili » July 16th, 2017, 4:45 pm

Nice project man, thanks for sharing. I think it might be worthwhile spending some time thinking about making the controls more responsive. That is a skill that is going to serve you well in many domains of the game development field.

Glad to hear you've gained a newfound appreciation for Git. It's an important tool and the sooner you realize it's importance the sooner you can git gud at exploiting it ;)
Chili

Tajari
Posts: 9
Joined: July 10th, 2017, 7:42 pm

Re: My Coding Journal

Post by Tajari » July 16th, 2017, 9:08 pm

Yeah I initially started out using the standard keyboard input which brought the need for some sort of cooldown but when I moved to events the need probably wasn't there any more but I didn't take the cool downs out. It was fun to make but I think I'll look back at the code in a few months and cringe.

On the plus side, pointers are starting to make sense.

Tajari
Posts: 9
Joined: July 10th, 2017, 7:42 pm

Re: My Coding Journal

Post by Tajari » July 22nd, 2017, 10:52 am

Hola,

Thought I would do a little update mainly for my own sake to re-confirm what I have done this week.

So I started off with a little pointer action and things finally started to click once you get to grips with 2 simple ideas -

Code: Select all

 Char* pointer = p;
- Declaring a pointer variable to store the memory address of p,

Code: Select all

*pointer 
- get me the value of the thing stored at the memory address in pointer.

If I've got that totally wrong then please let me know. I messed around with pointers for a bit doing the whole swap thing and messing about with arrays before moving on to C strings.

C strings really helped me in getting to grips with pointers and I was pretty happy with it. I went my own way when it came to the homework mainly because I have no idea what a Fibonacci sequence is and I find I'm much more motivated when I have a clear goal.

With that in mind I set out to make a simple calculator that takes 2 number inputs from the user, converts them from a string to an int, takes a string input that corresponds to an operation (1 = +, 2 = - etc) and then did the sum, converted the answer from int to string and outputted it to the user. Very similar to the Fibonacci idea (I watched the homework vid after) but with my own little spin.

With that all being good I moved onto the File IO stuff and that is where I currently am. I've watched the lesson vid twice and have played around with the code. The homework is an interesting idea but I'm gunna go my own way again on this and create something more game specific. I've decided to do a little save/load game feature with the ability to add to the variables being saved. I think the slight game twist will keep me inspired and also give me some good base knowledge for further down the line when I try to do a save/load system in an actual game.

So that's me, happy coding everyone!

Post Reply