Pac-Man Movements

TheouAegis

Member
The code didn't work so well. All it did was jumbled all the ghosts and Pac-Man together and pretty much ruined their movements.

Woops! Yeah that was bad logic. I wrote that while walking. Try this one.
Code:
with all {
if hspeed !=0 and position_meeting(xprevious,yprevious,other.id) and !position_meeting(x,y,other.id) {
    x = other.myPair.x + hspeed;
    y = other.myPair.y;
}
else
if vspeed != 0 && position_meeting(xprevious,yprevious,other.id) and !position_meeting(x,y,other.id) {
    y = other.myPair.y + vspeed;
    x = other.myPair.x;
}
}
 
Q

Qing Donnie Yoshi

Guest
Woops! Yeah that was bad logic. I wrote that while walking. Try this one.
Code:
with all {
if hspeed !=0 and position_meeting(xprevious,yprevious,other.id) and !position_meeting(x,y,other.id) {
    x = other.myPair.x + hspeed;
    y = other.myPair.y;
}
else
if vspeed != 0 && position_meeting(xprevious,yprevious,other.id) and !position_meeting(x,y,other.id) {
    y = other.myPair.y + vspeed;
    x = other.myPair.x;
}
}
OK getting better results,now back to the instance ID. Since there's 2 objects on each end of the tunnels shouldn't I put both of their Inst ID in as a ref for "myPair" in the create event?
 

Nidoking

Member
OK getting better results,now back to the instance ID. Since there's 2 objects on each end of the tunnels shouldn't I put both of their Inst ID in as a ref for "myPair" in the create event?
No. Each one knows its own ID, so why would you need to add it? It only needs to know the ID of the other teleporter instance. That's what "myPair" is - the ID of the teleporter at the far end.
 
Q

Qing Donnie Yoshi

Guest
No. Each one knows its own ID, so why would you need to add it? It only needs to know the ID of the other teleporter instance. That's what "myPair" is - the ID of the teleporter at the far end.
Because just having the other instance ID alone causes Pac to get stuck...
 

Nidoking

Member
Because just having the other instance ID alone causes Pac to get stuck...
It's not the instance ID that's wrong. I suspect that the place where you're moving Pac to is on top of the other teleporter, and he's just moving back and forth. You'll probably have to offset the destination x or y based on the bounding box of the teleporter, unless your hspeed and vspeed are at least the size of Pac himself.
 
Q

Qing Donnie Yoshi

Guest
It's not the instance ID that's wrong. I suspect that the place where you're moving Pac to is on top of the other teleporter, and he's just moving back and forth. You'll probably have to offset the destination x or y based on the bounding box of the teleporter, unless your hspeed and vspeed are at least the size of Pac himself.
It might be the code because the one Pac kept getting stuck in I went straight to it first and it just get completely stick while the other one that's basically the first instance is working fine since Pac approaches it and instantly goes to the second instance.
 

TheouAegis

Member
OK, no more typing crap up on my phone. The logic error was essentially the same as last time. So now i'm just going to stick with the maze dimensions. I got distracted by the teleporter object. So use this in the teleporter object instead:

Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x
        x += maze_width * sign(hspeed);
    else
    if median(y,maze_top,maze_bottom) != y
        y += maze_height * sign(vspeed);
}
What it will do is check if any instance is colliding with the teleporter but halfway outside the maze. It will then just teleport the instance to the other side of the maze. This is your basic Pac-man layout. Since it's just based on the maze dimensions, you don't need myPair anymore.

If you want the teleporter to send Pac-man or the ghosts somewhere other than just on the opposite side of the maze, then you'd use something like
Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x {
        x = other.myPair.x + hspeed;
        y = other.myPair.y;
    }
    else
    if median(y,maze_top,maze_bottom) != y {
        x = other.myPair.x;
        y = other.myPair.y + hspeed;
    }
}
 
Q

Qing Donnie Yoshi

Guest
OK, no more typing crap up on my phone. The logic error was essentially the same as last time. So now i'm just going to stick with the maze dimensions. I got distracted by the teleporter object. So use this in the teleporter object instead:

Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x
        x += maze_width * sign(hspeed);
    else
    if median(y,maze_top,maze_bottom) != y
        y += maze_height * sign(vspeed);
}
What it will do is check if any instance is colliding with the teleporter but halfway outside the maze. It will then just teleport the instance to the other side of the maze. This is your basic Pac-man layout. Since it's just based on the maze dimensions, you don't need myPair anymore.

If you want the teleporter to send Pac-man or the ghosts somewhere other than just on the opposite side of the maze, then you'd use something like
Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x {
        x = other.myPair.x + hspeed;
        y = other.myPair.y;
    }
    else
    if median(y,maze_top,maze_bottom) != y {
        x = other.myPair.x;
        y = other.myPair.y + hspeed;
    }
}
OK and what do I put to define Maze_top, Maze_Bottom, Maze_left, and Maze_right? it does look like I have to define those, do I put the maze name?
 
Q

Qing Donnie Yoshi

Guest
OK so the create event for the Warp Tunnels (I'm calling them that now since it sounds much better) should look like this when defining them right?
Code:
maze_left = 256;
maze_right = 1344;
maze_top = 32;
maze_bottom = 1216;
maze_width = 896;
maze_height =992;
Also this error had just occurred when I ran it. Idk why it's trying to do this with boarder when it's specifically for the maze.
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event2
for object obj_Warp_Tunnel:

Variable obj_Boarder_1.maze_right(100015, -2147483648) not set before reading it.
at gml_Object_obj_Warp_Tunnel_Step_2 (line 2) - if median(x,maze_left,maze_right) != x
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_Warp_Tunnel_Step_2 (line 2)[/code]
 
Last edited by a moderator:

Nidoking

Member
If those variables are defined in the obj_Warp_Tunnel, you'll need to use other.maze_right (etc.) to get the variables from it within a with block.

But it might make more sense to make those global variables anyway, since they're not going to change from teleporter to teleporter.
 

TheouAegis

Member
Yeah, what Nido said. What's obj_Boarder? lol Probably hast to do with the "with all"...but that means obj_Boarder, whatever it is, is actually overlapping obj_Warp_Tunnel. The sprite for obj_Warp_Tunnel should be just the right size so it fits inside the tunnel without touching anything so that only Pac-Man and the ghosts can ever touch it.
 
Q

Qing Donnie Yoshi

Guest
obj_boarder was the boarders on the side of the maze that has all the illustrations of Pac and other stuff like the ones from the old Namco Museum games. what I was planning on doing was find a way to for the boarders to follow Pac as he moving because I'm planning on adding mazes that requires the camera to scroll along with him. BUT hearing that now I'm gonna have to either change the obj up in a different way or delete it for now.
 
Q

Qing Donnie Yoshi

Guest
Yeah, what Nido said. What's obj_Boarder? lol Probably hast to do with the "with all"...but that means obj_Boarder, whatever it is, is actually overlapping obj_Warp_Tunnel. The sprite for obj_Warp_Tunnel should be just the right size so it fits inside the tunnel without touching anything so that only Pac-Man and the ghosts can ever touch it.
OK so I changed the boarders from Objects to Tiles and ran the program for a test and I got the same result from before except it's with Pac as you can see

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event2
for object obj_Warp_Tunnel:

Variable obj_Player_1.maze_right(100015, -2147483648) not set before reading it.
at gml_Object_obj_Warp_Tunnel_Step_2 (line 2) - if median(x,maze_left,maze_right) != x
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_Warp_Tunnel_Step_2 (line 2)
The code you gave me is still the same as before and I tried to define the variables the best I can in the create event

End Step:
Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x
        x += maze_width * sign(hspeed);
    else
    if median(y,maze_top,maze_bottom) != y
        y += maze_height * sign(vspeed);
}
Create:
Code:
maze_left = 256;
maze_right = 1344;
maze_top = 32;
maze_bottom = 1216;
maze_width = 896;
maze_height =992;
 

TheouAegis

Member
Make maze_left through maze_height macros. It should be a simple change (don't use any punctuation):

#macro maze_left = 256
#macro maze_right = 1344
#macro maze_top = 32
#macro maze_bottom = 1216
#macro maze_width = 896
#macro maze_height = 992

Since those numbers will be "hard-coded", there is no point making them be variables. By declaring them as macros like this, the game will replace all references of maze_left with 256, maze_right with 1344, and so on.
 
Q

Qing Donnie Yoshi

Guest
Make maze_left through maze_height macros. It should be a simple change (don't use any punctuation):

#macro maze_left = 256
#macro maze_right = 1344
#macro maze_top = 32
#macro maze_bottom = 1216
#macro maze_width = 896
#macro maze_height = 992

Since those numbers will be "hard-coded", there is no point making them be variables. By declaring them as macros like this, the game will replace all references of maze_left with 256, maze_right with 1344, and so on.
now these errors are occurring. I tried to fix it by putting in what it was asking for but it's still not working

Object: obj_Warp_Tunnel Event: Create at line 1 : unexpected symbol "=" in expression
Object: obj_Warp_Tunnel Event: Create at line 1 : got '=' expected ',' or ')'
Object: obj_Warp_Tunnel Event: Create at line 1 : got '=' expected ')'
Object: obj_Warp_Tunnel Event: Create at line 1 : unexpected symbol "=" in expression
Object: obj_Warp_Tunnel Event: Create at line 1 : malformed assignment
Object: obj_Warp_Tunnel Event: End Step at line 2 : malformed if statement
 
Q

Qing Donnie Yoshi

Guest
show your code
End Step
Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x
        x += maze_width * sign(hspeed);
    else
    if median(y,maze_top,maze_bottom) != y
        y += maze_height * sign(vspeed);
}
Create
Code:
#macro maze_left = 256
#macro maze_right = 1344
#macro maze_top = 32
#macro maze_bottom = 1216
#macro maze_width = 896
#macro maze_height = 992
 
Q

Qing Donnie Yoshi

Guest
OK now it's working but the end step code still needs tweaking, all it's doing is shooting Pac and the ghosts to the far edge of the room instead of to the other warp tunnel.
 

Attachments

Q

Qing Donnie Yoshi

Guest
OK now it's working but the end step code still needs tweaking, all it's doing is shooting Pac and the ghosts to the far edge of the room instead of to the other warp tunnel.
Yeah, Tried to make the coordinates for the edge of the maze smaller, that didn't work.I tried to swap all the coordinates around with Left's being Right's and Top's being Bottom's and so on, that didn't work. I moved the Warps closer to the tunnel end as well as the coordinates, that didn't work. I don't exactly know what to do because all the Warp Tunnel is doing is send Pac and the ghosts right outside the screen.
The code is pretty much how you sent it to me minus me trying to find a way to fix the problem:
End STEP
Code:
with all if place_meeting(x,y,other.id) {
    if median(x,maze_left,maze_right) != x
        x += maze_width * sign(hspeed);
    else
    if median(y,maze_top,maze_bottom) != y
        y += maze_height * sign(vspeed);
}
Create
Code:
#macro maze_left 256
#macro maze_right 1344
#macro maze_top 32
#macro maze_bottom 1216
#macro maze_width 896
#macro maze_height 992
 

TheouAegis

Member
The only variable that would make it do that is maze_width, which should be the distance from where your pink arrow is to just left of where your X is in that picture.
 
Q

Qing Donnie Yoshi

Guest
The only variable that would make it do that is maze_width, which should be the distance from where your pink arrow is to just left of where your X is in that picture.
OK so I figured out the solution... I just had to add a - to the Maze_width... why is it always the minus sign??
 
Last edited by a moderator:
Q

Qing Donnie Yoshi

Guest
Qeustion: Is it possible for me to use switch as a means to alternate Pac-Man's Chomping sound?
 
Q

Qing Donnie Yoshi

Guest
So I've been trying things and I've not been having much luck. I feel like this line of code should work if put together correctly, I just need a lil' help doing so
Code:
if audio_play_sound(Pac_Man_Eat_1,10,0)
else 
if audio_play_sound(Pac_Man_Eat_2,10,0)
 

Nidoking

Member
if something audio_play_sound(Pac_Man_Eat_1,10,0)
else audio_play_sound(Pac_Man_Eat_2,10,0)

You just need to figure out the something. A very basic tutorial on GML would be advisable. Or just read the Manual.
 
Q

Qing Donnie Yoshi

Guest
OK so I've went with this since the Pac-Man is basically destroying the Pac-dots. the code seems to work at first but now as soon as the game starts Pac-Man disappears and the game crashes.
Code:
if instance_destroy() audio_play_sound(Pac_Man_Eat_1,10,0)
else if instance_destroy() audio_play_sound(Pac_Man_Eat_2,10,0)
 

Nidoking

Member
I don't know how you went from reading a basic tutorial to thinking instance_destroy() was the thing you wanted to put into the if. I really don't know how you fail to see the connection between calling instance_destroy and your instance being destroyed. Read the tutorials. Read all the tutorials. Read every tutorial you can find. Please.
 
Q

Qing Donnie Yoshi

Guest
I've returned with great news. After finding so many ways to get the code i need to work and after help from someone who's an expert in coding I can safely say that Pac-Man's waka waka sound can now alternate like the original.
 
Q

Qing Donnie Yoshi

Guest
The only variable that would make it do that is maze_width, which should be the distance from where your pink arrow is to just left of where your X is in that picture.
So with that out of the way I wanna try to tackle the idea of Pacs as or Bots. you mentioned that they can pretty much have the same line of code as the ghosts right? All i have to do is add a code that would have them avoid the ghost until a power pellet is active and can start chasing them?
 

TheouAegis

Member
So with that out of the way I wanna try to tackle the idea of Pacs as or Bots. you mentioned that they can pretty much have the same line of code as the ghosts right? All i have to do is add a code that would have them avoid the ghost until a power pellet is active and can start chasing them?
Yes, if you want the AI to actually chase the ghost. (You could make an AI that aims for ghosts when it has the power pellet and make a different AI that treats pellets as just an invincibility token and uses that time to just continue getting normal pills instead of aiming for points).

You'll want multiple AI goals for handling Pacman AI movement. For example, you probably wouldn't want him running to a power pellet right away, so if his current route puts him on a collision course with a power pellet, you'd want him to look for an alternate route. Since Pac-man can change direction at any time, unlike ghosts, you might want some form of motion planning. For example, maybe calculate a path for 8 or 16 cells and save the direction he plans to go in each of those cells to an array, then attempt to loop through the array as long as no ghosts are coming for him. If Pac-man AI detects a ghost coming for him, clear the array and calculate a new path.

Ghosts have very simple AI. Since Pac-man's AI would want to simulate human movement, it's much more difficult to program. So yes, the coding methods will be about the same as with the ghosts, but it will take a lot more planning.
 
Q

Qing Donnie Yoshi

Guest
Yes, if you want the AI to actually chase the ghost. (You could make an AI that aims for ghosts when it has the power pellet and make a different AI that treats pellets as just an invincibility token and uses that time to just continue getting normal pills instead of aiming for points).

You'll want multiple AI goals for handling Pacman AI movement. For example, you probably wouldn't want him running to a power pellet right away, so if his current route puts him on a collision course with a power pellet, you'd want him to look for an alternate route. Since Pac-man can change direction at any time, unlike ghosts, you might want some form of motion planning. For example, maybe calculate a path for 8 or 16 cells and save the direction he plans to go in each of those cells to an array, then attempt to loop through the array as long as no ghosts are coming for him. If Pac-man AI detects a ghost coming for him, clear the array and calculate a new path.

Ghosts have very simple AI. Since Pac-man's AI would want to simulate human movement, it's much more difficult to program. So yes, the coding methods will be about the same as with the ghosts, but it will take a lot more planning.
So I just realized that if I'd want the AI thing to work we need the ghosts to turn blue and we don't have that done yet. I think I wanna get that done first as well as other functions for the ghost before moving on to the Pac AIs. so where do I begin with the Power Pellet effect?
 
Q

Qing Donnie Yoshi

Guest
Yes, if you want the AI to actually chase the ghost. (You could make an AI that aims for ghosts when it has the power pellet and make a different AI that treats pellets as just an invincibility token and uses that time to just continue getting normal pills instead of aiming for points).

You'll want multiple AI goals for handling Pacman AI movement. For example, you probably wouldn't want him running to a power pellet right away, so if his current route puts him on a collision course with a power pellet, you'd want him to look for an alternate route. Since Pac-man can change direction at any time, unlike ghosts, you might want some form of motion planning. For example, maybe calculate a path for 8 or 16 cells and save the direction he plans to go in each of those cells to an array, then attempt to loop through the array as long as no ghosts are coming for him. If Pac-man AI detects a ghost coming for him, clear the array and calculate a new path.

Ghosts have very simple AI. Since Pac-man's AI would want to simulate human movement, it's much more difficult to program. So yes, the coding methods will be about the same as with the ghosts, but it will take a lot more planning.
Hey sorry to bother but I was just wondering if you're still gonna help me out with the coding?
 

TheouAegis

Member
Figuring out the AI is the job of the programmer. We have been giving you the basics for the AI for a ghost. Anything beyond that is up to you. This thread is as long as it is because, as far as most of the people that have been following it with us can tell, I've been practically writing your entire program for you. And maybe a couple other people near the beginning. Mama bird has to push the chick out of the nest at some point.
 
Q

Qing Donnie Yoshi

Guest
Figuring out the AI is the job of the programmer. We have been giving you the basics for the AI for a ghost. Anything beyond that is up to you. This thread is as long as it is because, as far as most of the people that have been following it with us can tell, I've been practically writing your entire program for you. And maybe a couple other people near the beginning. Mama bird has to push the chick out of the nest at some point.
I understand. Thank you for all the help you provided me through the thread. And if anything I hope you're interested in the progress once i post some. :)
 
Top