Tuesday, November 29, 2011

Green Algae: Updates & Combat System

Health bar, obelisk,
summoning effect and monsters
Here are some recent screenshots of the Green Algae project. Progress so far is minimal as I was discovering how to use GLES20 for Android. Added a green health bar and summoning of enemies from the obelisks with a basic scaling circle for a summon effect so far. It's rudimentary but at least it is something. I used the same placeholder image for both the enemies and for the player avatar. So the avatar in the image is the one directly below the obelisk or the messed up wooden thing sticking out of the ground. I refined the map generation algorithm a little and put in sandy beach like outlines. Still have way too many trees there.

Accelerated Image Problem
I also fixed an issue with images not being accelerated, the problem being unknown but found when I got incredible choppy and low framerates after putting in the fullscreen switch. You can test if an image is accelerated like this
GraphicsConfiguration gc = GraphicsEnvironment
boolean isAcclerated = 
In order to get the images accelerated I simply switched them to being VolatileImages which did the trick but then it broke the fullscreen switching so I need to reload them when the switching to fullscreen exclusive mode, or use the fullscreen window and just scale everything to match the size without changing resolution.

Map Generation Changes
Map generation actively changes
as the map is being generated
Here is another screenshot, its the map generation preview which helped me debug a few oddities with the sand outlining piece and parameters. I have a bunch of primitive looking slide-bars that act as controls for how many islands and how large, long, and how much they vary when built. You can see my attempt at grass here and making it repeat well. Also my first attempt at an actual standing tree to align with the top-down style graphics, it needs work and a leafy version.

Combat System Snippet Work
So, after fiddling a little bit with trying to make the summoned monsters fight back I found that I am indeed in need of a combat system. So I started thinking about the design of it and what I wanted it to be able to handle. I have a few basic classes and interfaces put into a separate project so I can share it with all of you as a snippet. Currently the idea is to use the mediator design pattern having a CombatSystem class as the mediator to handle things like who swung first and what not, handle multiple Combatants (which are the Colleagues in the pattern). Asses damage and timing between attacks it seems like it will be a good way of handling combat and could potentially be used in a lot of different games. So hopefully have that working in a couple of days if I get time to work on it. Or it may have to wait till the weekend, my day job does get busy sometimes.

Other ideas
If anyone would like to share what types of systems they've used in the past for combat, I am sure people would find it very helpful. Thanks for reading, and if you have any suggestions for snippets or need help figuring out something that I may know how to do don't hesitate to ask in a comment.

Tuesday, November 22, 2011

A weekend with Android GLES20

So I spent most of the weekend porting my android game code from GL10 to GLES20 it's quite the endeavor especially if you've never worked with opengl shaders or matrices. Moving away from the matrix stack was about the hardest part. The shaders were easy to get a handle on all except for the texture passing bit since you don't actually bind the texture to a specific sampler it's done indirectly through the use of numbered textures and order of sampler definitions in the fragment shader.

I've worked with shaders before in a similar way with XNA so some of the concepts were familiar to me. The new part for me was getting a basic post-processing bloom shader to work. I got it now but apparently there are some techniques I have to research before I use it efficiently. But about the one thing that opengl offers that Java2D is without is additive blending which is extremely useful for a lot of great effects, of course you can create your own custom composite in Java for doing additive blending though performance might be an issue there.

But some of the things I learned in getting this to work are as follows,
  • One you need to setIdentity before filling in the transforms
  • You can use the Matrix.translateM, Matrix.rotateM, and Matrix.scaleM in sequence
  • If you want to translate for example from the last position in the matrix you need to multiply the matrix by the new translation matrix (problems with order of operations)
  • A problem I am still having is that of textures still appearing mirror or flipped and other such non-sense due to orientation issues.
  • Oh and you have to manage your own matrix stack, if you want to change coordinate systems to use local coordinates for a particular object.
I'll post examples and more details after the holidays.

Aside from that just getting ready for Turkey Day. Hope everyone has a good and thankful Thanksgiving!

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: