Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 2d game engine done by a newbie - progress diary  (Read 9538 times)

0 Members and 1 Guest are viewing this topic.

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
2d game engine done by a newbie - progress diary
« on: October 15, 2013, 12:17:37 am »
Hey there. I'm slowly but surely making my first 2d game engine in SFML 2.1. I figured that sice I'm making it, I might as well share my code, and get some feedback to make it better :)

15.10.2013
http://speedy.sh/V88ww/IncuEngine-15.10.rar
20.10.2013
http://s000.tinyupload.com/index.php?file_id=00971552907888389184
What's in so far:
- Main loop and all the basics
- image manager class
- tile class
- basic mapping
To be done next:
- basic camera movement
« Last Edit: October 20, 2013, 10:08:02 pm by Kyubey »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #1 on: October 15, 2013, 12:24:52 am »
Supposedly you have to distribute some "visual C++ runtimes" or whatever, but to be honest I've never had to do that and I have no idea why some people always have to do that.  I can only assume it means you chose a project type that adds a lot of extraneous crap (try a "Blank Project" sometime since that's the only safe one) or you're using some non-standard extension.

Also, make games, not engines.  It's easier, more fun, and when you make actual games the engine behind it turns out far better in the long run.

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #2 on: October 15, 2013, 12:30:23 am »
Hmmm... I think I might do just that. I mean my goal was to make a game based on this engine anyway, so might as well start throwing stuff in for this specific reason from the start. Also, I'll remake the project with "blank project" option. Thanks for the tips!

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #3 on: October 15, 2013, 12:42:36 am »
Cool.  Hopefully you can get that standalone-ness(?) problem out of the way now while the codebase is still small.

Incidentally, if you have any desire to be cross-platform, at some point you should get your code running in a Linux VN, but you can probably put that off a lot longer (eg, until you have some real gameplay) as long as you're using only SFML and the standard library.  But that's the only other big thing I can think of where not planning ahead might screw you over.

Look forward to seeing how it goes.

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: 2d game engine done by a newbie - progress diary
« Reply #4 on: October 15, 2013, 05:27:07 pm »
1. Don't include in archive data that could be regenerated. I mean local solution data, precompiled header, compiled objects. Other programmers do not need them. Real size of your project is just several kilobytes. And RAR is a good archiver, but Linux guys don't have it. =)
2. If you want to share your code - use special services for it. Bitbucket or Google.Code, for example.
3. Precompiled header is not used in your code. So turn it off.
4. Always check an index of array that your function receives. In critical places use assert macro:
assert(index < imageList.size());
It will check expression in Debug build and skip check in Release.
That's all! =)

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #5 on: October 15, 2013, 05:35:10 pm »
You can unpack rars with unrar or unar on Linux, it's not a big deal.
Back to C++ gamedev with SFML in May 2023

ChronicRat

  • Sr. Member
  • ****
  • Posts: 327
  • C++ programmer
    • View Profile
    • My blog
Re: 2d game engine done by a newbie - progress diary
« Reply #6 on: October 15, 2013, 05:40:57 pm »
You can unpack rars with unrar or unar on Linux, it's not a big deal.
There was a smile. May be my russian humour is not clear? =) Forget it.

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #7 on: October 16, 2013, 09:36:37 pm »
Thanks for feedback ChronicRat. Gonna try to add asserts from now on. I didn't have much time latety, but I'll try to make some mapping class tonight. Gonna share it ofc! :)

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #8 on: October 17, 2013, 10:16:52 pm »
Ok, I'm stuck. Could someone give me an idea for making a map? My current idea is kinda dumb. Here's my code - it's not compiling but it'll explain it better than I would.

http://s000.tinyupload.com/index.php?file_id=52683591925031820198

The idea is really primitive behind mapping is primitive, but I wanted to ask about one other thing while I'm at it. In Mapping.h I have a vector in which I hold my Tiles. If I want to use Tile class functions from them, how would I do that? Is the way I'm doing it right?

I'm going to set up google.code or something along those lines in the near future, so you don't have to download the source all the time.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #9 on: October 17, 2013, 10:32:00 pm »
If the only purpose of these classes is to draw a tile map, then this is about the most inefficient way you could possibly do it, because you're storing one texture per tile.  Unless every single tile in your map actually uses a different texture, that's a massive waste of resources.  Plus, you can draw the entire tilemap with only one draw() call if you use a spritesheet and vertex array properly.

The official SFML tutorial on VertexArrays includes some example code for a tilemap, because 2D games with tile-based maps are such a common use case.  Go read it: http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #10 on: October 17, 2013, 11:19:18 pm »
Thanks again for the input Ixrec! That's really handy and kind of easy to use - I'm going to code it tomorrow.

@Edit: Nevermind, I'll do it on Saturday.
« Last Edit: October 17, 2013, 11:48:23 pm by Kyubey »

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #11 on: October 20, 2013, 10:07:23 pm »
Ok. I did mapping based on Vertex arrays. I don't know how to use sites like google.code so until I get around to learn how it works I'll continue to upload entire code.

Next time I'm going to add some kind of camera movement - I'll have to do some research tho.

As always, feedback is appriciated!

LINK: http://s000.tinyupload.com/index.php?file_id=00971552907888389184

SneakySnake

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #12 on: October 21, 2013, 06:44:27 pm »
I don't know how to use sites like google.code so until I get around to learn how it works I'll continue to upload entire code.

I would recommend using GitHub. It is a very popular project hosting service, and it has beginner friendly clients for Windows and Mac.
It also has a short tutorial on how to use Git: http://try.github.io
Oh yeah, and it's free if you only use public repositories.

I also took the liberty to make your engine linux-compatible.
Here are the patches (generated by Git): https://gist.github.com/crumblingstatue/7086887

The red ( - ) lines are the removed lines, the green ( + ) lines are the added lines.

Kyubey

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • Email
Re: 2d game engine done by a newbie - progress diary
« Reply #13 on: October 21, 2013, 10:20:56 pm »
Thanks a ton SneakySnake. I'm going to read Git stuff tomorrow and for making my code Linux-friendly have a classy pug on a horse: http://oi42.tinypic.com/2ajndp3.jpg :)