External Exam Download Resources Web Applications Games Recycle Bin

AI


go to resource tree, Options, Main and check the default Game Frames Per Second is still 30:

make asteroid:

put 3 or 4 asteroid objects in room and add Create event:

when asteroids collide with eachother they will change to "broken" sprite for 1 second (i.e. 30 steps):

Alarm 0 and Outside Room (found in Other events) are identical, they both destroy and respawn a new asteroid:

control movement of enemies or obstacles using blocks, alternatively could use paths


Pacman

six objects: objPacman, objEvil, objBlock (for the walls, make sure to set property: solid), objPellet, objScoreDisplay (no sprite), objYouWin (image saying "magnifique")

^^the L, R, D & U sprites for Pacman have 2 subimages, one with mouth closed, the other open

objPacman Create:

image_speed = 0.25;
myScore = 0;

objPacman Step:

if (keyboard_check(vk_left) and place_snapped(32, 32)){
  sprite_index = sprPacL;
  motion_set(180,4);
}

if (keyboard_check(vk_right) and place_snapped(32, 32)){
  sprite_index = sprPacR;
  motion_set(0,4);
}

if (keyboard_check(vk_up) and place_snapped(32, 32)){
  sprite_index = sprPacU;
  motion_set(90,4);
}

if (keyboard_check(vk_down) and place_snapped(32, 32)){
  sprite_index = sprPacD;
  motion_set(270,4);
}

if (keyboard_check(vk_nokey) and place_snapped(32, 32)){
  sprite_index = sprPac;
  motion_set(0,0);
}

if(place_meeting(x + hspeed, y + vspeed, objBlock)){
  move_bounce_solid(true);
  sprite_index = sprPac;
  motion_set(0,0);
  move_snap(32,32); 
}

objPellet Collision (with objPacman):

objPacman.myScore = objPacman.myScore + 1; 
instance_destroy();

if(instance_number(objPellet) == 0){
  instance_create(0,0,objYouWin);
}

objScoreDisplay Create:

total_pellets = instance_number(objPellet);

objScoreDisplay Draw:

draw_set_color(c_black);
draw_text(x,y,string(objPacman.myScore) + " / " + string(total_pellets) +
"collected, " + string(instance_number(objPellet)) + " remaining")

objEvil Step:

if (
  //aggro within a set distance:
  (distance_to_object(objPacman)<=100) and 
  
  //check whether any objects collide with a given line, and return the 'id' of the object if there is:
  (collision_line(x,y,objPacman.x,objPacman.y,objBlock,false,true) == noone) and 
  //^^ so my ghost cant see pacman through walls..
  
  //stick to grid based movement:
  (place_snapped(32, 32))
  
){
    //if the above conditions are all true, do this:
    chaseDirection = point_direction(x,y,objPacman.x,objPacman.y);
    if(chaseDirection > 315) or (chaseDirection < 45) motion_set(0, 2);
    if(chaseDirection > 45) and (chaseDirection < 135) motion_set(90, 2);
    if(chaseDirection > 135) and (chaseDirection < 225) motion_set(180, 2);
    if(chaseDirection > 225) and (chaseDirection < 315) motion_set(270, 2);
}

//bounce off solid walls:
if(place_meeting(x + hspeed, y + vspeed, objBlock)){
  move_bounce_solid(true);
}