【GAMEMAKER】Dual View Bomber Man Game

 Information about object: obj_splash

Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//set up globals and goto game room
global.player_bombs=0;
global.enemy_bombs=0;
health=100;
global.enemy_health=100;
room_goto(room_1_player);

Information about object: obj_player_1
Sprite: spr_player_1
Solid: false
Visible: true
Depth: -2
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

///setup
move_dx = 0;
move_dy = 0;
move_amt = 0;

image_index=0;
image_speed=0;

can_hurt=true;

Alarm Event for alarm 5:
execute code:

can_hurt=true;
Step Event:
execute code:

///MOVEMENT
if (move_amt > 0)
{
    // moving towards destination
    if (scr_move(move_dx, move_dy))
    {
        move_amt -= 1;
    }
    else move_amt = 0; // if hit a wall, stop moving
}
else
{
    var spd = 4; // movement speed (grid size should divide by it w/o remainder)
    move_amt = 32 div spd; // calculate number of steps for movement
    move_dx = 0;
    move_dy = 0;
    if (keyboard_check(vk_left)) && !(position_meeting(x-18,y,obj_wall))//move if only 1 block and pos free
    {
        move_dx = -spd;
    }
    else if (keyboard_check(vk_right)&& !(position_meeting(x+18,y,obj_wall)))
    {
        move_dx = spd;
    }
    else if (keyboard_check(vk_up) && (!position_meeting(x,y-18,obj_wall)))
    {
        move_dy = -spd;
    }
    else if (keyboard_check(vk_down))&& !(position_meeting(x,y+18,obj_wall))
    {
        move_dy = spd;
    }
    else move_amt = 0; // don't move if no buttons are pressed
}
execute code:

///DROP BOMB
if (keyboard_check_pressed(ord('Z')) && global.player_bombs>0)
{
    global.player_bombs--;
    instance_create(x,y,obj_bomb);
    scr_sound(snd_drop_bomb);
}
execute code:

///sprite control
//move_dx, move_dy
if move_dx>0 image_index=3;
if move_dx<0 image_index=1;
if move_dy>0 image_index=0;
if move_dy<0 image_index=2;
Collision Event with object obj_ammo:
execute code:

///increase no of bombs
global.player_bombs+=5;
with (other) instance_destroy();
instance_create(5,5,obj_ammo);
scr_sound(snd_ammo);
Collision Event with object obj_explosion:
execute code:

if can_hurt
{
    health--;
    scr_sound(snd_ouch);
    can_hurt=false;
    alarm[5]=room_speed;//prevent hurting for one second
}
Information about object: obj_wall
Sprite: spr_wall
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Information about object: obj_hud_1
Sprite:
Solid: false
Visible: true
Depth: -100
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

///test  lives
if health<1 or global.enemy_health<1
{
    room_goto(room_game_over);
}

Draw GUI Event:
execute code:

draw_set_halign(fa_center);
draw_text(400,750,"Player 1 - Arrow Keys Move - Z Drop Bomb");
draw_text(20,20,"Plater Health "+string(health));
draw_text(400,20,"Enemy Health "+string(global.enemy_health));
draw_set_halign(fa_left);
draw_text(20,50,"Player Bombs "+string(global.player_bombs));
draw_text(20,80,"Enemy Bombs "+string(global.enemy_bombs));
Information about object: obj_bomb
Sprite: spr_bomb
Solid: false
Visible: true
Depth: -5
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

move_snap(32,32);
life=5;
alarm[0]=room_speed/4;
Alarm Event for alarm 0:
execute code:

life--;
alarm[0]=room_speed/4;
Step Event:
execute code:

///create explostion
if life==0
{
    scr_sound(snd_explosion);
    //create exp at position
    instance_create(x,y,obj_explosion);

    //create up
    if !position_meeting(x,y-32,obj_wall)
    {
        instance_create(x,y-32,obj_explosion);
        if !position_meeting(x,y-64,obj_wall)
        {
            instance_create(x,y-64,obj_explosion);
            if !position_meeting(x,y-96,obj_wall)
            {
                instance_create(x,y-96,obj_explosion);
            }
        }
    }
    //create down
    if !position_meeting(x,y+32,obj_wall)
    {
        instance_create(x,y+32,obj_explosion);
        if !position_meeting(x,y+64,obj_wall)
        {
            instance_create(x,y+64,obj_explosion);
            if !position_meeting(x,y+96,obj_wall)
            {
                instance_create(x,y+96,obj_explosion);
            }
        }
    }
//create left
    if !position_meeting(x-32,y,obj_wall)
    {
        instance_create(x-32,y,obj_explosion);
        if !position_meeting(x-64,y,obj_wall)
        {
            instance_create(x-64,y,obj_explosion);
            if !position_meeting(x-96,y,obj_wall)
            {
                instance_create(x-96,y,obj_explosion);
            }
        }
    }
    //create right
    if !position_meeting(x+32,y,obj_wall)
    {
        instance_create(x+32,y,obj_explosion);
        if !position_meeting(x+64,y,obj_wall)
        {
            instance_create(x+64,y,obj_explosion);
            if !position_meeting(x+96,y,obj_wall)
            {
                instance_create(x+96,y,obj_explosion);
            }
        }
    }
    instance_destroy();
}


Collision Event with object obj_explosion:
execute code:

life=0;
Draw Event:
execute code:

draw_set_halign(fa_center);
draw_set_colour(c_red);
draw_self();
draw_text(x,y,life);
Information about object: obj_ammo
Sprite: spr_bomb_crate
Solid: false
Visible: true
Depth: -30
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//jump to a random free position
do
{
    var _x = (random(room_width) div 32) * 32;
    var _y = (random(room_height) div 32) * 32;
}
until (place_free(_x, _y));
x=_x;
y=_y;

Information about object: obj_explosion
Sprite: spr_explosion
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

///destroy at end
if image_index>45 instance_destroy();
Information about object: obj_game_over
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

alarm[0]=room_speed*10;
Alarm Event for alarm 0:
execute code:

game_restart();
Draw Event:
execute code:

if health<1
{
    draw_text(100,100,"Enemy Wins");
}
else
{
    draw_text(100,100,"Player Wins");
}

Information about object: obj_enemy
Sprite: spr_player_2
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

grid=mp_grid_create(0, 0, room_width div 16, room_height div 16, 16 , 16);
mp_grid_add_instances(grid, obj_wall, false);

image_speed=0;
image_index=0;
path=path_add();

mp_grid_path(grid,path,x,y,obj_ammo.x,obj_ammo.y,false);
path_start(path,3.5,path_action_stop,true);

can_hurt=true;
Alarm Event for alarm 0:
execute code:

//choose a target
target=choose("player","random");
if target=="player"
{
    mp_grid_path(grid,path,x,y,obj_player_1.x,obj_player_1.y,false);
    path_start(path,3.5,path_action_stop,true);
    alarm[0]=room_speed*5;//prevent sticking
    exit;
}
if target=="random"
{
    do//find a free place
    {
        var _x = (random(room_width) div 32) * 32;
        var _y = (random(room_height) div 32) * 32;
    }
    until (place_free(_x, _y));


    mp_grid_path(grid,path,x,y,_x,_y,false);
    path_start(path,3.5,path_action_stop,true);
    alarm[0]=room_speed*8;//prevent sticking
}
Alarm Event for alarm 5:
execute code:

can_hurt=true;
Step Event:
execute code:

///image control
if hspeed>0 image_index=3;
if hspeed<0 image_index=1;
if vspeed>0 image_index=0;
if vspeed<0 image_index=2;
execute code:

///randomlly drop a bomb
rand=irandom(200);//one in 200 chance of dropping a bomb
if rand==1
{
    if global.enemy_bombs>0//check player has bombs
    {
        global.enemy_bombs--;
        instance_create(x,y,obj_bomb);
    }
}
Collision Event with object obj_ammo:
execute code:

///increase no of bombs
global.enemy_bombs+=5;
with (other) instance_destroy();
instance_create(5,5,obj_ammo);
scr_sound(snd_ammo);
Collision Event with object obj_explosion:
execute code:

if can_hurt
{
    global.enemy_health--;
    scr_sound(snd_ouch);
    can_hurt=false;
    alarm[5]=room_speed;//prevent hurting for one second
}

Other Event: Game End:
execute code:

mp_grid_destroy(grid);
path_delete(path);
Other Event: End Of Path:
execute code:

///clear and update grid + drop bomb
if global.enemy_bombs>0
{
    global.enemy_bombs--;
    instance_create(x,y,obj_bomb);
    
}

//grid
mp_grid_clear_all(grid);
mp_grid_add_instances(grid, obj_wall, false);
if global.enemy_bombs<1
{
    mp_grid_path(grid,path,x,y,obj_ammo.x,obj_ammo.y,false);
    path_start(path,3.5,path_action_stop,true);
    alarm[0]=room_speed*5;//prevent sticking
    exit;
}

//choose a target
target=choose("player","random");
if target=="player"
{
    mp_grid_path(grid,path,x,y,obj_player_1.x,obj_player_1.y,false);
    path_start(path,3.5,path_action_stop,true);
    alarm[0]=room_speed*5;//prevent sticking
    exit;
}
if target=="random"
{
    do//find a free place
    {
        var _x = (random(room_width) div 32) * 32;
        var _y = (random(room_height) div 32) * 32;
    }
    until (place_free(_x, _y));


    mp_grid_path(grid,path,x,y,_x,_y,false);
    path_start(path,3.5,path_action_stop,true);
    alarm[0]=room_speed*8;//prevent sticking
}


Draw Event:
execute code:

draw_self();
draw_path(path,x,y,true);

Information about object: obj_view_control
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

var x1 = obj_player_1.x;//get x position of player 1
var y1 = obj_player_1.y;//get y position of player 1
var x2 = obj_enemy.x;//get x position of player 2
var y2 = obj_enemy.y;//get y position of player 2
var border = 50;//set a border distance
var vscale = max(1, abs(x2 - x1) / (view_wport[0]- border * 2), abs(y2 - y1) / (view_hport[0] - border * 2)); //calculte scale needed
view_wview[0] = vscale * view_wport[0];//apply scale to view port
view_hview[0] = vscale * view_hport[0];//apply scale to view port
view_xview[0]= (x1 + x2 - view_wview[0]) / 2;//update view
view_yview[0] = (y1 + y2 - view_hview[0]) / 2;//update view


No comments:

Contact Form

Name

Email *

Message *