Sunday, April 4, 2021

Edward Lance Lorilla

Edward Lance Lorilla


【GAMEMAKER】Day and Night

Posted: 03 Apr 2021 08:47 PM PDT

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

///set up
enum player_state {
idle,
up,
down,
left,
right
}

dir=player_state.down;
is_moving=false;
image_speed=0.5;
Step Event:
execute code:

///keypress code
if (keyboard_check(vk_left))
{
dir=player_state.left;
is_moving=true;
}
else
if (keyboard_check(vk_right))
{
dir=player_state.right;
is_moving=true;
}
else
if (keyboard_check(vk_up))
{
dir=player_state.up;
is_moving=true;
}
else
if (keyboard_check(vk_down))
{
dir=player_state.down;
is_moving=true;
}
else
{
is_moving=false;
}



execute code:

///movement
if is_moving
{
switch (dir)
{
case player_state.up:
if !position_meeting(x,y-4,obj_solid_base) y -= 4;
break;

case player_state.down:
if !position_meeting(x,y+4,obj_solid_base) y += 4;
break;

case player_state.left:
if !position_meeting(x-4,y,obj_solid_base) x -= 4;
break;

case player_state.right:
if !position_meeting(x+4,y,obj_solid_base) x += 4;
break;
}
}
depth=-y;
execute code:

///animation
if is_moving
{
switch (dir)
{
case player_state.up:
sprite_index=spr_walk_up;
break;

case player_state.down:
sprite_index=spr_walk_down;
break;

case player_state.left:
sprite_index=spr_walk_left;
break;

case player_state.right:
sprite_index=spr_walk_right;
break;
}
}
else
{
switch (dir)
{
case player_state.up:
sprite_index=spr_idle_up;
break;

case player_state.down:
sprite_index=spr_idle_down;
break;

case player_state.left:
sprite_index=spr_idle_left;
break;

case player_state.right:
sprite_index=spr_idle_right;
break;
}
}

Information about object: obj_cactus
Sprite: spr_cactus
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:

No Physics Object

Information about object: obj_flag
Sprite: spr_flag
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:

No Physics Object

Information about object: obj_mushroom
Sprite: spr_mushroom
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent: obj_elements_parent
Children:
Mask:

No Physics Object
Information about object: obj_elements_parent
Sprite:
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:

Children
obj_cactus
obj_flag
obj_mushroom
Mask:


No Physics Object

Create Event:
execute code:

instance_create(x,y,obj_solid_base);
depth=-y;

Information about object: obj_solid_base
Sprite: spr_solid_base
Solid: false
Visible: false
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object
Information about object: obj_day_night
Sprite:
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

time=12;
day=1;
alarm[0]=room_speed*2;
Alarm Event for alarm 0:
execute code:

time++;
if time==24
{
time=0;
day++;
}
alarm[0]=room_speed*2;
Draw Event:
execute code:

///drawing
//format and draw text
timestring=string(time);
if string_length(timestring)==1 timestring="0"+timestring;

draw_set_colour(c_white);
draw_text(50,50,"Time "+timestring+":00");
draw_text(250,50,"Day "+string(day));

//draw overlay

draw_set_colour(c_black);
draw_set_alpha(0);
switch (time)
{
case 21:
draw_set_alpha(0.1);
draw_set_colour(c_yellow);
break;

case 22:
draw_set_alpha(0.2);
draw_set_colour(c_orange);
break;

case 23:
draw_set_alpha(0.3);
draw_set_colour(c_blue);
break;

case 0:
draw_set_alpha(0.4);
draw_set_colour(c_dkgray);
break;

case 1:
draw_set_alpha(0.6);
draw_set_colour(c_black);
break;

case 2:
draw_set_alpha(0.8);
draw_set_colour(c_black);
break;

case 3:
draw_set_alpha(0.6);
draw_set_colour(c_black);
break;

case 4:
draw_set_alpha(0.4);
draw_set_colour(c_dkgray);
break;

case 5:
draw_set_alpha(0.3);
draw_set_colour(c_blue);
break;

case 6:
draw_set_alpha(0.2);
draw_set_colour(c_orange);
break;

case 7:
draw_set_alpha(0.1);
draw_set_colour(c_yellow);
break;


}

draw_rectangle(0,0,700,700,false);
//reset alpha
draw_set_alpha(1);

No comments:

Post a Comment