PercyPierce
Member
Ok, so you guys know that Rats! game where you are using bombs, gas, sterilizers in order to keep the rat population down and eliminate them all before they overwhelm you and you lose the game right?
Well, I had a lot of fun with that game, and I want to RE-Create that game and adjust it to MY tastes.
Right now I have some squares (masks for the rats. Don't have sprites for the rats yet) that are able to move around a maze. It can pick one of four directions whenit gets to an intersection a certain variable that counts down reaches zero.
I will show you my code real quick.
I apologize if I'm using too many screens as of course gml requires you to split codes for objects in tothings like create step alarm draw, and such.
ok, my problem with this code is that it's RARE for the rat to make its way to the middle of the level. They seem to love hanging around on the edge of the level.
even though that's quite typical for rats, I want my level to be HARDer and I would rather it not be easy to wipe all the rodents out with one or two bombs that would clear an entire line.
is it possible for anybody to help me program the rats so that they would turn more often where there is the option to keep straight or turn left or right?
Well, I had a lot of fun with that game, and I want to RE-Create that game and adjust it to MY tastes.
Right now I have some squares (masks for the rats. Don't have sprites for the rats yet) that are able to move around a maze. It can pick one of four directions when
I will show you my code real quick.
I apologize if I'm using too many screens as of course gml requires you to split codes for objects in tothings like create step alarm draw, and such.
GML:
//obj_rat create event
dir=choose(90,180,270,0); //0° is right, 90° is up, 180° is left and 270° is down.
ptm = -1; //path to move. this is counted down in order to keep a direction. then check and see if there is an opening in
//front or on the sides of it.
GML:
//obj_rat begin step
if ptm == 0
{
dir=choose(90,180,270,0); //0° is right, 90° is up, 180° is left and 270° is down.
choosepath(x,y); // this is a user defined function that creates another object that determines how many spaces the rat should move before deciding to change direction.
alarm[0] = 60;
}
if ptm > 0
{
switch (dir)
{
case 90: { if !place_meeting(x,y-1,obj_wall) {y-=mspeed; ptm -= mspeed;} if place_meeting(x,y-1,obj_wall) {ptm = 0;} break;}
case 180: { if !place_meeting(x-1,y,obj_wall) {x-=mspeed; ptm -= mspeed;} if place_meeting(x-1,y,obj_wall) {ptm = 0;} break;}
case 270: { if !place_meeting(x,y+1,obj_wall) {y+=mspeed; ptm -= mspeed;} if place_meeting(x,y+1,obj_wall) {ptm = 0;} break;}
case 0: {if !place_meeting(x+1,y,obj_wall) {x+=mspeed; ptm -= mspeed;} if place_meeting(x+1,y,obj_wall) {ptm = 0;} break;}
}
}
GML:
//script choosepath
function choosepath(x,y){
pathchooser = instance_create_layer(x,y,layer,obj_rat_pathchooser);
}
GML:
// obj_rat_pathchooser create event
belongto = instance_place(x,y,obj_rat); // this is here to add a number to the
//object instance that created it. it's not perfect of course, as what if the
//obj_rat.ptm becomes 0 and there are TWO rats overlapping eachother and
//this object is created?
dir = belongto.dir; //direction. I am afraid of the "black box" brought on by
//built in variables.
spacesmoved = 0; //this is determined by how many multiples of 32 this object
//has moved before it reached a wall.
switch (dir) //0° is right, 90° is up, 180° is left and 270° is down.
{
case 90: {movespaces(0,-32,0,-1);} break;
case 180: {movespaces(-32,0,-1,0);} break;
case 270: {movespaces(0,32,0,1);} break;
case 0: {movespaces(32,0,1,0);} break;
}
belongto.ptm = 32*irandom_range(1,spacesmoved);
belongto.cancreate = true;
instance_destroy();
GML:
//the move spaces function
function movespaces(xadd,yadd,xnext,ynext){
do {x+=xadd; y+=yadd; spacesmoved += 1;} until (place_meeting(x+xnext,y+ynext,obj_wall));
if spacesmoved <= 1 && place_meeting(x+xnext,y+ynext,obj_wall)
{
with (belongto) {ptm = 0;}
instance_destroy();
}
}
ok, my problem with this code is that it's RARE for the rat to make its way to the middle of the level. They seem to love hanging around on the edge of the level.
even though that's quite typical for rats, I want my level to be HARDer and I would rather it not be easy to wipe all the rodents out with one or two bombs that would clear an entire line.
is it possible for anybody to help me program the rats so that they would turn more often where there is the option to keep straight or turn left or right?
Last edited: