Tacostronk's profile picture

Published by

published

Category: Games

My progress making Pac-Man in Game Maker 8.0

I am making a Pac-Man Game on Game Maker 8.0

While I balance trying to work a cartoon about Pac-Man. I also decided to make a game to kill off some time because I of course enjoyed playing Pac-Man as a kid. I often went on flash game sites to play these games. So I took matters into my own hands and began making one. It's quite simple until you get into the ghost AI.

Difficulties in the Ghost AIs

It was a pain in the butt trying to make two perfect ghost AI 
  1. One of the AIs is to move randomly throughout the maze without reversing direction. If the ghost hits a wall and one direction is free, it must take the direction.
  2. A ghost AI that actively chases Pac-Man
For the chasing AI. I had to borrow a tutorial and analyze how the Ghost decided which way to go to get to Pac-Man without reversing. The built in AI (Motion Planning) was just too much baloney. I had to create a grid and cells, and the Ghost cut corners through the walls when reaching Pac-Man, it was quite accurate at finding Pac-Man....but it reversed direction.

Watch this for a tutorial on Pac-Man Ghost AI in Game-Maker (Made by Bradley Sward (NOT ME) )

Here is the code for Blinky's chasing AI from the tutorial

if sprite_index = spr_blinky 
{
speed = 4
distance_to_pacman = 9999999
new_direction = -1
//check up
if direction != 270
{
    if !place_meeting(x,y-4,obj_wall) 
    {
        dist = point_distance(x,y-32,obj_pacman.x,obj_pacman.y)
        if dist < distance_to_pacman
        {
            new_direction = 90;
            distance_to_pacman = dist;
        }
    }
}
//check down
if direction != 90
{
    if !place_meeting(x,y+4,obj_wall) 
    {
        dist = point_distance(x,y+32,obj_pacman.x,obj_pacman.y)
        if dist < distance_to_pacman
        {
            new_direction = 270;
            distance_to_pacman = dist;
        }
    }
}
//check right
if direction != 180
{
    if !place_meeting(x+4,y,obj_wall) 
    {
        dist = point_distance(x+32,y,obj_pacman.x,obj_pacman.y)
        if dist < distance_to_pacman
        {
            new_direction = 0;
            distance_to_pacman = dist;
        }
    }
}
//check rightw
if direction != 0
{
    if !place_meeting(x-4,y,obj_wall) 
    {
        dist = point_distance(x-32,y,obj_pacman.x,obj_pacman.y)
        if dist < distance_to_pacman
        {
            new_direction = 180;
            distance_to_pacman = dist;
        }
    }
}

if new_direction != -1
{
    direction = new_direction
}
}

It checks a space on whichever possible direction there is and measures the distance between that space and Pac-Man, the space with shortest distance will be the direction it will choose to go to.

Other interesting things I implemented

As I conclude this post, I would like to add certain things I implemented. I added a way where the eyes go back to their spawning position, it uses the same code as the chasing AI, but the eyes follow the spawning object. I added exclusive features such as barriers that only the ghosts or Pac-Man can pass through (it is color-coded). I plan to add some power-ups and add some twists such as skins, bonus levels and create a separate game where you play as a Ghost trying to get Pac-Man.


0 Kudos

Comments

Displaying 0 of 0 comments ( View all | Add Comment )