Forum > Other
Showing off what my 7 year old did with Lazarus!
engkin:
Binary might be easy here. Each digit for one arrow key. Here is how to track the keys:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type { TForm1 } TForm1 = class(TForm) procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); private public TrackDownKeys:Byte; procedure LetUsMove; end; var Form1: TForm1; implementationuses LCLType; {$R *.lfm} { TForm1 } const CFourArrowKeys:array[VK_LEFT..VK_DOWN] of byte = (%0001 {Left}, %0010 {Up}, %0100 {Right}, %1000 {Down}); procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState );begin if Key in [VK_LEFT..VK_DOWN] then TrackDownKeys:=TrackDownKeys or CFourArrowKeys[Key]; LetUsMove;end; procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin if Key in [VK_LEFT..VK_DOWN] then TrackDownKeys:=TrackDownKeys and not CFourArrowKeys[Key]; LetUsMove;end; procedure TForm1.LetUsMove;begin Caption:=TrackDownKeys.ToBinString;end; end.
In this case Up and Left is %0011. As you can see it is visible.
Up and Right is %0110 and so on
Choosing which of the eight directions could be like:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.LetUsMove;begin Caption:=TrackDownKeys.ToBinString; case TrackDownKeys of %0001:;//Left %0010:;//Up %0100:;//Right %1000:;//Down %0011:;//Left and Up %0110:;//Right and Up %1100:;//Right and down %1001:;//Left and Down end;end;
If you know the direction you can turn it into delta for x and y. Maybe like:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.LetUsMove;var dx,dy:integer;begin Caption:=TrackDownKeys.ToBinString; case TrackDownKeys of %0001:begin dx:=-1; dy:= 0; end;//Left %0010:begin dx:= 0; dy:=-1; end;//Up %0100:begin dx:=+1; dy:= 0; end;//Right %1000:begin dx:= 0; dy:=+1; end;//Down %0011:begin dx:=-1; dy:=-1; end;//Left and Up %0110:begin dx:=+1; dy:=-1; end;//Right and Up %1100:begin dx:=+1; dy:=+1; end;//Right and down %1001:begin dx:=-1; dy:=+1; end;//Left and Down end;end;
Tony Stone:
Thank you guys for the suggestions on the diagonal drawing aspect. For our purposes and skill level it was a bit much. But her and I tonight were able to complete the project! And as I said before, this is almost all her design!! Her ideas... I did the coding but walked her through what it was all doing and I did it based on logic she suggested! It was a ton of fun to do this with her. I am attaching the project. It actually works very well! Maybe it can even be useful to another beginner! :D 8)
Feel free to comment on the code and design. We are tough, we can take some criticism! ;)
Edit: just realized you may not find form1 right away as it will be off screen likely. Use the Window menu then Center a Lost Window if you need to get it on the screen.
Navigation
[0] Message Index
[*] Previous page