Game
Maker is a programme to make games, and has its own language,GML as
well as an option to use a drag and drop build mode, similar to the
Scirra/Construct app. Here in this post you will see exercises in GML
mode. In the workspace,the folder structure usually appear on the right
side and among others we will be using more the Objects, Sprites and
Room folders. Here are the instruction to create a player that has to elude rocks faling form the top of the screen.
1.CREATE THE PLAYER
Now to create the game. Since
the obj_test in room1, we can keep it there.Instead, now we go to
Sprite folder and select create to make one and call it spr_player. As a
rule of thumb,whenever you create an asset put the set type in the name
so you know what type of asset you are dealing with; this will come
handy when the project start to grow. Then, go to edit image and paint
the square then I go to objects panel and create anew object and it will
be linked to the sprite and I name it obj_player. Don't forget to move
the point of origin in the middle of the square in the sprite.Now in the
panel of obj_player select the button Events and add create , step and
draw just like you did with obj_test.
//to place the player in the room in the create panel add;
start_x=room_width/2
start_y=room_height-100
x=start_x
y=start_y
//In the draw panel add;
draw_self()
//now in the create panel add:
player_spd=5
//in the Step panel add:
if keyboard_check(vk_up){
y-=player_spd
}
if keyboard_check(vk_down){
y+=player_spd
}
if keyboard_check(vk_left){
x-=player_spd
}
if keyboard_check(vk_right){
x+=player_spd
}
//this is to make the player move up and down using the arrow keys
//you can change your sprite
image_xscale=1
image_yscale=1
2.CREATING ROCKS
Now
for the rocks. The process would be very similar, so we just repeat it.
Create a new sprite pain it orange name it spr_rock,place the origin in
the middle center, create an object, name it obj_rock, add events panel
for create and step. Drag instances of the rock object to the room. And
voila!
//In the rock create panel add:
rock_spd=5
rock_reset=false
//In the rock step panel add:
y+=rock_spd
if y>room_height{
rock_reset=true
}
if rock_reset{
y=-100
//appear in random places
x=irandom_range(o,room_width)
//change speed randomly
rock_spd=irandom_image(5,10)
rock_reset=false
}
3.CREATE ROCK GENERATOR
But
to place rock by rock would be cumbersome. So we create them
authomatically. How?. Enter the rock generator.Create an object called
obj_rock_gen, an invisible object that generate the rock , we drag into
the room1 and delete all the rock placed previously.
//We click event and add create. There we add:
num_rocks=12
//If we would want only one rock we could od like this:
instance_create_depth(0,0,0,obj_rock)
//We could repeat this again and again and it will work but better to use a for loop:
num_rocks=12
for (i=0;i<num_rocks;i+=1){
instance_create_depth(0,0,0,obj_rock)
}
4.SET UP COLLISIONS
One
of the crucial parts of a video-game is the way you handle collisions.
They are the basic interactions between the objects of your game. There
are many ways but we will use here one of them..
//Creating keyboard events: down, up, right, left
//Go back to our player object events in the step panel:
if keyboard_check(vk_up){
y-=player_spd
}
if keyboard_check(vk_down){
y+=player_spd
}
if keyboard_check(vk_left){
x-=player_spd
}
if keyboard_check(vk_right){
x+=player_spd
}
//one more if loop for the collision itself
//send player to start point when collides
if collision_circle(x,y,20,obj_rock, flash, false){
x=start_x
y=start_y
}
//in the create panel add;
start_x=room_width/2
start_y=room_height-100
x=start_x
y=start_y
player_spd=5
got_hit=false
hit_timer=0
hit_timer_max=120
//Go back to our player step panel and add:
if keyboard_check(vk_up){
y-=player_spd
}
if keyboard_check(vk_down){
y+=player_spd
}
if keyboard_check(vk_left){
x-=player_spd
}
if keyboard_check(vk_right){
x+=player_spd
}
if collision_circle(x,y,20,obj_rock, false, false){
got_hit=true
hit_timer=hit_timer_max
x=start_x
y=start_y
}
if got_hit{
hit_timer -= 1
if hit_timer <0{
got_hit=false
}
}
//Go back to our player draw panel and add:
if got_hit=+false{
draw_self()
}
//And finally in the step panel, we can wrap our conditionals in a one not got it function, like this:
if !got_hit{
if keyboard_check(vk_up){
y-=player_spd
}
if keyboard_check(vk_down){
y+=player_spd
}
if keyboard_check(vk_left){
x-=player_spd
}
if keyboard_check(vk_right){
x+=player_spd
}
if collision_circle(x,y,20,obj_rock, false, false){
got_hit=true
hit_timer=hit_timer_max
x=start_x
y=start_y
}
}
if got_hit{
hit_timer -= 1
if hit_timer < 0{
got_hit=false
}
}
Other links:
https://gamemaker.io/en/tutorials/how-to-make-buttons
https://gamemaker.io/en/blog/gui-layer-secrets
https://gamemaker.io/en/tutorials/gms2-tutorial-breakthrough
https://gamemaker.io/en/tutorials/coffee-break-tutorials-parallax-scrolling-gml
https://gamemaker.io/en/tutorials/easy-multiplayer-tutorial
https://gamemaker.io/en/tutorials/little-town-gamemaker-tutorial
https://gamemaker.io/en/tutorials/coffee-break-tutorials-simple-inventory-gml
https://gamemaker.io/en/tutorials/make-your-own-arcade-classic
https://gamemaker.io/en/tutorials/create-a-platformer-game-with-gml
https://gamemaker.io/en/tutorials/my-first-arena-shooter-gml
Comments
Post a Comment