Lachlan's misadventures in games programming

Showing posts with label Platform. Show all posts
Showing posts with label Platform. Show all posts

Saturday, 15 October 2011

Jack is a Fool - Potential use for platform engine

10/15/2011 01:13:00 am Posted by Lachlan , No comments

I've started toying with an idea to use with the Platform Engine. It's called 'Jack is a Fool'.

In Jack is a Fool, you won't control Jack directly at all. Instead, you'll control the machinery around him, to try to successfully get him to the exit. Think something along the lines of lemmings, where you control floating platforms to stop Jack falling in holes, and move doors around to get him through mazes. It will be almost a pure puzzle game - that happens to be with a guy who walks on platforms.

I've started doing some design drawings of levels etc. to figure out how viable this idea is in LibreOffice Draw. So far, I've designed 2 basic non interactive 'levels' (which will be a grand total of being a more entertaining way to write 'Nerdy Gentleman Games Presents' and on the next one 'Jack is a Fool' while introducing the basic start of gameplay). I've designed 1 basic level to demonstrate the moving mechanic.

I've finally so far designed 2 actual puzzles - I don't count the others as puzzles at all. The first involves moving lift doors and a lift to get Jack to the top of the level, and the second moving a series of platforms to get Jack to the other side without crushing him, or allowing him to fall off. Both are just design ideas, and as such don't look like what actual gameplay would. For your benefit, they're included below.
First fully designed level
Second fully designed level
I've got ideas for a couple of other mechanics I could add for puzzles, and a couple of unfleshed ideas I could use for the mechanics already introduced. I want to get to somewhere between 10 and 20 puzzles (probably closer to 10) before focussing on implementing the features they need, and seeing if gameplay is fun. If it is, I may more fully finish the game. If I can't figure out interesting puzzles, I won't bother.


Lachlan

Saturday, 8 October 2011

Platform Progress - Saving and loading levels

10/08/2011 05:45:00 pm Posted by Lachlan No comments
Wow... 3 posts in one day!? But - achievements get posts.

I can now save and load levels! So:
 gameexec
FatController bind_wing_keys K_LEFT "Actor inst 100" K_RIGHT "Actor inst 101" "Actor inst 102"
FatController bind_key_down K_SPACE "Actor inst 103"
FatController bind_key_up K_SPACE "Actor inst 104"
FatController bind_key_down K_ESCAPE "Game quit_signal"
FatController bind_key_down K_BACKQUOTE "Game toggle_console"
FatController bind_key_down K_e "Game toggle_editor"

run "level" "levels"

Game gravity_ddy = 400;
Game gravity_max_dy = 500;
Game gravity_ddx = 0;
Game gravity_max_dx = 0;

and

 level


Game new_feature "f_1" 
x1 = -20
x2 = 600
y1 = 500
y2 = 550
z = 0
collision_function = 1
visible = 1
.

Game new_feature "f_2" "f_1"
x1 = 150
x2 = 200
y1 = 450
y2 = 500
z = 0
collision_function = 1
visible = 1
.

Game new_feature "f_3" "f_1"
x1 = 700
x2 = 1500
y1 = 500
y2 = 550
z = 0
collision_function = 1
visible = 1
.

Game new_feature "f_4" "f_1"
x1 = 900
x2 = 950
y1 = 400
y2 = 500
z = 0
collision_function = 1
visible = 1
.

Game new_feature "f_5" "f_1"
x1 = 500
x2 = 800
y1 = 350
y2 = 400
z = 0
collision_function = 1
visible = 1
.

lead to an end result of:

Note - as well, this script is the actual save file, and was saved from within the game! Boo yeah!

Platform Progress - Scripts Ahoy!

10/08/2011 12:12:00 pm Posted by Lachlan No comments

I've started the process of being able to load scripts from files and (am working towards at the moment), saving them to files. As of Thursday, it loads (most of) the keyboard configuration from a script file. This script file, actually:

FatController bind_wing_keys K_LEFT "Actor inst 100" K_RIGHT "Actor inst 101" "Actor inst 102"
FatController bind_key_down K_SPACE "Actor inst 103"
FatController bind_key_up K_SPACE "Actor inst 104"
FatController bind_key_down K_ESCAPE "Game quit_signal"
FatController bind_key_down K_BACKQUOTE "Game toggle_console"
FatController bind_key_down K_e "Game toggle_editor"

This is important for a couple of reasons. The primary one is that levels are to be saved as a script which contains instructions on building levels - I've got recipe's being generated already, now I'm ensuring that I can save them.

The first step of this project was adjusting the PuppetMaster's Process Command thing to take multiple commands by splitting it by newlines and semicolons (though, in the case of the latter, providing that they're not within double-quote marks). I decided to use the same method I have for actually processing commands -  using an overly complex RegEx command that I barely understand, as processed by boost::regex.  The RegEx function I ended up using is:
"(\\.|[^\"])*\"|[^\n;]+

The sad thing is, I'm not entirely certain how this works except it does when I run it through "The RegEx Coach" (excellent piece of software btw). In reality though, RegEx seems to me to be a return to the archaic language of APL (see Wikipedia to see why I make this comparison). It's an ol' APL proverb that:
'Tis every programmers goal in life
Before his race is run
To write three lines of APL
And make the damned thing run!'

Wednesday, 28 September 2011

Platform Progress - Collision Detection Sucks

9/28/2011 03:27:00 pm Posted by Lachlan , No comments
Those red boxes? The things you can collide with. The white box?  You. Simple looking I know - but slowly getting there
I've been wrestling with collision detection quite extensively over the last week and a bit (and a bit more). I've had varying things working, but they either partially work by colliding well and not necessarily putting the actor back quite where it needs to go, or getting stuck in walls, and generally not being able to register as a collision when they're just touching - or freezing the box if it could.

I've ended up using a simplified case of the technique in http://www.metanetsoftware.com/technique/tutorialA.html - it's the one they use for 'N'. If I end up adding ramps or anything I may have to do it in more detail, but it seems to work. However, the code wasn't liberal enough in detection of collision where the platform and actor are just touching - without overlap. So, I've added a simple, more liberal check at the end. Code is below, if it's your sort of thing or you need help doing something similar.


  1 void Feature::TotalCollision(Actor* actor, float dt)
  2     //Method described in this... partially
  3     //http://www.metanetsoftware.com/technique/tutorialA.html#section5
  4 {
  5     //These shouldn't be using typecast x1() but instead x - w/2 or something - Maybe
  6     //This may change if features start being defined by x, w, y & h rather then
  7     //w and h being calculated and the feature being defined by (x1, y1) and (x2, y2).
  8     float left_a = actor->x() - (actor->w() / 2);
  9     float left_f = (float)x1();
 10     float right_a = actor->x() + (actor->w() / 2);
 11     float right_f = (float)x2();
 12     float top_a = actor->y() - (actor->h() / 2);
 13     float top_f = (float)y1();
 14     float bottom_a = actor->y() + (actor->h() / 2);
 15     float bottom_f = (float)y2();
 16     float midx_f = (left_f + right_f) / 2;
 17     float midy_f = (top_f + bottom_f) / 2;
 18
 19     //bool colliding = Collides(left_a, right_a, top_a, bottom_a, left_f, right_f, top_f, bottom_f);
 20
 21     bool colliding = true;
 22             
 23     if (bottom_a <= top_f) { colliding = false; };
 24     if (top_a >= bottom_f) { colliding = false; };
 25     if (right_a <= left_f) { colliding = false; };
 26     if (left_a >= right_f) { colliding = false; };
 27
 28
 29     if (colliding)
 30     {
 31         float x_overlap = (actor->x() > midx_f) ? left_a - right_f : right_a - left_f;
 32         float y_overlap = (actor->y() > midy_f) ? top_a - bottom_f : bottom_a - top_f;
 33         if (std::abs(x_overlap) > std::abs(y_overlap))
 34         {
 35             actor->set_y(actor->y() - y_overlap);    
 36             actor->set_dy(0);        
 37             actor->set_v_collided (true);
 38         }
 39         else
 40         {
 41             actor->set_x(actor->x() - x_overlap);
 42             actor->set_dx(0);        
 43             actor->set_h_collided (true);
 44         }        
 45     }
 46
 47     //These fill the special case uncovered by the above where there needs to be a collision
 48     //for whether or not we can jump or not, but the code doesn't need to move the actor
 49     if
 50     (
 51         ((bottom_a == top_f) || (bottom_f == top_a)) &&
 52         !((left_a > right_f) || (right_a < left_f))
 53     ) 
 54     {
 55         actor->set_v_collided(true) ;
 56     } ;
 57
 58     if
 59     (
 60         ((right_a == left_f) || (right_f == left_a)) &&
 61         !((top_a > bottom_f) || (bottom_a < top_f))
 62     ) 
 63     {
 64         actor->set_h_collided(true) ;
 65     } ;
 66
 67 }



By the way - if any of you know a good, easy way to highlight code for blogs - preferably an online utility, I'd really appreciate knowing it.



Lachlan

Monday, 18 July 2011

Platform Progress - Consoles

7/18/2011 01:56:00 pm Posted by Lachlan , , No comments

I've spent the last few days getting the console up and running. And it does.

Thus far, it can now access and manipulate things in classes which are exposed to it. For instance, the Game class is exposed to the 'Puppetmaster' (as I've dubbed it). If I load the console (Quake 1 style - by pushing ~), I can check what the cameras x value is by typing
Game camera_x
which will then return something along the lines of
45
I can also set camera_x in much the same way
Game camera_x = 30
This is advantageous because it is laying the foundation for me to be able to change the game without having to recompile. If I want new types of platforms etc, I may need to add them in C++ code. However, I'll be able to place them and modify them within the game itself (or in the editor of the game - which is currently (and will stay) in the same source as the game). The program is also going to use the triggers and console itself - in what may not be particularly efficient, but is going to make my job easier. For instance, I will add a Trigger underneath a block which tells the PuppetMaster that it's time for the block to the fall.

And so far it works!

Part of this has been learning to use the boost library - which I'm impressed with. I'm impressed with how consistent it is with the C++ STL itself - accessing regex results is done exactly the same way with iterators as any of the STL containers. I'm also finding boost::lexicalcast<> an absolute lifesaver.


I'm thinking next will be a very basic GUI for accessing code and using triggers that will operate through the PuppetMaster to make my life easier. Either that or just adding the template dude to make him jump around...