Imerion
Member
- Joined
- Feb 24, 2005
- Messages
- 218
I am currently working on an overhead Micro Machines-style racer for GP2X and Dreamcast. However, I can't get AI-cars to work well. I was thinking about using points on the track which the ai-cars would follow. Simply checking for the next point, rotate the car towards it and make it go there. But it wont work. Also, the cars will not make a smooth turn. I might be able to fix that though. But what I wonder is, how to I make the cars follow points set on the map? This is my current code : I have a process called aicar which will do that.
	
	
	
		
Any help with that is appreciated. If you want to test it, the graphicsfile can be found here : http://www.freewebtown.com/Imerion/racer.fpg
Please note that most of that graphics is temporal and will be replaced with better looking stuff.
				
			
		Code:
	
	program racer ;
global
rot;
col;
acc;
lap;
lc=1;
armor;
endrace;
anim;
finish;
finish2;
rot2;
acc2;
armor2;
second=0;
lc2;
lap2;
endrace2;
spa;
point=0;
pointx;
pointy;
begin
timer=0;
set_mode(640,480,8);
load_fpg("scroll.fpg");
coll();
goal();
check();
arm();
arm2();
car(160,120);
aicar(160,160);
lamp(747,250);
lamp(282,250);
lamp(748,488);
lamp(282,488);
end
process car(x,y)
begin
graph=2;
z=1;
start_scroll(0,0,3,0,0,0);
scroll.camera=id;
ctype=c_scroll;
write_int(0,160,20,0,&lap);
write_int(0,160,40,0,&second);
loop
    frame;
    timer++;
    if (timer>100)
      timer=0;
      second++;
    end
    if (rot==360000)
      rot=0;
    end
    if (rot==-360000)
      rot=0;
    end
    angle=rot;
    if (key(_control))
      acc=acc+2;
      if (acc>14)
        acc=14;
      end
    end
    if (acc>0)
      acc=acc-1;
      advance(acc);
      if(COLLISION(type coll));
        advance(-acc-6);
        armor=armor+1;
        spark(x,y,1,rot);
        spark(x,y,2,rot);
        spark(x,y,3,rot);
        spark(x,y,4,rot);
      end
    end
    if (key(_right))
      rot=rot-5000;
      if(COLLISION(type coll));
        rot=rot+7000;
      end
      if(COLLISION(type coll));
        advance(-acc-6);
        armor=armor+1;
        spark(x,y,1,rot);
        spark(x,y,2,rot);
        spark(x,y,3,rot);
        spark(x,y,4,rot);
      end
    end
    if (key(_left))
      rot=rot+5000;
      if(COLLISION(type coll));
        rot=rot-7000;
      end
      if(COLLISION(type coll));
        advance(-acc-6);
        armor=armor+1;
        spark(x,y,1,rot);
        spark(x,y,2,rot);
        spark(x,y,3,rot);
        spark(x,y,4,rot);
      end
    end
    if(COLLISION(type goal));
      if (lc==1)
        lap=lap+1;
        lc=2;
      end
    end
    
    if(COLLISION(type check));
        lc=1;
    end
    
    if (armor>15 and endrace==0)
      explode(x,y);
      endrace=1;
      break;
    end
    
    if (lap==5)
      finish=1;
      break;
    end
end
end
process aicar(x,y)
begin
graph=2;
ctype=c_scroll;
loop
frame;
get_point(0,3,point,&x,&y);
end
end
process coll();
begin
z=2;
ctype=c_scroll;
x=512;
y=384;
graph=3;
loop
frame;
end
end
process goal();
begin
z=2;
ctype=c_scroll;
x=500;
y=150;
graph=1;
loop
frame;
end
end
process check();
begin
ctype=c_scroll;
x=505;
y=595;
graph=4;
loop
frame;
end
end
process lamp(x,y);
begin
ctype=c_scroll;
flags=4;
graph=5;
loop
frame;
end
end
process explode(x,y);
begin
anim=0;
ctype=c_scroll;
repeat
 graph=6+anim;
 anim=anim+1;
 frame;
until (anim==9)
end
process arm();
begin
graph=16;
y=0;
loop
x=-10*armor;
frame;
end
end
process arm2();
begin
graph=17;
y=0;
x=0;
loop
frame;
end
end
process spark(x,y,t,ang);
begin
graph=19;
angle=ang;
advance(24);
spa=0;
repeat
spa=spa+1;
if (t==1)
x=x+4;
y=y+4;
end
if (t==2)
x=x+4;
y=y-4;
end
if (t==3)
x=x-4;
y=y+4;
end
if (t==4)
x=x-4;
y=y-4;
end
frame;
until (spa==30)
endAny help with that is appreciated. If you want to test it, the graphicsfile can be found here : http://www.freewebtown.com/Imerion/racer.fpg
Please note that most of that graphics is temporal and will be replaced with better looking stuff.
 
	
 
 
		 
 
		 
 
		 
 
		