Chadwyk.com

The ramblings of a developer

Bleh…

So it’s been a long time without an update.  For a while there I was working a side job at work which sucked up my free time, then I kind of just lost interest. Then next thing I knew I let me website hosting expire, and my Apple account expire.  I just now got my websites back up finally, but at this moment Lumps of Clay on the iOS App Store is still down.  I’m unsure if I’m going to bring it back.  It never saw too many downloads.  In order to get it back on the store, I may need to recompile it since it’s been so long, but the engine it is written in, is no longer supported so I may run into issues.  I’ve thought about porting it to another engine, but then I think “why should I do that unless I port it to other platforms”.  Bringing it to Switch might be cool.  But I also never got very far on my other project, which would have been a point and click adventure.  I’d almost rather see that through than revisit an old game.  I’ve kind of had more interest again to start that up again, so maybe I’ll do that.

Simple Stupid Funnel Algorithm

It has been a long time since I posted anything or really worked on this project.  I finally got some motivation and decided to tackle a couple of the hard issues that I was facing and wasn’t sure the best way how to handle.

First up, clicking outside of walk boxes.  What should happen? Where should the player move? I went through lots of experimentation to find the best results.  Finally I made an algorithm to expand a + out from the click point to see if it hit any walk boxes.  If it does, then that is the spot the player walks to.  If not, then it means it is in a diagonal and I need to find the closest walk box vertices to the click point, and have the player walk to that position.

That was difficult but I was able to handle it with relative ease.  The second issue was that I had the player walking the path to a click point, but he would move to the center point of each walk box as he walked through them. This lead to a very unnatural look.

When I originally made the code for walk box path finding, I remembered that Julian Ceipek wrote about something called the Simple Stupid Funnel Algorithm. http://jceipek.com/Olin-Coding-Tutorials/pathing.html#funnel-algorithm This algorithm finds a more direct route for the player to walk, and it looks a lot better.  I followed this article that he linked to by Digesting Duck which gives a very excellent explanation of how it works. http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html

However, much of his code was hard to follow and in psuedo code.  Luckily in the comments I found someone used his code in a javascript example and posted it on pastebin.  http://pastebin.com/7jwrmw1i

It actually probably only took me a couple hours to port the code to c++.  The hard part was to figure out all the “portal points” along the walking path.  This means basically finding all the vertices of the edges the player walks through. Also not a horribly difficult task.

What was hard, is that I needed to keep track of the point orientation as the player walked the path.  This was crazy hard for me to figure out the best way to do it.  You could not just say, if the player goes left, the left vertices is the bottom one and the right is the top.  That might work for some shaped walk boxes, but others it wouldn’t, especially if the angle you were walking into it was a diagonal.

The solution I finally came up with was to find the orientation of the segment. If it was mostly vertical, or mostly horizontal. Then I got the direction the player was moving in. Based on that I made the following conclusions which seem to work.

If the segment was vertical and player moving right, then left = upper vertices, right = lower.

If the segment was vertical and player moving left, then left = lower vertices, right = upper.

If the segment was horizontal and player moving up, then left = left vertices, right = right.

If the segment was horizontal and player moving down, then left = right vertices, right = left.

So now after tweaking my code to move the player along the path via the center points of each walk box, the player walks a smooth line to the click point!

The final step in the process is Steering.  I’m unsure if I’m going to do this or not.  I don’t think my walk box paths are going to be that big and it looks pretty good as is.  For example, if a player is walking around a turn, he will make a 0-point turn.  You could use steering to tell the character to generally stay within a range of the path I made with the Simple Stupid Funnel and steer back to it if they get off track. If I implement this, I’ll have to do some more research into the best way to implement it.

Now for a demo!

I was Hacked!!!

&%@# You Hackers!

Ugh… today was a pain… I woke up and found an email that eBay locked my account because someone hacked my password.  Turns out I think I used that same password on lumpsofclay.com… no good….

I also got an email that some random email address got set as an “Owner” for lumpsofclay.com. They hacked the site and since they had access to the server, where all my sites live, they messed up almost all of them. They hijacked them with malicious code and had google re-index my sites, so now crazy links pop up when you search for them.

 

Lame… I spent a good chunk of the day on chat with my hosting company.  Luckily they were able to restore everything from backups.  I then promptly changed all the passwords for website accounts, databases, and other websites that may have used any of those passwords that got hacked.  I also updated WordPress and all plugins incase that was the attack vector, but I think it was an old password that may have been listed on some hacker sites from other websites getting hacked.

 

Bleh… I know I should never of done it, but it was easy to use the same password for multiple sites.  But no more!  No more using the same password for multiple sites! I’m going to start using password manager software!

 

It could have been worse… they could have got banking passwords (which were all different already).

Changing direction to Cocos2d-x

So I know I was really excited to create my own engine from scratch, but I fear at this point in time it is just way too far over my head.  I’ve spent the last several days trying to get SDL or OpenGL to load and display images, with limited success. Once I get an image loaded, I’m unable to really abstract it into a class to load multiple instances.  If I was able to, it wouldn’t be very efficient either because I’d need to figure out how to do texture atlases and texture batching, as well figure a way to manage the textures in memory.  It’s all really complex to someone that hasn’t touched c++ in a long time.

 

At the moment I feel fairly defeated, so instead, for now, since someone has already done all the hard work, I think I’m going abandon my engine attempt and try out Cocos2d-x instead.  It is a C++ version of the Cocos2d-iphone engine which I used to make Lumps of Clay.  It should be fairly similar I think.  Since Cocos2d-x is written in C++ it is cross platform compatible, and I believe the renderer uses OpenGL at the core, but it’s super easy to load images as Cocos2d-x does all the hard work for you .  I just don’t know how compatible it will be if I ever want to port it to devices like the Nintendo Switch. But if the Switch will be incompatible with Cocos2d-x, it would probably be incompatible with my custom engine since they were both going to be OpenGL based.

 

Maybe I’ll try to make a simple game with it, then send my pitch to Nintendo so I can get a Developer Kit, then see how hard it would be to port it.  We’ll see.  For now, I’m going to abandon my own engine and try to get a prototype going this weekend in Cocos2d-x.

 

In the future I can always revisit my own engine project.

 

UPDATE

I hopped on the forum for cocos2d-x and there is a thread about supporting the Switch since it was revealed that the Switch supports OpenGL.  It appears that at least one developer was able to port their game to the Switch from cocos2d-x, so that is good news!  There was not any posts lately on it so I left one asking if anyone else had been able to port to Switch.  Hoping to hear back some positive results!

Early Roadblock

So… It turns out, loading graphics is hard!

 

My goal is to be able to make a basic texture loader class that I can use on any node class in my engine.  This is kind of how Cocos2d-iPhone worked, in a simplified manner.  If I could only find one that was already created someplace that I could utilize…

I was able to get SDL to load images, though it was pretty complicated, and not optimized what-so-ever yet.  Plus if I go this route, I can’t use cool lighting effects.

I think my preferred route is to use OpenGL for that purpose.  However, I started playing with OpenGL and that’s waaaay harder then using SDL.  Though there are some image libraries that are supposed to make it easier.  I am currently trying one called SOIL, but I can’t find much documentation on it at all and the last time it was updated was years ago.  I might look at trying out a different one and seeing if I can get it working with OpenGL.