Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Fri Feb 28, 2020 9:22 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Dec 23, 2013 1:52 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi,

Firstly thanks for writing this book, it is by far one of the clearest on the very confusing topic of DiractX & all the elements of game programming.

I would like to redesign the engine but using DirectX11 and primitives for my own learning experience. I am basing the work on the SpaceshipControl project as it has the basics up and running. I have managed to get directX 11 initalized with a DirectXBase class (which would be similar to your graphics.h), but I am very stuck on how to actually implement the primitives the way you have when you call e.g.

Code:
ship.draw()


I have a .h file "shapes.h" of which holds among other things:

Code:
public:
   BasicShapes(); //Constructor
   ~BasicShapes(); //Destructor

   void CreateSquare(ID3D11Buffer **vertexBuffer);
   void CreateVertexBuffer(unsigned int numVertices, Vertex *vertexData, ID3D11Buffer **vertexBuffer);


where
Code:
CreateSquare
are the vertices requires from the square and then it calls
Code:
CreateVertexBuffer


I am stuck from here to simple get a blank square appearing in my DX window. I am guessing I have to initialize the square first then call a draw() command, but have not been successful. I would like to store the square and use something like square.draw() similar to your code.

Any help would be greatly appreciated.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 23, 2013 4:45 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 554
First a comment; As far as I know, the only reason to use DirectX 11 for 2D games is if you are writing a Windows 8 store app. This page has a good overview of the different versions of DirectX and the supported hardware: http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Assuming you want to create your own Sprite class, take a look at the Console class from Chapter 8. A sprite is just a textured quad. The Console class creates a quad and renders text on it.

If you want to do something even more elaborate, such as surface sharing with D2D then these pages might help:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://www.gamedev.net/topic/547920-how ... ith-d3d11/

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 25, 2013 9:27 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi Professor Kelly,

Thank you for your response. I am just starting to learn Direct X so I thought it is a good procedure to use the sample code you provided and try to get it working in DX 11 as an exercise.

I now see where you have created the vertices in your console class. Right now I am not trying anything too elaborate, just to make a super simple engine that just renders a quad at the center of the screen.

I would then like to render another quad somewhere else and give it some simple AI such as wondering around randomly. This is purely for a learning exercise.

I believe I am close to getting my first goal, just a few difference between DX9 and 11 and I am not 100% sure where certain initialization routines should go. I will post here if I am successful.

Thanks again for the book.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 28, 2013 5:42 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
I finally got it working. The problem was in my createVertexBuffer command:

Code:
HRESULT createVertexBuffer(unsigned int numVertices, Vertex *vertexData, ID3D11Buffer **vertexBuffer);


I was not passing the **vertexBuffer just a *vertexBuffer, still wrapping my head around why I need to pass the double pointer though.

One quick question, would you have any advice on the simplest way to add some AI? Im talking just a CPU controlled shape that just walks around randomly or maybe chases the player. There is a lot of AI documentation on the net, but just some advice on how to make it work in your particular engine would be great.

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 29, 2013 12:43 am 
Offline
User avatar

Joined: Wed Oct 30, 2013 11:46 pm
Posts: 30
Quote:
Code:
HRESULT createVertexBuffer(unsigned int numVertices, Vertex *vertexData, ID3D11Buffer **vertexBuffer);


I was not passing the **vertexBuffer just a *vertexBuffer, still wrapping my head around why I need to pass the double pointer though.


because the function you are using wants the ADDRESS of the pointer. Not the VALUE of the pointer (the address that the pointer is storing as its "value").

As for the AI,
Quote:
Im talking just a CPU controlled shape that just walks around randomly or maybe chases the player.

I think you need to be a bit more specific. Chasing the player and moving randomly are two VERY different behaviours. If you want some "entity" moving at random across the screen just set up a random number generator. Generate two numbers every 5 sec and assign those two numbers to X velocity and Y velocity of the entity you want to move "randomly".
(you ll also need a timer :D )

As for the following.. that's a little harder. Supposing you have no obstacles or anything then just get your enemy's X position and Y position and the player's X position and Y position. Each frame you ll perform a couple of checks and you'll move the enemy closer to the player by however you want the enemy-s speed to be. (and this is "actual" simple AI. Moving randomly doesn't require too much intelligence :lol: )

As for DirectX11. I suggest you use DirectX9 and master it. At least this is what I am doing. All the techniques that you learn with DirectX9 will still be more than valuable with any future DirectX and even with different languages. You can get more support if you use DIrectX9. There's always time to "update"

Good luck
:)
Cla


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 01, 2014 12:33 pm 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Hi Cla,

Thanks for your response. I see now why to pass the double pointer, that makes sense. otherwise I am sending it some random memory location...

Regarding the AI, I will definitely start with just a randomly generated number movement scenario. I just struggle to really understand how things work without code to play around with. In the engine provided, I see there is an AI() sub category, I am guessing that would be where such calculations go.

I understand what you write about DX9. I guess all of methods of how graphic objects move and interact stay the same across all languages, just with different names or conventions. But since the engine provided is already DX9 it does not give me much to 'do' in terms of reshaping it for my own learning. So DX 11 gives me something to create from the ground up.

Thanks again.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 01, 2014 11:59 pm 
Offline
User avatar

Joined: Wed Oct 30, 2013 11:46 pm
Posts: 30
Quote:
I see there is an AI() sub category, I am guessing that would be where such calculations go.

Yes, exactly.
However, if all you want is an entity going around the screen to play around with. I suggest you initialise the enemyX, Y, enemyVelX, Y in the
Code:
Game::initialise
function.
Then in AI you will write something along the lines of:
Code:
enemyX += enemyVelX;
enemyY += enemyVelY;

In this way you would have a moving entity going. Make sure to check for collisions with/against screen borders to make the enemy stay on screen.

Quote:
since the engine provided is already DX9 it does not give me much to 'do' in terms of reshaping it for my own learning. So DX 11 gives me something to create from the ground up.

Yes. I suffer from not being able to build things from scratch as well. That's why I am taking everything apart just like you. I am just sticking with D9 but doing the same with D11 isn't a bad idea as the professor is knowledgeable in both and many people use D11 nowadays.

Cla


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 04, 2014 3:27 am 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
Thanks. I just got my Direct X 11 version of the engine working with a quad that I can move around. So I am on my way there. My next gole is the bounce feature to play around with some simple collision code. I am learning an awful lot from doing this, because this is one of the few source codes and books which actually has things written in a simple and understandable way.

Quote:
Yes. I suffer from not being able to build things from scratch as well. That's why I am taking everything apart just like you. I am just sticking with D9 but doing the same with D11 isn't a bad idea as the professor is knowledgeable in both and many people use D11 nowadays.

Cla


I will stick with DX 11 for now. I am actually using direct3d and just completely ignoring the Z axis so maybe when I make the jump to 3D it shouldn't be too hard.

I honestly cant express enough gratitude to Prof Kelly for putting together this book and source code.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 05, 2014 2:31 am 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 554
SteveHatcher wrote:
Thanks. I just got my Direct X 11 version of the engine working with a quad that I can move around.
Well done! It takes another programmer to appreciated how much work is involved in accomplishing that.
SteveHatcher wrote:
I honestly cant express enough gratitude to Prof Kelly for putting together this book and source code.
You are very welcome.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group