Jump to content


Shazzy Zang

Member Since 02 Jan 2010
Offline Last Active May 17 2013 12:33 AM

Topics I've Started

Destructible Terrain

12 May 2011 - 03:43 PM

•Title: Destructible Terrain
•Description: An Example on how to implement destructible terrain
•GM Version: GM 8
•Registered: Yes
•File Type: .gmk
•File Size: 12.3kb
•File Link: Download

Additional Info:
If you have any questions or concerns, feel free to post them here.
While credit is not required, I would greatly appreciate it.

'Swap Puzzle' Example

22 February 2011 - 09:16 PM

  • Title: 'Swap Puzzle' Engine v1.0
  • Description: A puzzle game in which blocks fall where the user must swap adjacent blocks to destroy groups of a single color
  • GM Version: Game Maker 8
  • Registered: Yes
  • File Type: .gmk
  • File Size: 21.1kb
  • File Link: Download Here [Box.net]

Additional Info
* Plenty of commenting, the average GML user should be able to understand what's going on

Posted Image

Platformer engine problems

11 January 2011 - 03:11 AM

A few problems i'm having:

Collision's with solids from the side sometimes cause you to stick into them.
Sometimes you get stuck when at the corner where a slope meets flat ground

Theres a fair bit of code in my program, commented though so you can see what I was thinking when I wrote it.
My levels are seperated into 'screen object sprites'. For every 640x480 part of the room there is another object[with the sprite] that holds the terrain data for that part of the level.
It's solid, everything else is done in the player's events.

Player Creation
//Custom speed variables
hSpeed = 0;
vSpeed = 0;

//Physics
ver_acc = 0.5;
hor_acc = 0.7;
ver_terminal = 10;
hor_terminal = 5;
fric = 0.5;
//Note: Acceleration must be larger than friction, otherwise movement is impossible

//Height from the ground
altitude[0] = -1;
altitude[1] = -1;
altitude[2] = -1;

//Is the player currently on the ground?
grounded = false;

//Jumps
jumps = 0;
max_jumps = 1;
jump_speed = 5;

//Angle at which the sprite is drawn. Use this instead of image_angle to avoid changing the mask
draw_angle = 0;
image_xscale = 1;

//Player actions
key_right = vk_right;
key_left = vk_left;
key_up = vk_up;


Player Begin Step
//Accelerate due to gravity, max at terminal velocity
vSpeed = min(vSpeed + ver_acc, ver_terminal);

//Floor Collisions
if (vSpeed >0 && !place_free(x, y + abs(vSpeed) + 1))
{
    //Snap to ground, and then stop downward motion
    move_contact_solid(270, abs(vSpeed));
    vSpeed = 0;
    
    //The player is on the ground
    grounded = true;
    jumps = 0;
}
else
{
    //Player is not currently on ground
    grounded = false;
}

//Friction
if (hSpeed > 0)
{
    hSpeed = max(0, hSpeed - fric);
}
else if (hSpeed < 0)
{
    hSpeed = min(0, hSpeed + fric);
}

Player Step Event
//Horizontal movement
if (keyboard_check(key_right))
{
    //Accelerate up to the max horizontal speed
    hSpeed = min(hor_terminal, hSpeed + hor_acc);
}
if (keyboard_check(key_left))
{
    //Accelerate up to the max horizontal speed
    hSpeed = max(-hor_terminal, hSpeed - hor_acc);
}

//Jumping
if (keyboard_check(key_up) && !place_free(x, y+1) && jumps < max_jumps)
{
    //On the ground, has another jump, so jump by adding to the vSpeed
    vSpeed -= jump_speed;
    jumps += 1;
}

//Check for collisions at the new spot
if (!place_free(x + hSpeed, y))
{
    //Check if it is a slope
    altitude[0] = get_height_from_below(x + sign(hSpeed), y, 128);
    altitude[1] = get_height_from_below(x + 2*sign(hSpeed), y, 128);
    altitude[2] = get_height_from_below(x, y, 128);

    //If they are equal, its flat, and therefore a wall
    if (altitude[0] = altitude[1] && altitude[0] = altitude[2] && altitude[1] = altitude[2])
    {            
        //Move to the collision.
        move_contact_solid(  90 - (90 * sign(hSpeed)), abs(hSpeed));
        hSpeed = 0;
    }
    else
    {
        //Max number of moves available[alternate way of moving diagonally]
        var px_moves;
        px_moves = abs(hSpeed) / 4;
        
        //Keep moving until there are no more moves
        do
        {
            //Get the height of the next part of the slope
            for (i = 0; i < abs(hSpeed); i += 1)
            {
                //If it finds the point
                if (place_free(x + sign(hSpeed), y - i))
                {
                    //Exit the loop
                    break;
                }
            }
            
            //Move horizontaly
            x += sign(hSpeed);
            //Subtract the one horizontal movement
            px_moves -= 1;
            
            //Move vertically
            y -= i + 3;
            px_moves -=i;
        }
        until (px_moves <= 0);
    }
}

Player End Step Event
//Execute movement using vSpeed and hSpeed
y += vSpeed;
x += hSpeed;

//Follow the ground, if they were on the ground at the begging of the step
if (grounded = true and vSpeed >=0)
{
    //Get the height from the ground
    altitude[0] = get_height_from_ground(x, y, 128);
    
    //Check two other altitudes
    altitude[1] = get_height_from_ground(x+1, y, 128);
    altitude[2] = get_height_from_ground(x+2, y, 128);
    
    //Check if they are all the same
    if (altitude[0] = altitude[1] && altitude[0] = altitude[2] && altitude[1] = altitude[2])
    {
        //If they are all the same, the below area must be a flat surface, so dont move along it, you will fal
    } 
    else
    {
        //Move down to snap to the slope
        move_contact_solid(270, altitude[0]);
    }
    
}

Player Draw Event
//Draw the player
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, draw_angle, image_blend, image_alpha);

Download GMK here

Any help is appreciated.

'Light' travelling outwards from a point

11 August 2010 - 03:28 AM

For Reference (The GM8 File): Download

Some Topdown/overhead games such as the gameboy zelda games use a specific effect for the lantern item. This effect is a simple one, with a circle around the player, and everything else is in the room is faded black. This is partially what i'm looking to accomplish, but theres a little more to it.

What I would like to do is rather than having a perfect circle represeting the lit area, have it adjust based on the terrain. For example, if the light is in the middle of a room, and there are no walls within the range of the light, it will end up being a perfect circle. However, if there is a wall say, 32px to the right of it, light moving in that direction will stop at that wall. This would leave walls 'invisible' to the player, and just passageways visible. Of course anything that is not within reach of the light should be blacked out.

I've made an attempt at this, and what i've managed to do is make light moving outward from a central point, and stop at blocks. What i'm not entirely sure of how to do, is to make everything else be completely black, unless its within the range of one of these lights.

Also, i'm wondering if there is any faster way of doing this, because my goal is to be able to have a moving light(following a player perhaps). The method i'm doing this takes to much code to run in the step event, so it makes it incredibly hard to work as I was hoping.

I tried to explain as clearly as possible, but if theres anything you need clarification on, just tell me. Thanks!

ShapeShifter

22 June 2010 - 09:14 PM

One evening, as your walking down an alley, you hear some noise. Before you can react, someone jumps out from behind you, puts a bag over your head, and you are soon unconscious. When you awake your in a massive laboratory. As you wake up, your welcomed by a voice on the intercom. He tells you that your here to 'voluntarily' test his newest technology. This technology allows you to alter terrain using a computer now imbedded onto your wrist. This method, he says, is called 'Shape-Shifting'...

The goal of this game is to travel through several floors of the research factory in an attempt to find a way out. Unlike any standard platformer, you have the ability to certain terrain. This allows for many unique puzzles and challenges!

Currently Features:
1 Demo Level(Introduction Level, it Explains the basics)
The ability to create, save, load, and play your own levels! (Using the Level Editor on the main menu)

Want to see what it looks like(Sprites and such are temporary though)?
Posted Image

Game Link: Click Here!

For the level editor, you can access the 'add-item' menu by hovering over the top of the screen. From left to right, the icons represent:
Start, Checkpoint, End, Rectangle, Triangle, Electrified Block, Moving Electrified Block, Barrier, Message, Turret, Switch, Locked Door
(I suggest you play the first level first, it explains each of these items).

Also, if you hold Control you can move the view too see the rest of the room(for larger levels). The view will move when your holding control and the mouse is near the edge of the screen.

I would appreciate any comments, as thats the only way I can know what to improve on. Also, if you create any levels your really proud of, send them to me and i'll take a look. They may even make an appearance(fully, or partially) in the next version(with your permission of course) in the campaign or in a 'selected few' section.