Tag Archives: haxepunk

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