Wednesday, November 16, 2011

Green Algae Project

Yeah weird name I know. But it's good to have a non-restrictive name for a project that doesn't really make you think of anything specific. It helps you move in different directions without thinking about the title of the game. Although I have a work-in-progress game title, but I don't know if it will fit the game exactly after I change the game a bit.

So yes the game! The initial idea was centered around building bridges out to sea. Though one just can't build bridges for the hell of it (or can one, I wonder, hmmm) Any way it was decided that they cannot but the reason for building the bridges is indeed an odd one to be sure. And the reason would be, of course, sea monster hunting. Yeah well sea monsters are kind of cool. Think giant sun fish, man size and above, that can walk on land and rip your precious bridges and you to shreds.

You don't just build bridges, oh no, there's more to build like buildings a bunch of them. You can build well you can build yourself a hut to place your rare fish trophies in collect them all and get to the bottom of this nasty fish evil that's plaguing the island inhabitants. Oh yeah did I mention that there are islands yeah lots of them or as many as you like. The random map generation was of course on of the first things I got working. It's not bad, and by not bad I mean I wouldn't release a game with it but if it came down to it. It wouldn't be horrible. 

Currently only three types of tiles, you get sand, and um water, and of course grass. The terrain generation is random and controlled by a few parameters at the moment island count, size, length, and a extra variance value I used to vary some of the random chances and things. I will make an additional post about the generation method later so you can see one way of doing it.

So the project I figured is for my own personal enjoyment so it's more like a test bed I can work with to implement gameplay mechanics and test out effects and other things. So in order to get working on the combat system I thought I'd add in the ability to summon monsters. You place a wooden obelisk yeah weird but anyway this is of course after chopping down the tree and dragging the fallen log to where you want it. Then you start summon after a little while monsters will appear for you to fight. And right now it's pretty much you just go up to them attack them then they die, you get experience which you can't see atm, that's easily shown take me like 5 minutes.

So yeah that's The Green Algae project. A nice test project that could potentially have some interesting gameplay. Those green things are trees by the way. And that would be a boring old wood pile and a test avatar sprite placing wood in the pile.

So hang on to the edge of your seats for some spectacular updates.

Wednesday, November 2, 2011

Mouse Movement by Dragging

So I forgot to post this one type of movement piece. It's pretty simple if you know how to do the math which I will show you. Like the other snippets it's not entirely polished so there is definitely improvements that can be made to the movement style. This snippet will do a simple move towards the cursor when the mouse is dragged.

Other ways to do mouse movement is point-and-click movement. Point-and-click movement usually works along side a good pathfinding algorithm using either tiles or nodes. So here's the meat of this snippet.
  // only move if the user is dragging the mouse and we aren't already
  // at the mouse position
  if (dragging && !isMouseOverBlock()) {
   // the amount to move the character in x and y directions
   double dx = 0.0d;
   double dy = 0.0d;

   // relative mouse position from the character
   double relativeMouseX = mouseX - basicBlock.x;
   double relativeMouseY = mouseY - basicBlock.y;

   // determine the angle the mouse is from the current position
   double angle = Math.atan2(relativeMouseY, relativeMouseX);

   // now determine based on the angle what direction to move in
   dx = Math.cos(angle);
   dy = Math.sin(angle);

   /*
    * move the block by multiplying the amount of time in seconds that
    * has passed since the last update by the speed constant and by the
    * change in x or y directions which will either will result in += 0
    * or dt * speed negative or positive.
    */
   basicBlock.x += dt * speed * dx;
   basicBlock.y += dt * speed * dy;   
  }
So one of the tricks here is knowing how to use the atan2 method. It gives you the angle for the Cartesian points x,y passed to the function using the arctan trig function. Once we have the angle it's a simple matter to move in that direction based on speed and time. You can think of the dx and dy as percentages of the speed to apply and the dt as the amount of time applied.

Some ehancements that could be made to this snippet are things like using acceleration instead of pure speed. You could use this snippet to experiment with different styles of mouse movement such as the point and click and other variations as per your gameplay.

There is also a little bug I noticed in this example, sometimes when moving the block if it is over the mouse cursor it will sometimes jump quickly back and forth around the cursor. I tried to fix it by using the isMouseOverBlock but it wasn't 100% successful. If you figure it out please let me know.
Here's the full snippet: