Тема: 3D куб!
Показать сообщение отдельно
Старый 26.12.2005, 21:07   #1
Red Ninja
 
Сообщений: n/a
Ответ на 3D куб PAX!
Написано всё понятным языком!

program NewProject;
var i,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8 :integer;
modD,trafD:integer;

Procedure Rect(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8:integer);
begin
 SetColor(0,0,0);
 {Передний квадрат }
 DrawLine(x1,y1,x2,y2);
 DrawLine(x2,y2,x3,y3);
 DrawLine(x3,y3,x4,y4);
 DrawLine(x4,y4,x1,y1);
 {Задний квадрат }
 DrawLine(x5,y5,x6,y6);
 DrawLine(x6,y6,x7,y7);
 DrawLine(x7,y7,x8,y8);
 DrawLine(x8,y8,x5,y5);
 {Соединение квадратов}
 DrawLine(x1,y1,x5,y5);
 DrawLine(x2,y2,x6,y6);
 DrawLine(x3,y3,x7,y7);
 DrawLine(x4,y4,x8,y8);
end;

Procedure Key;
var keyAction:integer;
begin
 keyAction := keyToAction(getKeyClicked);
 
 if modD=1 then 
 begin
  if keyAction = GA_UP  then y1:=y1-1;
  if keyAction = GA_RIGHT then x1:=x1+1;
  if keyAction = GA_DOWN then y1:=y1+1;
  if keyAction = GA_LEFT then x1:=x1-1;
 end;
 
 if modD=2 then 
 begin
  if keyAction = GA_UP  then y2:=y2-1;
  if keyAction = GA_RIGHT then x2:=x2+1;
  if keyAction = GA_DOWN then y2:=y2+1;
  if keyAction = GA_LEFT then x2:=x2-1;
 end;
 
 if modD=3 then 
 begin
  if keyAction = GA_UP  then y3:=y3-1;
  if keyAction = GA_RIGHT then x3:=x3+1;
  if keyAction = GA_DOWN then y3:=y3+1;
  if keyAction = GA_LEFT then x3:=x3-1;
 end;
 
 if modD=4 then
 begin 
  if keyAction = GA_UP  then y4:=y4-1;
  if keyAction = GA_RIGHT then x4:=x4+1;
  if keyAction = GA_DOWN then y4:=y4+1;
  if keyAction = GA_LEFT then x4:=x4-1;
 end;
 
 if modD=5 then
 begin 
  if keyAction = GA_UP  then y5:=y5-1;
  if keyAction = GA_RIGHT then x5:=x5+1;
  if keyAction = GA_DOWN then y5:=y5+1;
  if keyAction = GA_LEFT then x5:=x5-1;
 end;
 
 if modD=6 then
 begin 
  if keyAction = GA_UP  then y6:=y6-1;
  if keyAction = GA_RIGHT then x6:=x6+1;
  if keyAction = GA_DOWN then y6:=y6+1;
  if keyAction = GA_LEFT then x6:=x6-1;
 end;
 
 if modD=7 then
 begin 
  if keyAction = GA_UP  then y7:=y7-1;
  if keyAction = GA_RIGHT then x7:=x7+1;
  if keyAction = GA_DOWN then y7:=y7+1;
  if keyAction = GA_LEFT then x7:=x7-1;
 end;
 
 if modD=8 then
 begin 
  if keyAction = GA_UP  then y8:=y8-1;
  if keyAction = GA_RIGHT then x8:=x8+1;
  if keyAction = GA_DOWN then y8:=y8+1;
  if keyAction = GA_LEFT then x8:=x8-1;
 end; 
 
 if keyAction = GA_GAMEC then 
  begin 
  modD:=modD+1; 
   if modD=9 then modD:=1;
  end; 
  if keyAction = GA_GAMED then 
  begin 
  trafD:=trafD+1; 
   if trafD=2 then trafD:=0;
  end;
end;

Procedure Modes;
begin
 SetColor(255, 0, 0); 
 DrawText('Mod='+IntegerToString(modD), 0, 0);
 
 if trafD=0 then DrawText('OFF',(GetWidth - GetStringWidth('OFF')), 0);
 if trafD=1 then DrawText('ON',(GetWidth - GetStringWidth('ON')), 0);
 
 if trafD=1 then
 begin

 if modD=1 then SetColor(255, 0, 0); else SetColor(0, 0, 255);
 DrawText('1',x1-3,y1-3);DrawEllipse(x1-2,y1-2,4,4); 
 if modD=2 then SetColor(255, 0, 0); else SetColor(0, 0, 255); 
 DrawText('2',x2-3,y2-3);DrawEllipse(x2-2,y2-2,4,4); 
 if modD=3 then SetColor(255, 0, 0); else SetColor(0, 0, 255);  
 DrawText('3',x3-3,y3-6);DrawEllipse(x3-2,y3-2,4,4); 
 if modD=4 then SetColor(255, 0, 0); else SetColor(0, 0, 255); 
 DrawText('4',x4-3,y4-6);DrawEllipse(x4-2,y4-2,4,4); 

 if modD=5 then SetColor(255, 0, 0); else SetColor(0, 0, 255);
 DrawText('5',x5-3,y5-3);DrawEllipse(x5-2,y5-2,4,4); 
 if modD=6 then SetColor(255, 0, 0); else SetColor(0, 0, 255); 
 DrawText('6',x6-3,y6-3);DrawEllipse(x6-2,y2-6,4,4); 
 if modD=7 then SetColor(255, 0, 0); else SetColor(0, 0, 255);  
 DrawText('7',x7-3,y7-6);DrawEllipse(x7-2,y7-2,4,4); 
 if modD=8 then SetColor(255, 0, 0); else SetColor(0, 0, 255); 
 DrawText('8',x8-3,y8-6);DrawEllipse(x8-2,y8-2,4,4); 
 end;
end;

Procedure CLS;
begin
 SetColor(255, 255, 255);
 FillRect(0, 0, GetWidth, GetHeight); 
end;

begin
 {Передний Квадрат}
 x1:=35;y1:=35;
 x2:=85;y2:=35;
 x3:=85;y3:=85;
 x4:=35;y4:=85;
 {Задний Квадрат}
 x5:=40;y5:=30;
 x6:=90;y6:=30;
 x7:=90;y7:=70;
 x8:=40;y8:=70;
 
 modD:=1;
 trafD:=0;
 repeat 
 
 Modes;
 Key;
 Rect(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8);
 
 Delay(100);
 Repaint;
 CLS;
	until i=2
end.
Дерзайте
 
Ответить с цитированием