Category Archives: A-Life

Collision Detection Insufficient

Delight of delights, I finally have a modern laptop. I’ve already gone ahead and moved most of my stuff onto here, and I have already got my previous work compiling and running. Great! That’s how I like things; working. I like myself working too, so I’m happy to be back at the cafe with my IDEs open.

Last time I worked on my programming, I added in the Animals to my little sandbox. They don’t DO anything yet, but they’re there. Little blue triangles.

I’m going to use a state-based sort of AI. Each critter will have a bunch of different behaviors wrapped in functions, and depending on what state they’re in, they’ll use different functions. It depends on their needs. These first ones will focus on eating, so they’ll have a hungry state, and a rest state. I’ll probably throw in a play state later.

So first off, I’m making the hungry state. When an animal is hungry, it’ll start using its senses to search for food. To simulate senses in this 2D world, I’m going to have the animals generate invisible shapes and see if those shapes collide with things. There’ll be a sight shape, which will be sort of like a cut-pie in the direction the creature is looking, and a scent shape, which will be a big circle. These guys will be pretty dumb to start. If they see food, they’ll move straight at it. If they smell food, they’ll move in it’s general direction. If they don’t see or smell food, they’ll keep wandering untill they do.

Using shapes like this for collision testing might be a bad idea. It’s easiest to test collisions with a square. Using a complex shape makes things a lot more processor intensive.

Hmm… On further investigation, it looks like HaxePunk entities can only have rectangular collision areas. Shoot.

*loads up the Entity code* Hmm… the collision detection is surprisingly simple. I could probably extend it myself to make shaped collision detection. I’m not sure if that’s a terribly good idea or not though. The more I work with HaxePunk, the more it feels like I’m pushing beyond it’s intended purpose.

Maybe I should do some research on how other people have solved this problem before. Or maybe I shouldn’t. It’s a tough call. They say that you shouldn’t worry about optimization at first, just make something that works, and then refine it afterwards. I could make a shaped collision system. Of course, I could also do the senses by other means than colliding with objects.

Yeah I think I’ll do research for a bit, see if I can dig up any ideas.

Hmm… Well, one thing I’ve learned is that apparently there’s a pollitical blog named Collision Detection. How about that?

Another interesting thing is that when you google Collision Detection, you mostly get linked to articles from the turn of the century.

Oh, here’s one from last year. Looks interesting. The math involved may require me to do further research, though. I’m lucky I’m able to figure out advanced math like this, even though I didn’t learn it in school. I wish I had, though.

http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/

This article assumes the reader has a basic grasp of mathematics and geometry he says. Matricies are not basic! EVER!

Well, it seems like it’s a good article anyways. I’m not done with it, but I need a break. Learning makes my anxiety peak.

Tagged , , ,

The Plants are Planting, and Synthesizing Food

Well, I’ve been working a bit more on the first a-life experiment. So far, I have some ugly scaling bitmap plants that grow over time. Some of them are overlapping the boundary of the sandbox though and I don’t want to have that, so I need to make them move away from it when they touch it. Also, future me, draw your graphics large and scale them down. I don’t know what I was thinking making little green dots and scaling them up like this…

A big problem I’ve got is that when the plant collides with the sandbox boundary, it doesn’t give me the location of the collision. It’ll give me the colliding entity, and if it was a regular entity I could extrapolate the collision based on its location and dimensions, but in this case I’m using a tilemap and it doesn’t give me the tile’s info, it gives me the TILEMAP’s coord, which is 0,0.

Oho! I have come up with an idea. It’s a bit dirty but if I make sure that, upon growth, the plant is at least 16px from the border, it won’t overlap!

… Not sure that’s a great idea.

Instead, I think I’ll just futz it, leave it as it is, and only spawn plants at least their maximum size away from the walls.

*work work work* Okay, looking good! The plants are functional, so it’s time to add the animals. To start with, I’ll be making a mobile herbivore that will eat the plants, mate, reproduce, and die of old age.

They’ll need to have a sense of some kind to tell what’s around them, what direction to go, and so on. I’m thinking I’ll give them a radial sense, since most herbivores have a wide range of vision. I might give them a sense of smell, too. Sight will give them the exact location of a thing if it’s in range, and smell will have a longer range and give them a general direction to go in.

I’ll start by making them sense food and eat it; I won’t do reproduction untill I at least have them moving around and finding food.

But, for now, it’s getting busy in the cafe, I’m getting tired, the sun is shining in my face, and I’m all done my food. I think I’m going to head home.

Tagged , ,

FD is Working Again

After the update, and a bit of confusion with a previous project with a similar name (but totally different location), I’ve found that FD is working again. My apps are running and connecting to the debugger properly. Hooray!

Now I can get back to actual work again.

The downside is that between the excitement of it seeming to fail but actually work and a really tenacious fly, I’m extremely overheated right now and don’t feel up to doing ANYTHING. Not sure what to do with myself now. I’m going to try and cool down by stepping outside for a bit, but I may make ‘fixing FD’ my whole thing for today.

Tagged

No FlashDevelop Replies

I didn’t get a single reply to my post on the Flash Develop forum. You know what that means?

UPDATE ALL THE THINGS!!!!

That’s about the only thing I can think of to solve it at this point. I’m updating FlashDevelop first, and if that doesn’t do it I’ll try Java and finally .NET. I’ll have to restart my lappy in between there so this is just a short in-progress post while I wait for the update on FlashDevelop, which is pretty slow on this machine at this location.

Tagged

FlashDevelop Troubles

Well I’m finally back to work after a long absense. It’s finally time to deal with the problem I had immediately before said absense; suddenly FlashDevelop stopped connecting to the debugger when it ran my project. Not sure what’s up with that.

So far, I’ve tried reinstalling the Flash Debug Player but that didn’t work.

Now I’m trying to use the debugger in other projects, but it’s getting even weirder. When I compiled and ran a different program, it didn’t even try to use the debugger. I edited it to use a flash trace but it didn’t work. So, it’s not just my other project, but this is even worse. At least in the main one, it’s visibly trying and failing to connect the debugger. This isn’t even saying anything is wrong. I double checked that it was in Debug mode since the first one I tried was in release mode, but it doesn’t make a difference.

Okay I tried an AS3 project and the debugger worked fine. Very puzzling.

My Haxe project still isn’t connecting to the debugger.

Alright I’ve tried a few more and it’s definately happening with all my Haxe projects.

Alright I’m going to try and install the mozilla style flash debugger as well and see if that does anything.

Oh, well this is interesting. Now the debugger is working, but the program isn’t, and it’s not giving any errors or compile errors. I just get the flash player with a white screen for all of my previously working programs.

And again it’s happening to all Haxe projects but not AS3 projects. They go fine.

Alright I’m going to take a break for the night and ask for help on the FlashDevelop forum.

Tagged , ,

The Sandbox

Okay work time is time for work.

Gonna make the background into a bunch of 16×16 squares instead of 32×32, and give them simple colours…

Huh, interesting, I had thought that shrinking them wouldn’t make a big difference since the graphics are simpler and it’s just re-using two bitmap stamps over and over, but the FPS with nothing in the scene has dropped by five. Well, that’s partly ’cause my laptop isn’t very good, but I also realized that the grid is also being used for collision tests, so there is more overhead than I had thought at first.

I’ll leave it like this for now, though there shouldn’t be many collisions with the tilemap outside of the border, so maybe I’ll switch it with something else later.

Now, I’m going to add in arrow key control for the viewpoint, since I can only see part of the scene right now.

*work work work* Okay, now I can move my viewpoint about the scene as I please.

Now for the logic of life, I think.

The plants will spawn at a very small size and slowly be scaled up as their food value increases, simulating photosynthesis. At this stage, they’ll be static things. I’ll sprinkle them in randomly, and they’ll grow slowly over time.

The animals will just be herbivores for now. I’m not sure if I should code in senses at this stage; should they be omnicient and automatically head towards the best plant, or use senses to try to find a plant that is big enough to eat while wandering around pseudo-randomly?

Now that I think about it, I don’t really know much about how microbes do their stuff. Do they have senses? Do they just squiggle around pseudo-randomly untill they blunder into success or failure? Let’s look it up…

*looks it up*

Huh, well it looks like microbes are like bears; they can smell you from SO FAR AWAY!!!! Or at least, relative to scale. They have incredibly powerful senses and can detect something like a sugar molecule from pretty far away, if I’m understanding this article right. http://biosingularity.com/2006/06/04/how-bacteria-sense-their-environments/

So for my simulation it might actually make sense to have the little animals be omnicient at this stage. Of course, I’m not coding this to simulate microbes, so maybe I should just knuckle down and do the senses now.

For now I’m thinking that they’ll drop an invisible ‘area of effect’ entity that will pass its collisions back to the parent. If it detects a food source, it’ll head towards it and chow down. Otherwise it’ll wiggle around pseudo-randomly. Eventually I’d like to use different AoEs for sight, sound, and smell. Hopefully it won’t bog down the simulation too much, but figuring out stuff like that is part of why I’m doing this.

It’s noon now, so I think I’m done for the day. Next time I’ll have to try and code the plants.

Tagged , , ,

Plants and Animals

So here I am, at the cafe again. It’s been a while; this last month has been terrible for me overall.

I’ve decided to push the textworld project to the back burner. I kept changing my goals on that project and ultimately realized I wasn’t working towards any of them anymore. Instead I’m going to focus on my artificial life experiments for a while, in preparation for my return to college this fall.

As before, I intend to do these a-life experiments using HaXe and HaxePunk, but those various libraries were updated even while I was using them, so I’m going to have to start by updating all my libraries.

*work work work* Well that took an hour. Ahh well life goes on, and now my libraries are all updatified.

Hmm… Now that I’ve opened all the references, I’m feeling really anxious and somewhat disturbed. I think I’ll have to take it slowly and refresh myself on the workings of HaxePunk.

*work work work* Okay after some difficulty I am successfully back where I left off before, and prepared to make a HaxePunk app thingy.

The first thing I’ll do is the most basic sort of a-life. I’ll make little green circles to be ‘plants’ and have them grow slowly, and little blue triangles to be ‘herbivores’ that will seek out the plants for food. I’ll make the herbivores reproduce asexually for now, when they have enough food, and die if they starve. I might have them die of old age later.

First things first. Gotta set up the ‘world’. This’ll be a bordered box for the critters to live in.

Anxiety is peaking really hard right now. Really want to run home and hide, but such is life. I’m staying.

Made a world, working on Plant and Animal entities to populate it…

Okay I’ve got some of the basics set up. But, I still need to make a bounded space in the World, right now I think it goes on forever.

*work work work* Alright I’ve put in a temporary field for my sandbox, it’s basically the box I made for my last HaxePunk experiment, with the zelda style tiles. I’ll probably switch it out with just a black outline later, and make it bigger. For now, I’m out of time. I have work to do today, and it’s finally almost 9:30.

Tagged , , ,

Figuring Out HaxePunk

Well, I’m trying to learn HaxePunk, which is a HaXe port of FlashPunk, but both are lacking something important. Good overview. Even pouring over the documentation doesn’t give me a good idea of what everything is and how they fit together. I’m able to figure out some things via the tutorials, and so I’m going to try to piece together the workings of FlashPunk and HaxePunk. I’m also going to check out the source, and see if I can’t figure out something from that.

At any rate this gives me something to do while I try to brute force my way into the Diablo III Open Beta. I’m not sure if Blizzard is failing their stress test, or if they’re intentionally using less than their capacity to see what happens when stuff goes wrong.

So, HaxePunk. The basic thing for HaxePunk is the Engine class. When you make a HaxePunk project you make your main class extend the Engine class, and override the Engine class’s methods to add functionality. You give the constructor the details about screen size and frame rate, and it’s basically a sprite on the stage for you Flashers.

You override the init method of the Engine class and that runs once when the program starts. That initializes the game for you. Then there’s update, which updates the active world, and render, which draws everything to the screen, each every frame.

Then there’s HXP, which is a mix of constants and references to important data across the various classes. When you set which world is currently active, you set it through HXP.

The next most important class is World. Your game takes place in one or more World instances. You set a world to the HXP.world. A world contains entities, which are physical objects that do things in the game. Those entities have a graphics property which can be one of several different graphic type classes. An Entity also has an update method you can override, and various methods for collisions and things.

That much I was able to glean from the tutorials and such. But there’s other stuff in there.

The World class has layer variables. I would guess so that you could have multiple layers of background and foreground sprites, without having them collide. Or for doing paralax scrolling. That sort of thing.

The code in the libraries spaghettis a lot, especially due to the HXP class. I think I’ll need to actually try a lot of these elements out to see what they do. For that, I need to set up an experiment game.

*work work work* Well so far I’ve made an area with a tilemap of floor and barrier tiles LoZ style, and a little red box to be the ‘player’, and the camera follows the player, and the player moves in response to the arrow keys. I also put a pair of parallax scrolling textures in the background, and they’re very neat and hypnotic. It’s a couple of repeating textures using the “Backdrop” class; it’s a graphical class made for non-interactive looping background images.

Next I’ve got to set up some collision stuff.

*work work work work work* Alright! I managed to figure out the built-in movement-collision system. Now I need to take a break.

*takes a break* At this point I should probably mention that unlike my other blog entries, this one is being written over the course of several days. I think this is the fourth time I’ve opened it up and started writing. Usually I close it down when I’m done for the day and post it, but instead I’ve just been adding to it as I go.

I’ve got my little test game going now, but another thing I’m doing is commenting on all of the classes. I’ve got a little folder and I’m slowly filling it up with .txt files named after each of the HaxePunk classes. I’m going to try and figure out what each of them does, and piece together the full intent of the HaxePunk/FlashPunk system. I really have no idea why something like this isn’t already in the API or the documentation anywhere, but so far the code itself hasn’t been _too_ difficult to figure out, once I open the source.

One more thing I’ve been able to figure out is that the entire Masks namespace is full of collision masks. Masks is kind of a vague name, but all the masks are used for collision. They get popped into an Entity’s mask property and compared against for collision.

That leaves the last big mystery, the tweens.

*work work work* Okay before I dive into the tweens I decided to dive into the render loop. I wanted to know how the game works on that end. It seems that it has two bitmaps, and it draws to one in the background using copypixels, and then does a page flip to make a buffer. That’s how I was considering making one, so that’s great, saves me the work. The worry/concern/question I have though is this: Is it neccesary to have two drawing surfaces? I would imagine that Flash/NME handle clipping and page buffers in their own rendering. Maybe it is neccesary. I’m not sure.

Anyways it works, so that’s good enough for me right now.

Now let’s see if I can figure out what these tweens are. I know that in animation, a tween consists of the frames between key frames. In particular in Flash animation, tweens are automatically generated animations based on the differences between one vector image and another. They’re kind of infamous for being terrible, though they’re effective. I studied them a bit in college, and I think if you do them right they don’t have to look terrible, but I’m not much of an animator…

Anyways, near as I can tell there are two classes that subclass the Tweener class, world and entity. The Tweener class lets you apply tweens, which are defined in three different namespaces. So, I should be able to apply a tween to an entity or the world, to see what it does.

To have a clearer idea, I’m going to add another entity into the world.

*work work work* I added a test pattern object, I’m going to try putting tweens in there first to see what they do.

… I’ve just tried the Alarm tween. It didn’t seem to do anything, so I went into the code. I think it’s just a glorified timer. You can supply a callback function when the tween is done, so this one just gives you the callback after the timer is up.

Hmm… The AngleTween is definately SUPPOSED to do something, but I’m having trouble making it actually do something. I’m pretty tired now, though, so I’m going to try to sleep.

I’m going to post this as an entry today, around a week after I last updated it. I’ve been too busy on a different project and now I’m going to work on TextWorld for a while, so I want this up for when I decide to work on HaxePunk some more.

Tagged ,

HaXePunk is Coming Under Control

Well, it’s taken a lot of finageling and futzing but I’ve managed to get HaxePunk to operate with FlashDevelop the way I wanted it to. Code completion works, lookups work, and pressing the test button tests the app. Huzzahulations!

Now to actually learn how to use HaXePunk and see how it goes. The framerate isn’t great on my dinosaur laptop to begin with, when it’s not doing anything besides reporting its status. I wonder what will happen when I make it DO things?

Well, first things first. I’m going to go through the FlashPunk tutorials, since HaxePunk is based on FlashPunk and for whatever reason they haven’t just copied the tutorials.

*work work work work work*

Wow I did a lot of work and didn’t have much to say. It’s getting late and cold though, so I think I’m going to head home. FlashPunk is coming along, though there’s still a bit to learn. If I get the pixels dancing by tomorrow night then I might give Ludum Dare a try this weekend. Wish me luck!

Tagged , ,

A Beginning for A-Life

Today I don’t feel like working with text, but I can’t relax and play, so I’ve got to work on something else. So, I’m going to start doing the other option of the two I started with, when I started the text game. I’m going to start doing some A-Life experiments.

So, I’m going to keep on using HaXe and target Flash, so I’ll basically be making a flash app in HaXe. It seems like a decent language, especially for Flash development, and I can re-use code from it pretty easily.

First I’m going to do some experiments with how I want to render this. I might use a library, there’s a bunch of them out there. This HaXePunk looks good; it’s a HaXe port of FlashPunk. There’s one of Flixel too but it doesn’t look as good.

Hmm, they both need something called NME, which is related to HaXe…

It looks like NME is an extension API for HaXe which makes it even easier to do multiplatform programming.

Let’s try this NME out… *downloads an example, compiles, builds, runs* Yeah that works. I love it when things work.

*read read* Oh I see, NME basically has an interface like Flash, but you can target to other platforms with the same code. So, you can code the interface with HaXe instead of doing a different interface for each platform. That’s cool.

I’m taking a long time messing around with Libraries, I haven’t even touched the A-Life experiments I was going to start. Maybe I won’t get to them today, we’ll see. I’ll have to eat soon.

*read read read* awe6 seems good too, though. I should check them out later. FlashPunk seems more familiar, for now. It’s interesting and noteworthy that the same game on Flash and JavaScript/HTML5 is much faster for me in Flash. I guess JS/HTML5 has a ways to go yet.

I haven’t done much besides decide which library I’m going to use, but now it’s time for meal and break. I’m sure there will be interesting things coming up!

Tagged , , , ,