new to game maker, need help

A

azzzanadra

Guest
alright people, i am trying to create a platformer, i figured i would start step by step, i have no knowledge of programming and the videos on youtube help only so much.

first i would like help with knockback, i want forced knockback in which if the player touches the enemy they are knocked back at what ever direction the attack came from, in which the player gets in a getting hurt animation where they cannot react until it is over.

second i would like to learn how to implement a health bar, i know how to make health but not a health bar.
third i would like it so that whenever i lose a life the room reset and the player returns to the beginning of the room, similar to how castlevania handled it.

if anyone can tutor me i really appreciate it.
 

TDSrock

Member
I'll run through each of these core concepts real quick/

1. Remove the user's control for a time. On the moment of impact have the player object's speed values be something like
Code:
hsp = 16 * direction_of_attack;//where direction_of_attack is between 1 and -1
vsp = -8;//knocks the player up a bit too.
2. Game-maker actually has a draw_hp_bar function. You can use this. I have employed that method in my prototype which all the source code is available to below.(See link in my signature)

3. Here you can again look at what I did in my prototype. Only things needed to be added are that on spawn there should be a checkpoint and when a checkpoint gets loaded each mob spawner and is reset too. Of-course each mob would also need to be despawned. But just for the gradual line here you'll probably want to do the following things:
Make mobs be spawned via a mob spawner, not placed in the room by hand(this will let you control what mob is spawned at the moment of spawn, so in certain conditions you can change things much easier).
Someway store each mob spawner(Could just toss em into an array)
On death delete every enemy, respawn the player, reset the mob spawners.
 
R

Ratatosque

Guest
i can help you with the healthbar.

i use the following method in my game:

you need 2 variables: max_hp, hp. Set them in the create event of your Player.

I recommend creating another object that handles the User-Interface.

lets say obj_Control_UI.
In that objects draw event or better Draw_GUI event.
you put the following:

Code:
var hp, max_hp;

hp=obj_Player.hp;
max_hp=obj_Player.max_hp;

draw_set_colour(c_red)
draw_line_width(32,32,100,32,8)         // this draws a red line 100 pixels long at the top left corner
                                        //of your screen. it is the red background of your healthbar
var hp_percent;                         //here we set a temprary variable
hp_percent=((hp/max_hp)*100);           //it calculates the percent of hp you still have

draw_set_colour(c_green)                 //here we draw a green
draw_line_width(32,32,hp_percent,32,8)   //line on top of the red one as long as the percentage of your maximum hp
                                         //you still have
this is just the bar, you can use any colour any variations in colour and hue, you can draw borders around it or insert it into nice sprite you drew for the Interface. you can change it to be from top to bottom instead of left to right and you can draw a vial or bottle on top of it to make it look like a health potion which is beeing emptied as you loose health... anything is possible ;)
 
Last edited by a moderator:
A

azzzanadra

Guest
sir your prototype is a bit too much for me to chew, i need some lessons on what variables and types of scripts i need to use.
 
A

azzzanadra

Guest
ok let's start with knock back again.

what are the variables required for it?
 

TDSrock

Member
All you'll need there is a Boolean that is wheiter or not you are knocked back.
In all reality that can already be enough. But if you want there to be a timer of some sort, then we'll also need that(can use gamemaker's alarm system here too!).
 
A

azzzanadra

Guest
ok i already have this variable, so, where should i apply the knock back? and is it as simple as the function you gave me?
 

TDSrock

Member
Pretty much. Just think about what knock-back is. It's movement while the player has no control.
Use the Boolean to disable the controls and give the player some velocity values.
 
A

azzzanadra

Guest
i want the knockback to be sent both vertically and horizontally, similar to how simon belmont in super castlevania 4 had it.
 

TDSrock

Member
Jup so what I showed you there will be a pretty decent start in terms of movement values to pass to player on hit.
 
H

Heat4Life

Guest
If you really want to make that type of game you want to make on GameMaker: Studio then you better off Learning GML.
 
A

azzzanadra

Guest
i want to make a game where the first half of it is linear castlevania while the second half is metroidvania
 
A

azzzanadra

Guest
ok i tried to implement the statement for the direction of attack to be the enemy's direction, when i touch the enemy i keep going back and never stopping,
here is my statement for player object:

//get player input
key_right = keyboard_check(vk_right)
key_left = -keyboard_check(vk_left)
key_jump = keyboard_check_pressed(vk_space)
key_jump_held = keyboard_check(vk_space)
key_attack = keyboard_check(ord('z'))
//react to input
if (keyboard_check(vk_right))
{
hsp=movespeed
sprite_index=sprt_player_right;
image_xscale= 1
}
if (keyboard_check(vk_left))
{
hsp=-movespeed
sprite_index=sprt_player_right
image_xscale= -1
}

if (hit = 0)
{
move = key_left + key_right;
hsp = move * movespeed;
}
if (hsp < 1)
{
sprite_index=sprt_player
}

//attack



//control jump

if (vsp < 10) vsp += grav
if (place_meeting(x,y+1,obj_wall))
{
if(keyboard_check_pressed(vk_space)) vsp = -jumpspeed
}
if(!key_jump_held) && (vsp<0) vsp =max(vsp,0)

//horrizontal 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

scr_vertical_collision()

//getting hit

if (place_meeting(x,y,obj_enemy))
{
hit = 1
}

if (hit = 1)
{
key_right = 0
key_left = 0
key_jump = 0
hsp = 6 * (obj_enemy.dir);
alarm [0] = 300
}
else
{
hit = 0
}
 

TDSrock

Member
direction_of_attack is a variable. You'll need to figure out a way to find out where the attack came from.
Code:
direction_of_attack =
That will need to occur before it is used.

For now I'll leave it to you to figure it out. But if you do get stuck with it, show me what you tried to do, what you expected and what the actual result was.
I mainly do this because I want to see you working on this and this is the only real way for me to ensure you aren't just asking me for the solution and copy pasting it, expecting it to work.
 
A

azzzanadra

Guest
ok, i put the direction_of_attack variable, i managed to get a knockback effect, however it isn't forced knockback as i can still press right and keep moving forward, also there isn't a jump effect on the knockback and the knockback itself has a very small effect.

here is my script for getting hit:
//if enemy is walking to the left

if (place_meeting(x,y,obj_enemy))
{
if obj_enemy.dir = -1
{
hit = 1
direction_of_attack = -1
}
}
else
{
hit = 0
}

// if enemy is walking to the right

if (place_meeting(x,y,obj_enemy))
{
if obj_enemy.dir = 1
{
hit = 1
direction_of_attack = 1
}
}
else
{
hit = 0
}

//knockback
if (hit = 1)
{
hsp = 8 * (direction_of_attack);
vsp = -5
}
if (hit = 0)
{
hsp += -8* (direction_of_attack);
}
 

TDSrock

Member
Look at where you set the controls. Just force each control to be false while knock_back is true. (that will disable the player from doing things)
My guess with the jump is that you are playing with vsp not in the way I suspected. That or try to decrease the vsp value.
 
A

azzzanadra

Guest
Look at where you set the controls. Just force each control to be false while knock_back is true. (that will disable the player from doing things)
My guess with the jump is that you are playing with vsp not in the way I suspected. That or try to decrease the vsp value.
if i want to have a knockback animation, how do i make it so that by the end of the knockback animation the player regains control?
 

TDSrock

Member
So say I had only one control in my entire game for simplicity sake(I would grab source code from projects, I just don't have the access right now).

Code:
left = keyboard_check(ord('A'));
So that does my controlls. All I would need to do to take away the abilty for the player to change left is to surround it by an if statement.

Code:
if(knock_back){
    left = false;
} else {
    left = keyboard_check(ord('A'));
}
So now as long as knock_back is true, the player won't be able to change what the value of left is. Heck I even forced the input to be false.

So somewhere we could have this:
Code:
if(hit){
    knock_back = true;
//include the movement direction stuff
//other code for getting hit here
}
That will start the knockback on the player
Now it's just a matter of coming up with a way to flip the Boolean back to false. I'll use touching the ground as an example:
Code:
if(place_meeting(x,y+1,obj_ground)){
    knock_back = false;
}
That would do the trick.
If you want to use an animation you can look into the built in variable that is called sub_img or something close to that.
 
A

azzzanadra

Guest
i ended up doing a knockback where i end up being teleported a certain distance, i think i am doing something wrong here.
have a look:

//knockback
if (hit = 1)
{
hsp = 50 * (direction_of_attack);
vsp = -5
key_right = false
key_left = false
key_space = false
alarm [0] = 60*2
}

at alarm 0:
hit = 0
hsp += 3*(direction_of_attack)
key_right = keyboard_check(vk_right)
key_left = -keyboard_check(vk_left)
key_jump = keyboard_check_pressed(vk_space)
 
A

azzzanadra

Guest
sorry for this one, i didn't see your reply, but the teleport problem isn't solved
 

TDSrock

Member
The idea is to set the speed to a value and then through gravity to let it fall back down. While holding the horizontal speed the same(or slowly decreasing it).
 
A

azzzanadra

Guest
ok i changed my mind about vertical knockback, i remembered how frustrating castlevania knockback was, i will make it like megaman, small vertical knockback with invisibility frame.
i just need to make the horizontal knockback a bit more as i can only inch a little bit away from the enemy, can you look at my script?


if (place_meeting(x,y,obj_enemy))
{
if obj_enemy.dir = -1
{
hit = 1
direction_of_attack = 1
}
}
else
{
hit = 0
}

if (place_meeting(x,y,obj_enemy))
{
if obj_enemy.dir = 1
{
hit = 1
direction_of_attack = -1
}
}
else
{
hit = 0
}

//knockback
if (hit = 1)
{
hsp -= 10 * (direction_of_attack);
key_right = false
key_left = false
key_jump = false
}
else
{
key_right = keyboard_check(vk_right)
key_left = -keyboard_check(vk_left)
key_jump = keyboard_check_pressed(vk_space)
hsp = move * movespeed
}
 
Top