Programming 2D Games

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

It is currently Sat Jan 19, 2019 1:05 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Jan 09, 2019 3:09 am 
Offline

Joined: Wed Jan 09, 2019 2:46 am
Posts: 3
Hello, so I recently came back to this book because I forgot it has examples of isometric. I always avoided isometric because it looked way too complicated, only until recently see it's not much different than regular tiles. But I have some confusion with the formula you're using in this book.

So far I have gathered that:

I want to find out half the width and height of the tile. (for this example lets say 64,32). When I run a simple for loop I would do x = j * TextureSizeX/2; y = i * TextureSize/2;

Using a simple function like this I could plug (x, y) in and have it give me the correct results.
2dToIso:
isoX = (x - y)
isoY = (x + y) * 0.5
--------------------------------------------------------
Now in this book, and from what I gathering in my prehistoric isometric programming book it uses something that seems much more difficult to work with. I noticed BOARD is (WindowSize / 2 - TextureSize / 2)
float x = BOARD_X - (x * TEXTURE_SIZE / 2) + (y * TEXTURE_SIZE / 2);
float y = BOARD_Y + (x * TEXTURE_SIZE / 4) + (y *TEXTURE_SIZE / 4)

The first thing I thought was "perhaps this is simplifying it all for me?" but that doesn't seem to be the case. I understand that BOARD is just an offset, but why is this formula specifically used? Is there any benefit to using it like such in the long run?
---------------------------------------------------------------------------------
With my first example the function to go from isometric back to 2D would be:
IsoTo2D:
isoX = (2 * y + x) * 0.5;
isoY = (2 * y - x ) * 0.5;

And to get the tile coordinates:
float tempX = point.x / (float) tileSize.x;
float tempY = point.y / (float) tileSize.y;

How would I do that with the example formula from the book? What am I not understanding here?

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 09, 2019 2:14 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 550
The difference is you are using a rectangular texture of 64,32 while the code in the book uses a square texture. Other than that and the BOARD offset which you already mentioned the code is the same.

The following is example code from my new book. It calculates the selected tile row and column.
Code:
    // Calculate location of pointer relative to isometric grid.
    // This treats the top corner of the board as location 0,0.
    pointerX = input->getPointerX();
    mouseXMap = (pointerX - SCREEN_X) / mapZoom - scrollX;
    pointerY = input->getPointerY();
    mouseYMap = (pointerY - SCREEN_Y) / mapZoom - scrollY;

    // Calculate selected column
    selectedCol = (int)(mouseXMap / TEXTURE_SIZE_TERRAIN + mouseYMap /
        (TEXTURE_SIZE_TERRAIN / 2));

    // Calculate selected row
    selectedRow = (int)(mouseYMap / (TEXTURE_SIZE_TERRAIN / 2) - mouseXMap /
        TEXTURE_SIZE_TERRAIN);

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 09, 2019 11:49 pm 
Offline

Joined: Wed Jan 09, 2019 2:46 am
Posts: 3
Hello Prof Kelly,

I appreciate the response, I wasn't actually sure if this forum was active anymore (I couldn't figure out my old screen name). You mentioned you have a new book (I hope I've read that correctly)? Where can I check this out at? I see you only have 2D Game Programming when doing a brief search. Unless you are referring to updated pages/source code? I've had 2D Game Programming since the 1st day it was released.

Anyways, I'm not quite sure I understand. I am actually using your same tiles to display these results. I only mentioned the 64,32 because the tiles I'd like to use are that size. I'm using the Checkers sprite sheet to be more clear. So I get the same results with either formula. Unfortunately, I haven't used more than basic Math for 12 years (I've come back to programming in the past year dedicated) so I apologize for possibly not seeing the obvious. Which is why I'm having a hard time figuring out how to go back to cartesian and retrieve the correct tile in isometric with that specific formula. With all that said, this is just me finally sitting down and figuring out how you work with isometric.

I have one more question (thanks again for the help). I'm 32 now, I use to program back in elementary school and moved up to C++ in high school. Long story short, I abandoned it after getting some bad advice in college and changed my degree. Unfortunately, I am now on permanent disability and have had all the time in the world to come back to my passion and have far surpassed all my knowledge before (but damn! I'd wish I had 12 years of doing this straight!). Not to mention I have money to purchase needed books (up to 17?). It has been 1.4 years of programming 4-12 hours a day (85% of the time). My problem has been not stopping to do my own project as I constantly love learning new things and ways to implement something more efficient (I got obsessed learning about design patterns haha).

In the meantime, I'm working towards my goal of a rogue like. I'd love for it to be isometric, but art-wise, it's just too big of a pain. So I'm okay settling with the traditional rogue style (not ASCII though). I've actually found your little dungeon crawler example very helpful. But I at least want a "complete" basic engine (using SFML at the moment) and to the point where I can simplify a lot of it and expand (which is why I like the design patterns). I just don't want to end up wasting my time where I have to rewrite something ALL over again once I actually try my own game. It would be great to stop learning cool implementation and concepts so I could stop making prototypes and do my own thing haha.

(This is where I get to the real question)
With that said, when I returned I started back using SFML, then I transferred to SDL and am now back to SFML. I dipped into some OpenGL (not really interested in 3D yet) and I like the fact that SFML is really compatible with it. I would like to give DirectX a shot again, especially because I heard it is way more intuitive (at least a few aspects apparently) than OpenGL. Is this book a bit outdated to use to learn DirectX again? I believe the book uses DirectX9 and isn't it up to 12 now? I'm really only interested in 2D game programming, but there will be a day where I may way to try the next step!. What are your thoughts on using DX9 today?

Much appreciated, thank you.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 10, 2019 12:13 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 550
My new book, which I'm still working on, will feature 2D game programming for UWP (Universal Windows Platform). That means the games will run on Windows 10 and on the XBox. I don't have a release date yet because I still have a bunch of code to write. I'm currently adding physics to the game engine. I'll post on the forum and on my Twitter feed twitter.com/professor1300 when it is ready. I would humbly recommend waiting for my book :) but if you can't wait, take a look at Win2D. I'm using it in all my new code.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 11, 2019 3:24 am 
Offline

Joined: Wed Jan 09, 2019 2:46 am
Posts: 3
I will 100% purchase your book. From what I remember your book was very consistent in terms of not having errors and confusion between the book and source code. I think your book was one of the few where every damn source code booked right out of the box and didn't involve solving a bunch of errors. I'd highly advise making sure the book code is the same code in the source code. I've purchased many books, mostly from Packt and I've recently stopped because the amount of errors (Grammar, source code, etc.) and the constant errors where the book might be right or the source code might be right; it's tiring. I have every C++ book on the damn site at the moment (excluding Unreal and QT).

I'm looking forward to your book and will keep an eye out. Although I'm assuming, you're saying DX9 is just a bit too old these days and to wait, I had no regret buying your book when it was released (despite really not being qualified to follow the code at the time). But at the time you released 2D GP I thought it was the most well-done book I've read and the best part was actually being able to REACH the author of the book. I feel like forums are dying out in some aspects, call me old school but I find them a great help on many levels. I remember back on the release of your first book I asked you to run a poll on a "theme/topic" for your next book (must have been 7-8 years ago!).

I love how you plan to cover some isometric examples, and hey! wouldn't hurt to put some rogue/RPG elements in that thing either! :lol: Unfortunately, I don't have twitter or use any social media anymore. So I'll be sure to check in on your site. Based off how much you have done, you couldn't give any estimation on the release time? Would you at least say this year? Is there anywhere I can find more information on what you are covering? Perhaps a table of contents? Pages? I actually was under the impression UWP was for mobile programming, so that's was interesting to look into it a bit more.

Anyways, once again, much appreciated and looking forward to it! I'll check out Win2D.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 11, 2019 12:28 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 550
Thank you for the comments on the accuracy of the source code in my first book. That is something I really focused on. I'm doing the same thing for the new book. I write and test the code for a chapter before I start writing the text. Something every textbook author should do in my humble opinion.

The new book should be available this year.

Here is a "tentative" table of contents:

Code:
Annotated Table of Contents(proposed)

Chapter 1 – Getting Started.
      Updated to include installation of the required software in Windows 10.

Chapter 2 – Windows Programming Fundamentals
      Topics updated for Windows 10.
      
Chapter 3 – Introduction to UWP.
      Topics updated for UWP and Win2D.
      Running code on the XBox.

Chapter 4 – Game Input
User input from keyboard, mouse and controller
      Creating our first game
Creating the Game Engine
The Game Class
The Input Class

Chapter 5 – Sprites and Animation
Drawing images with Transparency.
Displaying Animated Sprites
Movement, Rotation and Scaling
The Graphics Pipeline
      Drawing with Transparency
Sprite Textures
Loading the Texture
Drawing the Sprite
The Image Class
      
Chapter 6 – Collision Detection and Physics
      Bouncing off the Walls
      Collisions
Circular Collision Detection
Box Collision Detection
Rotated Box Collision Detection
Rotated Box and Circle Collision Detection
      Physics for 2D Games
Gravity Effects
Using Collisions and Physics in our Game
      Vector Math
      The Entity Class
      
Chapter 7 – Sound
      Obtaining Audio Files
      Creating Audio Files
      Playing a Sound
      Adding Sound Effects to our Game
      Adding Background Music
Using XAudio2
      Adjusting Audio Playback
      Adding Audio to the Game Engine
Playing a Sound
Stopping a Sound
Audio Clean Up
Incorporating the Audio Class
      
Chapter 8 – Game GUI
      Displaying Text in the Game
Sprite Text
DirectX Text
Adding Menus
Dialog Boxes
Text Boxes
Progress Bars
      Using the Game Console
      The Text Class
      Dialog Box Class
      Text Box Class
      Game GUI Class
      Console Class

Chapter 9 –  Enhancied Appearance
      Bitmap Scrolling
      Painters Algorithm
      Parallax Scrolling
      Shadows and Reflections
      Perspective Scaling
      Particle Emitter
      
Chapter 10 – Tiled Games
      Creating a Tile Set
      Using a Map Editor
      Displaying the Tiles
      Scrolling the Background
      Orthogonal Projection
      Oblique Projection
      Isometric Projection
      Isometric Terrain
      Height Maps
      Elevation Layers
      Creating a Map Editor in C#

Chapter 11 – Role Playing Games    {New Chapter}
      Character Rules
      Dialog Files
      Character Class
      Scripting
      Adding Scripting Support
      Controlling Characters with Scripts
      Testing and Debugging Scripts

Chapter 12 – Artifical Intelligence   {New Chapter}
Targeting
Avoidance
Flocking
Path Finding
A Star Implementation
Learning Behavior

Chapter 13 – Building a Complete Game
      Game States
      The State Class
      Adding a State Manager
      Saving and Loading Games
      A Complete Game

Chapter 14 – Network Programming
      IP networks
      TCP and UDP
      Client/Server Model
      Local Area Networks
      Internet
      Creating a Network Game

The final book may not follow this table exactly but give you an idea of what I have planned.

_________________
Professor Kelly


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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