• Create Account

# KnolanCross

Member Since 29 Sep 2012
Offline Last Active Yesterday, 01:04 PM

Posted by on 04 December 2013 - 11:19 AM

2D or 3D? Free, paid, open source? Any language preference? Android only or do you need more platforms?

I believe the most popular engine around here is unity 3D (it supports 2D also). It has a free and a paid version, uses C#, js or boo and a pretty simple to use editor.

### #5113791SOLVED Asking for help for Efficient code/Fast to use, ideas/suggestions

Posted by on 02 December 2013 - 10:46 AM

2)

I used this formula in a python game, you will have to adapt it to c++, shouldn't be hard:

```def target(m, x, y, radius):
yMax = len(m) - 1
xMax = (len(m[0])) - 1
yMin = 0
xMin = 0

size = 1
for t in range(size):
xToTest = x + t - (size/2)
if ((xToTest >= xMin and xToTest <= xMax) and (upperYToTest >= yMin and upperYToTest <= yMax)):
m[upperYToTest][xToTest] = 'x'

if ((xToTest >= xMin and xToTest <= xMax) and (lowerYToTest >= yMin and lowerYToTest <= yMax)):
m[lowerYToTest][xToTest] = 'x'
else:
xToTest = x + t - (size/2)
if ((xToTest >= xMin and xToTest <= xMax) and (yToTest >= yMin and yToTest <= yMax)):
m[yToTest][xToTest] = 'x'

size += 2
```

m is a matrix that represented the tile map.

x is the x coord of the spell

y is the y coord of the spell

You can guess what radius is

### #5112773Advice to someone learning pathfinding?

Posted by on 28 November 2013 - 09:28 AM

All depends on how much performance/precision you need.

Notice that a pathfinding algorithm is one thing and navmesh is another entirely different thing.

The most popular pathfinding algorithm (and the fastest known) is A*, you may find a very detailed tutorial of how it works here:

A* algorithm is a little complicated, but you will be able to code it yourself without any major issue if you dedicate some time to it. You will also find it coded in a lot of places (my own blog has a C version of it). Most versions are not top optimized, but they may be fast enough for your needs.

About the navmesh, A* works on any graph and navmesh is just a graph very well known for being efficient in the representation of game spaces. It is also pretty complicated to create. There is an opensource program that creates navmeshes, its name is recast, you may find it here:

And a great study of how it works here:

You should keep in mind that you can use much simpler approachs, such as A* with a grid (which is a matrix telling where your character can move and where it can't). It is a very simple solution that may be fast enough for your needs.

Of your last question, depends on what AI/pathfinding you want to implement. If your AI is a monster that walk to a character, attacks and use a spell with 30% chance per second, and you want to use Heap optimized A* with navmeshs then yes, this will be the worst part. If you want your monster to adapt to 30 different character behaviors, analizing possibilities with heuristics and you plan to use a simple A* implementation with grids, then no, it won't be.

### #5112165Python sockets code give away, need opinions/reviews.

Posted by on 26 November 2013 - 09:50 AM

Hi there guys, latelly I have been busy as hell, but wanted to take some time to publish a simple code I created and helps me a lot when I want a quick way to send/receive binary data in a python server-client application.

Since sending binary information with python requires you to use the ctypes and the struct module, this can get a bit complicated. So I created this two helper classes, one is used to send information (Message) and the other is used to parse information (BufferHandler). The idea behind those codes are to provide a way that any python programmer can send/receive binary data with no knowledge of the struct and the ctypes module.

Warning: this is going to be a very large post.

Here are the codes:

First, the constants.py, that is used to keep the constant codes used by ctypes and their sizes.

```# constants.py
class FormatConstants:
UNSIGNED_SHORT_INT_CODE = 'H'
UNSIGNED_SHORT_INT_SIZE = 2
CHAR_CODE = 'c'
CHAR_SIZE = 1
SHORT_INT_CODE = 'h'
SHORT_INT_SIZE = 2
INT_CODE = 'i'
INT_SIZE = 4
UNSIGNED_INT_CODE = 'I'
UNSIGNED_INT_SIZE = 4
LONG_INT_CODE = 'l'
LONG_INT_SIZE = 4
UNSIGNED_LONG_INT_CODE = 'L'
UNSIGNED_LONG_INT_SIZE = 4
LONG_LONG_INT_CODE = 'q'
LONG_LONG_INT_SIZE = 8
UNSIGNED_LONG_LONG_INT_CODE = 'Q'
UNSIGNED_LONG_LONG_INT_SIZE = 8
FLOAT_CODE = 'f'
FLOAT_SIZE = 4
DOUBLE_CODE = 'd'
DOUBLE_SIZE = 8
STRING_CODE = 's'

```

Then the buffer handler, used to parse information received:

```# buffer_handler.py

from struct import unpack_from
from constants import FormatConstants
from ctypes import create_string_buffer

class BufferHandlerException(Exception):
pass

class BufferHandler:

def __init__(self, size):

self.currentBuffer = create_string_buffer(size)
self.originalBufferSize = size
self.currentBufferSize = size
self.currentBufferOffset = 0

def getBuffer(self):
self.currentBufferOffset = 0
self.currentBufferSize = self.originalBufferSize
return self.currentBuffer

def getOriginalSize(self):
return self.originalBufferSize

def setLimit(self, limit):
self.currentBufferSize = limit

def __checkValidity(self, size):
if (self.currentBuffer == None):
raise BufferHandlerException("Buffer is invalid.")

if (self.currentBufferOffset + size > self.currentBufferSize):
raise BufferHandlerException("Buffer is too small for the requested data.")

def __processBufferRequest(self, formatCode, formatSize):
self.__checkValidity(formatSize)
value = unpack_from(formatCode, self.currentBuffer, self.currentBufferOffset)
self.currentBufferOffset += formatSize
return value[0]

def getUnsignedShortInt(self):
return self.__processBufferRequest(FormatConstants.UNSIGNED_SHORT_INT_CODE,
FormatConstants.UNSIGNED_SHORT_INT_SIZE)

def getChar(self):
return self.__processBufferRequest(FormatConstants.CHAR_CODE,
FormatConstants.CHAR_SIZE)

def getShortInt (self):
return self.__processBufferRequest(FormatConstants.SHORT_INT_CODE,
FormatConstants.SHORT_INT_SIZE)

def getInt(self):
return self.__processBufferRequest(FormatConstants.INT_CODE,
FormatConstants.INT_SIZE)

def getUnsignedInt(self):
return self.__processBufferRequest(FormatConstants.UNSIGNED_INT_CODE,
FormatConstants.UNSIGNED_INT_SIZE)

def getLongInt(self):
return self.__processBufferRequest(FormatConstants.LONG_INT_CODE,
FormatConstants.LONG_INT_SIZE)

def getUnsignedLongInt(self):
return self.__processBufferRequest(FormatConstants.UNSIGNED_LONG_INT_CODE,
FormatConstants.UNSIGNED_LONG_INT_SIZE)

def getLongLongInt(self):
return self.__processBufferRequest(FormatConstants.LONG_LONG_INT_CODE,
FormatConstants.LONG_LONG_INT_SIZE)

def getUnsignedLongLongInt(self):
return self.__processBufferRequest(FormatConstants.UNSIGNED_LONG_LONG_INT_CODE,
FormatConstants.UNSIGNED_LONG_LONG_INT_SIZE)

def getFloat(self):
return self.__processBufferRequest(FormatConstants.FLOAT_CODE,
FormatConstants.FLOAT_SIZE)

def getDouble(self):
return self.__processBufferRequest(FormatConstants.DOUBLE_CODE,
FormatConstants.DOUBLE_SIZE)

def getString(self):
lenght = self.__processBufferRequest(FormatConstants.UNSIGNED_INT_CODE,
FormatConstants.UNSIGNED_INT_SIZE)

value = self.__processBufferRequest(str(lenght-1)+FormatConstants.STRING_CODE, lenght)

if (lenght != len(value)+1):
raise BufferHandlerException("String sent is invalid.")

return value

```

And finally the message.py, used to create messages that wll be sent.

```# message.py
from struct import pack_into
from ctypes import create_string_buffer
from constants import FormatConstants

class Message:
def __init__(self):
self.formatString = ""
self.bufferSize = []
self.valueList = []

self.formatString += typeCode
self.bufferSize.append(typeSize)
self.valueList.append(value)

def finish(self):
totalBufferSize = 0
for i in self.bufferSize:
totalBufferSize += i
buff =  create_string_buffer(totalBufferSize)
offset = 0
j = 0
for i in self.valueList:
if (self.formatString[j] == 's'):
w = 0
for k in i:
pack_into(self.formatString[j], buff, offset+w, k)
w+=1
else:
pack_into(self.formatString[j], buff, offset, i)
offset += self.bufferSize[j]
j+=1
return buff

FormatConstants.UNSIGNED_SHORT_INT_SIZE, value)

FormatConstants.CHAR_SIZE, value)

FormatConstants.SHORT_INT_SIZE, value)

FormatConstants.INT_SIZE, value)

FormatConstants.UNSIGNED_INT_SIZE, value)

FormatConstants.LONG_INT_SIZE, value)

FormatConstants.UNSIGNED_LONG_INT_SIZE, value)

FormatConstants.LONG_LONG_INT_SIZE, value)

FormatConstants.UNSIGNED_LONG_LONG_INT_SIZE, value)

FormatConstants.FLOAT_SIZE, value)

FormatConstants.DOUBLE_SIZE, value)

FormatConstants.UNSIGNED_INT_SIZE, len(value)+1)
len(value)+1, value)
```

I can post a whole example that I plan to release with this code when it is a final version, but I guess it would be far too much code in a single post. So I will use some very simple example.

Assuming we want to send an position update for our character via socket, it would be something like this:

```    x = character.getX()
y = character.getY()
message = Message()
mainSocket.send(message.finish())
```

Where:

Message is the Message class constructor.

addXXX are methods provided that will add the given variable as the type given. Here is a list of every method provided:

finish method creates the buffer via ctypes, fills it as the Message object was configured and returns the buffer.

The shortInt added is used as a message id for a protocol, it is used to tell the client that the message received is a position update and also used for the client to know what is the rest of the message. The other two floats are the (x,y) coords of the character.

To receive the data, the code would be something like this:

```    bufferHandler = BufferHandler(4096)
messageId = bufferHandler.getShortInt()
if (messageId == POSITION_UPDATE_ID):
x = bufferHandler.getFloat()
y = bufferHandler.getFloat()
character.setX(x)
character.setY(y)
```

Where:

BufferHandler is the class constructor, 4096 is the max length of the the buffer.

getBuffer returs the buffer created in with ctypes module, it will be used to receive the information.

getOriginalSize returs the max size of the buffer.

setLimit is used to parse the received data, if you ask for more information than this set limit, it will raise an exception.

getXXX are methods used to recover information, there is one version for each of the addXXX of the message class.

Well that is it, any feedback or suggestions are very welcome.

As always, you may use this code if you find it useful, but there are no waranties.

### #5108395How does a packet system work?

Posted by on 10 November 2013 - 09:21 PM

Well, that is pretty much how it goes. Recover the ID, parse the rest of the message as the id indicates, ALWAYS testing if the data is in the right format since a hacker can send fake packages.

Also, most packet protocols I have seen use binary information - not text - since it this will save a lot of CPU and bandwidth (think that you need to send a character position at 1578.4783892301 is a 4 bytes float/8 bytes double, but 16 bytes string), not to mention conversion problems.

### #5105056Sprite Sheets

Posted by on 28 October 2013 - 09:33 AM

There is a great full sets of a medieval fantasy city here.

http://www.lostgarden.com/search/label/free%20game%20graphics

The post is the one titled "More free game graphics"

http://www.lostgarden.com/files/2D%20Circle%20Graphic%20Archive.zip

I encorage you to check the site, there is great material and insights there (the site is not mine).

### #5096219Would this be a good idea? (Episodic release)

Posted by on 23 September 2013 - 12:41 PM

So,I should spend hours working on something to sell it for 1\$? That way I'm gonna get more by selling lemonade in the strret than this.

I'm gonna release it at 7\$,if someone buys it fine,if no one does,fine again.

Good luck selling a million lemodades with a single lemon. You need to realize that once your work is done, the number of copies you can do is infinite.

Also, people won't care about your situation or fair price when they are buying your game, they won't risk much money on a complete unknown release, it may not be fair, but that is how things work. I wouldn't pay 7\$ for a 1 hour content unless it was something I wanted to play really badly (such as a chrono trigger direct sequel).

### #5088478Which Gaming Engine/Level Editor Should I Go With?

Posted by on 23 August 2013 - 02:13 PM

I am going to do a 3D Adventure RPG for PC (Windows 7) by myself as my first game

Co-co-co-co-combo breaker.

On-topic:

I would go with unity, it is far more popular in the indie scene, so you are more likely to find more help. But you should probably start far smaller than a 3D RPG.

### #5082045Why do I get ridiculous floating point values when I read a binary file?

Posted by on 31 July 2013 - 04:03 PM

Something like this:

```    uint8_t array[sizeof(float)]

uint8_t reverseArray[sizeof(float)];
for (int i = 0; i < sizeof(float); ++i){
reverseArray[i] = array[sizeof(float)-i-1];
}

float* fp = reverseArray;
printf("%f\n", *fp);

```

### #5081961Help with 2d texture array for maps in XNA

Posted by on 31 July 2013 - 11:09 AM

for (int y = 0; y <= bound0; x++)

"Did you mean: y++ ?"

Posted by on 26 July 2013 - 12:26 PM

There are a few algorithms to determine your actions, I believe the most simple one is the minimax (https://en.wikipedia.org/wiki/Minimax).

Here is my five minutes explanation to give you the main idea of the way it works (probably not really good, but there are thousands of great articles on the internet about it).

First must define an evaluation function that given an army, determines one score for each strategy, this is probably a hard and subjetive task and pretty likely you will need to put a lot of twinking on it. For instance of points you can check to determine the score of an strategy:

- you can check how well defended are the airfields, the shipping and the factories.

- In case of a direct conflict how many resources you will lost and compare it with enemy loses, you may also include some factor for resource aquisition (for instance, I will lose more resources, but I have a lot remaining, while my enemy has nearly none, so this is good for me) and rate of production (I will take 2 minutes to recreate the lost unities, my enemy will take 4, so this is good for me).

After you got this function, you run it for the possible strategies for your army, then you check the counter mesures your enemy would take and run the function to those, and so on. In the end you will have a decision tree (look at the wikipedia article, this forum won't let me post in svg format). Now you pick the best result when it is your turn, and the worst when it is your enemy's turn (hence minimax). In the end you will filter the path of the best strategy. Keep running this algorithm from time to time to assert if you should keep your plan.

This is one of multiple ways, I believe it is the most simple one, and a good one because it will make your logic more organized (as you just need to twink the evaluation function), otherwise you may end up in an if-else hell.

### #5080445Terrain Collision and Bounding spheres?u

Posted by on 25 July 2013 - 07:50 AM

Thinking of the games I have coded as a hobbist, I have always handled this problem in two parts: first a way to keep the character on the ground and other that will avoid collisions with the world.

In my experience engines that support a height map can give you the height of a certein coordinate, so you wouldn't need any colision solid to know where the ground is. For static meshes I have always used a collision ray. An important side note: no matter which solution you choose, you must always check the angle between the point the character is and the one he is trying to move, this will avoid movement in very steep slopes (if the is trying to move from a lower to a higher point) and may trigger some short of fall (if the is trying to move from a higher point to a lower one).

To deal with the world collision I would use spheres rather than bounding box, since spheres are faster and more precise. If you have the option, you should use a capsule object (that is basically two spheres and a cilinder). I am assuming you are talking about the solid you will use on the characters, for objects I use whatever fits better (I try to go with spheres, but whan an object fits nearly perfectly inside a box, I use a box).

To sum things up, I would choose: Heigtmaps and capsules for collision. Finally, be sure to check Bullet library, that implements collisions in a simple and fast way (link: http://bulletphysics.org/wordpress/ )

### #5080202Game development, which path should i choose?

Posted by on 24 July 2013 - 01:22 PM

Mostly starting with something VERY simple is the way to go, try coding some pong or tic tac toe with some very simple library (pygame, sfml or even openGL) to get the feel of the game programming and learning the basic problems (rotations, scales, collisions and input handling).

After you master those, try some UI (which is way harder than most people realize) and sound. When you finished you will have learned a lot and probably will know what next steps you want to take (networking, pathfinding, tile map base game, some 3D coding, using other engines, so on).

### #5077967Emo framework for mobile games?

Posted by on 15 July 2013 - 03:28 PM

I do NOT intend to use game makers, because they are wrong. You should have to code your game and not have these "Easy Options".

If you are determined to avoid "easy options" on vague emotional notions of them being wrong, then you're going to have a bad time. Game development is hard and time consuming. My gut tells me that unless a developer is willing to cut a corner now and then, or go the easy route, she'll never see a project through to completion. Besides, how easy is too easy? Where's the line drawn? Personally, I don't think you're a real programmer unless you do it all in assembly. All these "programmers" using C or C++ to code are amateurs. I'm talking to you, John Carmack.

More seriously, I would encourage you to not to immediately discredit "easy options," because no matter how much easier a game maker is to use over straight-up coding, game development is still hard.

I can't speak to all of the options you've listed above, but I know something about a few of them:

Android SDK - It's only "hard to use" in that it is not a framework designed for game development. It provides access to the hardware and operating system services. Java code running against the SDK will be slower than well written C or C++ code, sometimes significantly. Carefully written Java can be fast on Dalvik (Android's Java VM), but it's not easy to do right. Just like in C or C++ you need to be very aware of how you're allocating memory in Java otherwise you'll have to deal with the garbage collector causing stutters in your framerate. I think this is why many iOS usually feels smoother than Android, but that's just a gut feeling. I have no evidence and don't have the inclination to look for some.

Kivy - Kivy is built on python and I think for anything beyond a simple game you will hit the performance wall.

MonoGame - You do not need to buy Xamarin studio to use MonoGame. MonoGame is free of cost to use. People are having success with MonoGame, but keep in mind you will have some of the same performance issues as you would if using the Android SDK. Mono runs on a virtual machine with a generational garbage collector. If you're not nice to it, it will bite you.

PyGame - Love pygame on the desktop, but, again, I think it would be too slow for anything but simple games. Also not very polished.

Dude, you realize that pygame's core is written on c++ right? Same is truth for most part of kivy (some of its classes are still use python).

I hardly see how its performance can be a problem on the logic of the game (it will be an incredible small performance lost if you consider the cost of rendering), and even if it is, use cython to optimize your code and you reach the C speed.

On topic, have you tried:

- orx, a C based engine that is portable to mobile. I like it a lot, it is oriented to loading your objects from ini files, so it is very easy to change your game attributes really fast. The link is: http://orx-project.org/

- playn, a java based framework that is made to be highly portable. I never used, but some friends of mine did and they like it a lot. The link: http://code.google.com/p/playn/

### #5077211Isometric map problem

Posted by on 12 July 2013 - 04:09 PM

Have you tried using objects of the same size? It seems to me that this is what is causing the problem.