Tag 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 , ,

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 , , ,

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 , , , ,