0编程基础新人一周速成Gamemaker在打校内gamejam的时候搓出来的小玩意,直接上代码吧。
在这里放一下我们布谷游戏工作室的交流群群号,欢迎大家交流互相学习
布谷招待所 588307084
碰撞什么的就没放上来了,gms里面涉及多个object的有点复杂,里面用了别的子弹object和一些其他的东东,随便看看吧。
1.Boss_creat
globalvar hp_boss ;//血量
hp_boss = 120;
audio_play_sound(choose(sound_boss2,sound_boss1,sound_boss3),0,0);
var i = random(3);
if(i == 1)
{sprite_index = sprite69;}
else{
sprite_index = spr_enemy_boss;
}
enum Actions
{
ONE,
TWO,
THREE,
FOUR,
TIRED
}
phy_fixed_rotation = 1;
time_first_action = 90;//生成后行动
boss_state = Actions.TIRED;
time_tired = 150;
time_one = 150;
time_two = 150;
time_three = 150;
time_four = 300;
fired = true;
shoot_one = 30;
shoot_three = 30;
shoot_two= 30;
shoot_four = 95;
boss = true;
2.Boss_step
time_first_action --;
//初始动作
if(time_first_action >= 0){
phy_position_y += 2;
}
//状态机切换
if(boss_state == Actions.TIRED ){
Tired();
}
else if(boss_state == Actions.ONE){
One();
}
else if(boss_state == Actions.TWO){
Two();
}
else if(boss_state == Actions.THREE){
Three();
}
else if(boss_state == Actions.FOUR){
Four();
}
//不出房间
if(phy_position_x < 0) {phy_position_x = 0;}
if(phy_position_x >= room_width){ phy_position_x = room_width - 1;}
if(phy_position_y <= 108){ phy_position_y = 108; }
if(hp_boss <= 0){
instance_destroy();
room_goto(room_win);
score = 0;
audio_stop_all();
}
Boss_step_one
time_one --;
shoot_one --;
if(time_one <= 0){
boss_state = choose(Actions.TIRED,Actions.TIRED,Actions.ONE,Actions.TIRED,Actions.FOUR,Actions.THREE,Actions.TWO,Actions.TWO,Actions.THREE,Actions.FOUR);
time_one = 150;
fired = true;
}
else if(time_one >0 ){
if(shoot_one == 0 ){
var one = random_range( phy_position_x - 144,phy_position_x - 72);
var two = random_range( phy_position_x - 72,phy_position_x );
var three = random_range( phy_position_x ,phy_position_x + 72);
var four = random_range( phy_position_x + 72,phy_position_x + 144);
instance_create(choose(one,two,three,four),phy_position_y+32,choose(obj_bullet_red,obj_bullet_blue,obj_bullet_green));
instance_create(choose(one,two,three,four),phy_position_y+32,choose(obj_bullet_red,obj_bullet_blue,obj_bullet_green));
instance_create(choose(one,two,three,four),phy_position_y+32,choose(obj_bullet_red,obj_bullet_blue,obj_bullet_green));
instance_create(choose(one,two,three,four),phy_position_y+32,choose(obj_bullet_red,obj_bullet_blue,obj_bullet_green));
}
else if(shoot_one < 0){
shoot_one = 20;
}
}
Boss_step_two
time_two --;
shoot_two --;
var i =random_range(-5,5);
var m =random_range(-5,5);
if(time_two <= 0){
//切换概率
boss_state = choose(Actions.ONE,Actions.FOUR,Actions.ONE,Actions.ONE,Actions.THREE);
time_two = 150;//该状态持续时间
fired = true;
}
else if(time_two > 0){
if(shoot_two == 0){
var one = random_range( phy_position_x - 144,phy_position_x - 72);
var two = random_range( phy_position_x - 72,phy_position_x );
var three = random_range( phy_position_x ,phy_position_x + 72);
var four = random_range( phy_position_x + 72,phy_position_x + 144);//发弹位置
//每次发弹量
instance_create(one , phy_position_y + 16 , obj_bullet_red);
instance_create(two , phy_position_y + 16 , obj_bullet_red);
instance_create(three , phy_position_y + 16 , obj_bullet_red);
instance_create(four , phy_position_y + 16 , obj_bullet_red);
}
else if(shoot_two < 0){
shoot_two = 15;//每次发射间隔
}
else{
//乱走
phy_position_x += i;
phy_position_y += m;
}
}
Boss_step_three
time_three --;
shoot_three -- ;
var i =random_range(-5,5);
var m =random_range(-5,5);
if(time_three <= 0){
boss_state = choose(Actions.ONE,Actions.FOUR,Actions.ONE,Actions.ONE,Actions.TWO);
time_three =150;
}
else if(time_three > 0){
if(shoot_three == 0){
var one = random_range( phy_position_x - 72,phy_position_x+72 );
var two = random_range( phy_position_x - 72,phy_position_x+72 );
instance_create(one,phy_position_y + 16,obj_bullet_green);
instance_create(two,phy_position_y + 16,obj_bullet_green);
instance_create(one,phy_position_y + 16,obj_bullet_green);
instance_create(two,phy_position_y + 16,obj_bullet_green);
}
else if(shoot_two < 0){
shoot_two = 20;
}
else{
phy_position_x += i;
phy_position_y += m;
}
}
3.Boss_step_four
time_four --;
shoot_four --;
var i =random_range(-5,5);
var m =random_range(-5,5);
if(time_four <= 0){
boss_state = Actions.TIRED;
time_four = 300;
shoot_four = 95;
with(obj_weakness)
instance_destroy();
}
else if(time_four >= 30)
{
if(shoot_four == 0){
var one = random_range( phy_position_x - 36,phy_position_x+36 );
var two = random_range( phy_position_x - 144,phy_position_x -108 );
var three = random_range( phy_position_x + 108,phy_position_x +144 );
instance_create(one,phy_position_y + 16,obj_bullet_green);
instance_create(one,phy_position_y + 16,obj_bullet_green);
instance_create(two,phy_position_y + 16,obj_bullet_blue);
instance_create(three,phy_position_y + 16,obj_bullet_blue);
}
else if(shoot_four < 0){
shoot_four = 15;
}
else if(shoot_four == 90){
instance_create(phy_position_x,phy_position_y,obj_boss_skill);
instance_create(phy_position_x,phy_position_y + 40,obj_weakness);
}
}
Boss_step_tired
time_tired --;
var i =random_range(-5,5);
var m =random_range(-5,5);
if(time_tired <= 0){
boss_state = choose(Actions.FOUR,Actions.FOUR,Actions.TIRED,Actions.ONE,Actions.ONE,Actions.ONE,Actions.TWO,Actions.THREE,Actions.ONE,Actions.ONE);
time_tired = 150;
}
else{
phy_position_x += i;
phy_position_y += m;
}