AnyKey`щик
Регистрация: 14.11.2012
Сообщений: 1
Написано 0 полезных сообщений (для 0 пользователей)
|
Помогите исправить код
Пытаюсь красиво меню оформить, но что-то я не могу его доделать.
Хочется чтобы на выбранном пункте кнопка по-другому светилась, а выходит каша. Помогите пожалуйста, я в МП еще зеленый.
Мой код:
program RPG;
Uses Picker;
var
m:array [0..4] of string;
x,y,a,c,b,keyC,i:integer;
bg,button,buttonoff,cur,buttonon:image;
rep: boolean;
Procedure Menu;
Begin
x:=GetWidth;
y:=GetHeight;
a:=130;
b:=0;
rep:=true;
m[0]:='Game';
m[1]:='Options';
m[2]:='Help';
m[3]:='About';
m[4]:='Exit';
SetFont(FONT_FACE_SYSTEM,FONT_STYLE_BOLD,FONT_SIZE_SMALL);
bg:=LoadImage('/bg.png'); //Фон
button:=LoadImage('/button.png');
DrawImage(bg,0,0);
Picker.Load(button);
buttonoff:=Picker.GetArea(0,0,140,21); //Кнопка-фон
buttonon:=Picker.GetArea(0,22,140,21); //Выделенная кнопка фон
SetColor(255,250,205);
for i:=0 to 4 do begin
DrawImage(buttonoff,(x-140)/2,a+i*30);
DrawText(m[i], (x-GetStringWidth(m[i]))/2,(a+i*30)+2);
keyC:=GetKeyClicked;
if KeyToAction(keyC)=GA_UP then b:=b+4 mod 5;
if KeyToAction(keyC)=GA_DOWN then b:=b+1 mod 5;
if KeyToAction(keyC)=GA_FIRE then
begin
if c=0 then Game;
if c=4 then Halt;
end;
Repaint;
end;
end;
begin
Menu;
Delay(-1);
end.
А делал я опираясь на это меню:

Program Menu;
Var
wi, hi, key, ch, cw, i, c, c_color, c_pos, c_c, c_pos_c, timer: integer;
m: array [0..5] of string;
x, y: array [0..100] of integer;
rep: boolean;
Procedure Stars;// Плывущие звёзды для фона меню
begin
SetColor(255,255,255);
for i:=0 to 100 do
begin
x[i]:=x[i]-1;
if x[i]<0 then x[i]:=wi;
Plot(x[i], y[i]);
end;
end;
Procedure Txt;
begin
setColor(255, 0, 0);
drawText('Hello world', 0, 0);
repaint;{вывод из буфера на экран}
delay(1000);
repeat
until getKeyClicked <> KE_NONE;{пауза до нажатия любой клавиши}
end;
Procedure Menu;
Begin
wi:=GetWidth;
hi:=GetHeight;
rep:=true;
c:=0;
cw:=100;
c_color:=125;
c_c:=5;
c_pos:=0;
c_pos_c:=1;
timer:=0;
for i:=0 to 100 do
begin
x[i]:=Random(wi);
y[i]:=Random(hi);
end;
m[0]:='Старт';
m[1]:='Настройки';
m[2]:='Помощь';
m[3]:='Рекорды';
m[4]:='Авторы';
m[5]:='Выход';
SetFont(FONT_FACE_SYSTEM, FONT_STYLE_BOLD, FONT_SIZE_LARGE);
ch:=GetStringHeight('X'); // Высота букв
repeat
SetColor(0,0,0); FillRect(0,0,wi,hi); // Очистка экрана
Stars; // Отрисовка фона меню
SetColor(0,0,0);
FillRoundRect(20, (hi-ch*6)/2, wi-40, ch*6, 20, 20);
SetColor(255,255,255);
DrawRoundRect(20, (hi-ch*6)/2, wi-40, ch*6, 20, 20);
SetColor(0,127,0);
for i:=0 to 5 do
DrawText(m[i], (wi-GetStringWidth(m[i]))/2, (hi-ch*6)/2+i*ch);// Отрисовка пунктов меню
SetColor(0,c_color,0);
DrawText('>', (wi-GetStringWidth(m[c]))/2-20+c_pos, (hi-ch*6)/2+c*ch);
key:=GetKeyClicked;
if (key=-59) or (key=-1) or (key=50) then c:=(c+5) mod 6; // Клавиша вверх
if (key=-60) or (key=-2) or (key=-6) or (key=56) then c:=(c+1) mod 6;// Клавиша вниз
if (key=53) or (key=-26) or (key=-5) or (key=-20) then // Клавиша огонь
begin
if c=1 then Txt;
if c=5 then Halt; // Выход
end;
c_color:=c_color+c_c;
if (c_color=125) or (c_color=255) then c_c:=-c_c;
timer:=(timer+1) mod 3;
if timer=0 then
begin
c_pos:=c_pos+c_pos_c;
if (c_pos=0) or (c_pos=5) then c_pos_c:=-c_pos_c;
end;
Repaint;
until false;
End;
Begin
Menu;
End.
|