owsik Posted October 13, 2011 Report Share Posted October 13, 2011 Witam jestem nawy na forum ma wielka prośbę aby ktoś pomógł mi przerobić mój program aby można było sterować platforma aby odbijać piłeczkę .Jakiś miesiąc temu zacząłem moja przygodę z pascalem wiec program na pewno nie jest pięknie napisany. Używam free pascala . O to program; uses crt,graph; var karta,wysokosckreski,poczatek,koniec,j,wysokosc,z,szerokosc,r,x,i,ilosc,tryb:integer; begin clrscr; detectgraph(karta,tryb); initgraph(karta,tryb,''); r:=10; poczatek:=270; koniec:=370; wysokosckreski:=460; szerokosc:=r; wysokosc:=r; for ilosc:=0 to 600 do begin setcolor(14); line(1,1,640,1); line(1,1,1,480); line(1,480,640,480); line(640,1,640,480); x:=x+i; z:=z+j; setcolor(15); line(poczatek,wysokosckreski,koniec,wysokosckreski); setcolor(6); circle(szerokosc+x,wysokosc+z,r); delay(20); setcolor(0); circle(szerokosc+x,wysokosc+z,r); line(poczatek,wysokosckreski,koniec,wysokosckreski); if wysokosc+z=480-r then j:=-5; if wysokosc+z=r then j:=5; if szerokosc+x=r then i:=5; if szerokosc+x=640-r then i:=-5; end; readln; readln; closegraph; end. Link to comment Share on other sites More sharing options...
Integer Posted October 13, 2011 Report Share Posted October 13, 2011 coś na temat procedur: http://turbopascal.s...oteka.pl/9.html zrób procedurę odpowiadająca za rysowanie paletki jak przez to przebrniesz to daj znać - zajmiemy się klawiszami w stylu: // gdzieś po drodze procedure RuchPaletki; begin if vx<0 then if (xpal +vx)>5 then begin {... tu trzeba wymazać paletkę ze starej pozycji} xpal:= xpal+vx; xpal1:=xpal -5; xpal2:=xpal+5; {... tu trzeba nową paletkę} end else if vx>0 then if (xpal +vx)<200 then begin {... tu trzeba wymazać paletkę ze starej pozycji} xpal:= xpal+vx; xpal1:=xpal -5; xpal2:=xpal+5; {... tu trzeba nową paletkę} end; end; if Key=#77 then // np. klawisz - paletka w lewo begin vx:= -5; PaletkaRysuj; end; Link to comment Share on other sites More sharing options...
owsik Posted October 13, 2011 Author Report Share Posted October 13, 2011 procedura odpowiadająca za rysowanie paletki ; procedure paletkarusuj; var x1,ypal,x2:integer; begin setcolor(red); line(x1,ypal,x2,ypal); end; procedure paletkawymarz; var x1,ypal,x2:integer; begin setcolor(0); line(x1,ypal,x2,ypal); end; Link to comment Share on other sites More sharing options...
Integer Posted October 14, 2011 Report Share Posted October 14, 2011 Repeat Key:= Readkey; {chyba odczyt kodu klawisza} if Key=#75 then { np. klawisz - paletka w lewo} begin vx:= -5; PaletkaRysuj; end; if Key=#77 then { np. klawisz - paletka w prawo} begin vx:= 5; PaletkaRysuj; end; Delay(60); {mała pauza} Key:= #255; {czyszczenie kodu klawisza} vx:= 0; {paletka będzie stała w miejscu gdy nie będzie w ruchu} Until Key=#27; {bodajże klawisz Esc, zakończenie programu} Link to comment Share on other sites More sharing options...
owsik Posted October 14, 2011 Author Report Share Posted October 14, 2011 uses crt,graph; var karta,vx,j,wysokosc,z,szerokosc,r,x,i,ilosc,tryb:integer; key:char; procedure pilkarysuj; var xp,yp,r,x,z:integer; begin setcolor(6); circle(xp+x,yp+z,r); end; procedure pilkawymarz; var xp,yp,r,x,z:integer; begin setcolor(0); circle(xp+x,yp+z,r); end; procedure ruchpilki; var xp,i,j,yp,z,x:integer; begin x:=x+i; z:=z+j; pilkarysuj; delay(20); pilkawymarz; if yp+z=480-r then j:=-5; if yp+z=r then j:=5; if xp+x=r then i:=5; if xp+x=640-r then i:=-5; end; procedure paletkarysuj; var xpal1,xpal2,ypal:integer; begin setcolor(red); line(xpal1,ypal,xpal2,ypal); end; procedure paletkawymarz; var xpal1,xpal2,ypal:integer; begin line(xpal1,ypal,xpal2,ypal); end; procedure ruchpaletki; var xpal1,xpal2,xpal,vx:integer; begin if vx<0 then if xpal+vx>5 then begin paletkawymarz; xpal:=xpal+vx; xpal1:=xpal-5; xpal2:=xpal+5; paletkarysuj; end else if vx>0 then if xpal+vx <200 then begin paletkawymarz; xpal:=xpal+vx; xpal1:=xpal-5; xpal2:=xpal+5; paletkarysuj; end; end; begin clrscr; detectgraph(karta,tryb); initgraph(karta,tryb,''); r:=10; szerokosc:=r; wysokosc:=r; setcolor(14); line(1,1,640,1); line(1,1,1,480); line(1,480,640,480); line(640,1,640,480); vx:=0; ruchpaletki; ruchpilki; repeat key:=readkey; if key=#75 then begin vx:=-5; paletkarysuj; end; if key=#77 then begin vx:=5; paletkarysuj; end; delay(60); key:=#255; vx:=0; until key=#27; readln; readln; closegraph; end. gdy uruchamiam program wyskakuje taki blad ; http://ifotos.pl/zob...pg_hqexsap.jpg/ jak to naprawic? Link to comment Share on other sites More sharing options...
Integer Posted October 14, 2011 Report Share Posted October 14, 2011 skasuj niepotrzebne zmienne xpal i ypal wstaw jako zmienne globalne i przypisz im wartości np 50 i 50 Link to comment Share on other sites More sharing options...
owsik Posted October 19, 2011 Author Report Share Posted October 19, 2011 niestety po zrobieniu tak jak mowisz to nie dziala Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.