Day 27

I did a lot on class today. I restarted the new game and i got all the basic things down (like objects, sprites and tiles etc.)
Then i implemented Collision with a simple 20 line code

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;

Then I implemented movement into my game with the same code i used in my previous game

//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space) or keyboard_check_pressed(vk_up);
//React to inputs
if move_lock = false
{
    move = key_left + key_right
}

Then a new code I added from a different game is the Enemy movement which makes the object bounce back and forth off objects. Like this
Then i added a code that kinda makes it like a Goomba you can only kill if you jump on it. If it's sides touch you, you die.
This is the code

//Enemy Collision
if (place_meeting(x,y,obj_player))
{
    if (obj_player.y < y-16)
    {
        with (obj_player) vsp = -jumpspeed;
        instance_destroy();
    }
    else
    {
        room_restart();
    }
}

The video i used to help me with the enemy was: https://www.youtube.com/watch?v=wmnaOLI6RzE&nohtml5=False

Then I wanted a sprite for my player not just a block. So on the last bit of class i used http://www.piskelapp.com/ to make a 32x32 sprite for my player.

Tomorrow I will add powerups to the game and more levels. And if i have time an enemy sprite.

No comments:

Post a Comment