Pac-man like Lives System

Game Editor comments and discussion.

Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 7:29 am

I'm making a pac-man game, and I need a lives counter where the lives are represented by little pac-men. Now I can't figure out how to make one of these images disappear when the appropriate amount of lives are depleted. IE: two lives are lost, two images disappear.
Anyone's help would be appreciated :mrgreen:
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 8:24 am

You could create an animation, much like how you would do an hp bar (since that is all it is). Something like this. That way you can set animpos equal to hp.
Attachments
pacman_hp.png
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 8:37 am

Didn't think about that. That works. :mrgreen: Also, I'm having real difficulties with the ghosts AI. How could I make it so they ghosts go around the walls, in a mostly random pattern, but if they come closish to pac-man, they start chasing him?
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 9:01 am

Well, do you know how to make them move around randomly and also move towards the player? If so then all you need to do is use an if statement to check if the player is near.
Code: Select all
if(distance(x, y, player.x, player.y)<200)
{
    // move to player
}
else
{
    // move randomly
}

Or do you also need help with either/or?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 9:16 am

I have no clue how to do either of those things :oops:
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 9:25 am

Well, there are several ways to do it, but none of them I would say are particularly easy. Here is an example I made for another user. It uses shortest path computations via a grid. The code I think was pretty well documented, but it uses some slightly advanced stuff. Another approach is to use a node based decision system (where when a ghost reaches a node it picks the direction closest to the player, or one at random). That might be slightly easier for you. Either way, here's the file.
Attachments
pacman.zip
(81.65 KiB) Downloaded 118 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 10:12 am

Ya, that demo made little to no sense. What's this node thing you mentioned before?
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 10:27 am

The idea is that you have your map, and at every intersection, you have an actor of some type (most likely some invisible actor). If I were to use this system, I would give them animations to show what type of paths are available, as in from that position can the player move right/left/up/down. Then when the actor collides with it, it sets the xvelocity and yvelocity appropriately (you can use random setting or directed).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 10:52 am

I will try this out in the morning. But, before I go to bed, how would I make it random?
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 10:58 am

Well, each node would have a certain number of possible paths. The most choices would be a 4-way intersection. But the ghost is limited to only 3 choices, as it can't move backwards (same direction it came from). So you need to have a variable to determine which direction it is going, and then find a random number (each number represents a direction) that works.
Code: Select all
int previous_dir=dir;
do
{
    dir=rand(4);
}while(dir==(previous_dir+2)%4);

The (previous_dir+2)%4 just gets the opposite of the previous direction, so that it won't go backwards (since the loop will continue).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby phyzix5761 » Sat Dec 24, 2011 4:10 pm

Just a note. In the original pac-man 1 ghost is chasing the player, 1 ghost is chasing 20 pixels in front of the player, 1 ghost is chasing one of the other ghosts and the 4th ghost is chasing a random point in the map.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 7:29 pm

So could I make them move relative to the player? Also, do I put that code into the ghosts, or the nodes? Or where? Is it a collision event? I'm really confused :?
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 8:18 pm

It would be in the ghost's collision event with the node. So I'm guessing you don't get the idea behind it? If so do tell, and I can explain it further. But, here's what it should generally look like.
Attachments
pacman_nodes.zip
(16.21 KiB) Downloaded 104 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pac-man like Lives System

Postby GuybrushThreepwood » Sat Dec 24, 2011 10:35 pm

Oooohhhhh ok. This makes perfect sense. So, could I have maybe like a region relative to my pac-man where if the ghost is in it, would pick the path closest to the player? If so, how would I go about doing that? Or is that already scripted into your demo?
Pirate: You fight like a diary farmer!
Guybrush: How appropriate, you fight like a cow!
User avatar
GuybrushThreepwood
 
Posts: 94
Joined: Sun Jul 06, 2008 12:23 pm
Location: Melee Island
Score: 2 Give a positive score

Re: Pac-man like Lives System

Postby skydereign » Sat Dec 24, 2011 10:46 pm

I didn't make the move to the player part, but you would put that code into the decision making (collision event).
Code: Select all
if(distance(x,y,player.x,player.y)<200)
{
    // code that determines direction to move in
}
else
{
    // code that is already in the collision event (random choice)
}

This won't technically be a perfect way of chasing the player since your level could have a wall divide, but generally you can use if the angle to the player as a way of determining which direction to go. Of course you'll need to use the same idea as the random selection, namely preventing directions that it is not allowed to move at.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Next

Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest