Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 9, 2010 13:20:19 GMT -5
Hello, Exercise for your brain cells. In this game you have to get four stones in a series. Horizontal,Vertical or diagonal. You choose a slot if you press a number [1 to 9]. The game describes it itself what you have to do. If you are ready: you get it from here. brutus.pewtersoftware.com/upload/files/FourGame.rarmuch fun. Hi Guilect, if you want, then add it to the front page! another thing: if I'm starting my program from the Editor and I return to the Editor, the keyboard buffer has still all pressed key codes and writes them in the source code of the Editor! Can be annoying. It's usual?
|
|
|
Post by matthew on Jan 10, 2010 6:27:16 GMT -5
Nice Peter, I used to play Connect Four a lot when I was younger.
|
|
|
Post by Guilect on Jan 10, 2010 10:31:01 GMT -5
Hi peter, nice game. I will adventually put a notice about it on the front page. (It's been a while since I updated it, that I need to remember the login password ) The key presses showing up in the editor is not typical. I tried to duplicate your issue with the code below: ' Return the ASCII value of the key pressed
option explicit
dim bRunning bRunning = True
dim background, Font
sub main()
if (graphics.initialize <> True) then exit sub
Font = graphics.CreateFont("system", 24) graphics.setTitle "Demo - Keyboard - press n to exit" key.initialize do while bRunning = True
if key.pressed(vk_n) or key.pressed(0) = True then bRunning = False graphics.clear 255 graphics.settext Chr(dll.CallAPI("user32", "MapVirtualKeyA", key.pressedany(), 1)), 200,200, Font graphics.display loop key.terminate graphics.terminate
end sub
Call Main() but it always worked fine.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 10, 2010 11:28:28 GMT -5
Hi Guilect,
I mean: you write an program with Brutus2d. You want to test it. You click on start and the program will run. The test was good and you go back to brutus2d. And now: the whole keyboard buffer or the rest of the keyboard buffer apperars in you source code!
cheers.
|
|
|
Post by Guilect on Jan 10, 2010 18:39:17 GMT -5
peter, I understood perfectly. I just provided a simple example above as a test case, which when I run from the IDE and then stop the program and go back to the IDE everything is fine. Did you try the example above? Do you get extra characters in the IDE when you stop the program and return to the IDE? ? Does this happen to any of the other examples supplied with B2D for you? I have run many programs in B2D and do not see this.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 10, 2010 19:23:09 GMT -5
Hi Guilect,
I am sorry, I haven't been attentive! I can nothing see in the source code!
Okay, I guess that's an API routine, which causes this error. I'm going to check it. It's my fault! Thanks for your open ears.
|
|
|
Post by Guilect on Jan 11, 2010 18:58:25 GMT -5
Hi peter, I would gladly look into it, if some means of repeatedly reproducing it could be explained. It may be an issue with B2D, it is just that if the issue does not show itself, how can it be fixed. Let me know if you can give me the smallest example code that displays the behavior and the steps necessary to reproduce the problem.
Best Regards, Guilect
|
|
|
Post by u9 on Jan 18, 2010 6:06:32 GMT -5
Hey guys Nice game peter. I wonder how did you implement the AI? I am always pretty bad at making AIs. Guilect, i have had the same problem regarding the keyboard buffer. Maybe the keyboard should be terminated before you close the window? Or a need to call processmessages, or something, i am not sure. And i don't really remember how i solved it
|
|
|
Post by Guilect on Jan 18, 2010 20:49:25 GMT -5
The best theory about the keys that I can come up with is this. If you use a printable key like 'Q' for quit for example, and you are in your game, you press 'Q' and the game quits, focus goes back to the IDE editor window while you are still leaning on the 'Q' key and 'Q's are put into the editor until you release the key. Is this what is being seen? If so, make the last key a user might press in the game a non-printable one like 'ESC'.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 19, 2010 6:14:22 GMT -5
I'm sorry Guilect,
I can't give any part of the source code, the context is too complex.
Try these few lines and see what happens. This small program works correct for me. I get no numbers in my source code! And what about you ? Do you have the same ?
Code:
Option Explicit Dim Num,KeyF,Font,a
Sub Main() Graphics.Initialize 580,400,True,32 Key.Initialize Font = Graphics.CreateFont("comic",16,True) KeyF = 0 : Num = 0 While Key.Pressed(vk_escape) = False Graphics.Clear(&hFFD00000) HitNumber() TextOut() Graphics.Display Graphics.SetFPS 10 Wend Graphics.Terminate Key.Terminate End Sub
Call Main Sub HitNumber() iF Key.Pressed(vk_0) And KeyF =0 Then KeyF =1: Num = 0 ElseiF Key.pressed(vk_0) = False Then KeyF =0 End iF iF Key.pressed(vk_1) And KeyF =0 Then KeyF =1: Num = 1 ElseiF Key.pressed(vk_1) = False Then KeyF =0 End iF iF Key.pressed(vk_2) And KeyF =0 Then KeyF =1: Num = 2 ElseiF Key.pressed(vk_2) = False Then KeyF =0 End iF iF Key.pressed(vk_3) And KeyF =0 Then KeyF =1: Num = 3 ElseiF Key.pressed(vk_3) = False Then KeyF =0 End iF iF Key.pressed(vk_4) And KeyF =0 Then KeyF =1: Num = 4 ElseiF Key.pressed(vk_4) = False Then KeyF =0 End iF iF Key.pressed(vk_5) And KeyF =0 Then KeyF =1: Num = 5 ElseiF Key.pressed(vk_5) = False Then KeyF =0 End iF iF Key.pressed(vk_6) And KeyF =0 Then KeyF =1: Num = 6 ElseiF Key.pressed(vk_6) = False Then KeyF =0 End iF iF Key.pressed(vk_7) And KeyF =0 Then KeyF =1: Num = 7 ElseiF Key.pressed(vk_7) = False Then KeyF =0 End iF iF Key.pressed(vk_8) And KeyF =0 Then KeyF =1: Num = 8 ElseiF Key.pressed(vk_8) = False Then KeyF =0 End iF iF Key.Pressed(vk_9) And KeyF =0 Then KeyF =1: Num = 9 ElseiF Key.pressed(vk_9) = False Then KeyF =0 End iF End Sub
Sub TextOut() Graphics.SetRect 96,98,318,24,&hFF649000 Graphics.SetText "Press a number [1-9]",160,32,Font,&hFF0088FF Graphics.SetText Num,100+Num*16,100,Font,&hFFFFFF00 Graphics.Setbox (100+Num*16)-2,100,14,20,&hFFFFFFFF Graphics.SetText Num,400-Num*16,100,Font,&hFFFFFF00 Graphics.Setbox (400-Num*16)-2,100,14,20,&hFFFFFFFF Graphics.SetText "Escape key ends the Test",160,300,Font,&hFFB084FF TextMe(Num) End Sub
Function TextMe(Nummer) Graphics.SetText "you pressed " & Nummer & ",you win " & Nummer *4 & " eggs.",130,260,Font,&hFF00FF00 End Function
|
|
|
Post by Guilect on Jan 19, 2010 9:47:55 GMT -5
Hi peter, it works ok for me. I typed all sorts of numbers and letters and multiple keypresses at once and etc. (I like the look of this little test program by the way.)
BTW: I put a message on the Brutus2D homepage about your FourGame.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jan 22, 2010 12:36:36 GMT -5
Hello,
Here is the key test two. It is a simple test, for the rotation in six directions. Does it work well for you ?
Code: option explicit
'xx, yy, zz 3D coordinates of a point. 'ax viewing angle to the x-axis 'ay viewing angle to the y-axis 'xm x-distance to the origin of the 2D axis. 'ym y-distance to the origin of the 2D axis. 'fp vanishing point.
Public x,y,z,x1,y1,z1,x2,y2,z2,xx,yy,zz,xm,ym,xp,yp,ax,ay,zp,fp,pk Public dp,sw,rw,dh,pi,x3,y3,z3,Font,Color
Dim xa(8) Dim ya(8) Dim za(8) Dim xb(8) Dim yb(8) Dim zb(8) Dim a1(8) Dim a2(8) Dim b1(8) Dim b2(8) Sub Main() Graphics.Initialize 640,480,True,32 Key.Initialize Mouse.Initialize Font = Graphics.CreateFont("comic",12,True) Initial() Do While Key.Pressed (1) = False Start() Graphics.Display Graphics.SetFPS 85 Loop Graphics.Terminate Mouse.Terminate Key.Terminate End Sub
Call Main
Sub Initial() pi = 4 * Atn(1) dh = 8 fp = 512 xm = 320 ym = 240 ax = 0: ay = 0 sw = 1: rw = 6 x = 0: y = 0: z = 0 xx = 0: yy = 0: zz = 0 x1 = 0: y1 = 0: z1 = 0 x2 = 0: y2 = 0: z2 = 0 x3 = 0: y3 = 0: z3 = 0 xa(0) = 50:xa(1) =-50:xa(2) = 50:xa(3) = 50:xa(4) = 50:xa(5) = 50:xa(6) =-50:xa(7) = 50 ya(0) = 50:ya(1) = 50:ya(2) =-50:ya(3) =-50:ya(4) = 50:ya(5) =-50:ya(6) =-50:ya(7) =-50 za(0) = 50:za(1) = 50:za(2) = 50:za(3) =-50:za(4) = 50:za(5) = 50:za(6) = 50:za(7) = 50 xb(0) = 50:xb(1) =-50:xb(2) = 50:xb(3) =-50:xb(4) =-50:xb(5) =-50:xb(6) =-50:xb(7) = 50 yb(0) = 50:yb(1) = 50:yb(2) =-50:yb(3) =-50:yb(4) = 50:yb(5) =-50:yb(6) = 50:yb(7) = 50 zb(0) =-50:zb(1) =-50:zb(2) =-50:zb(3) =-50:zb(4) = 50:zb(5) = 50:zb(6) = 50:zb(7) = 50 End Sub
Sub Math() x1 = xx * Cos(ax) - zz * Sin(ax) y1 = yy z1 = xx * Sin(ax) + zz * Cos(ax) x2 = x1 + xp y2 = y1 * Cos(ay) - z1 * Sin(ay) + yp z2 = y1 * Sin(ay) + z1 * Cos(ay) + zp x = xm + (x2 * fp) / (fp - z2) y = ym + (y2 * fp) / (fp - z2) End Sub
Sub Calculation() For pk =0 To dh For dp =0 To pk xx = xa(dp): yy = ya(dp): zz = za(dp) Math(): a1(dp) = x: b1(dp) = y xx = xb(dp): yy = yb(dp): zz = zb(dp) Math(): a2(dp) = x: b2(dp) = y Next: Next End Sub
Sub Start() Graphics.Clear(&hFFFF8400) Graphics.SetText "3D Key-Test",254,16,Font,&hFFFFFF00 Graphics.SetText "Use arrow keys and (a) for origin",190,40,Font,&hFFFFFF00 CalCulation() For pk =0 To dh For dp =0 To pk Graphics.SetRect a1(dp),b1(dp),a2(dp)-350,b2(dp)-250,&hFF0000FF Graphics.SetBox a1(dp),b1(dp),a2(dp)-350,b2(dp)-250,&hFFFFFF00 Graphics.SetText "3D",a2(dp)-60,b2(dp),Font,&hFF00FF64 Next: Next iF Key.Pressed(vk_right) Then ax = ax - 2 * pi / 360 iF Key.Pressed(vk_up) Then ay = ay - 2 * pi / 360 iF Key.Pressed(vk_left) Then ax = ax + 2 * pi / 360 iF Key.Pressed(vk_down) Then ay = ay + 2 * pi / 360 iF Key.Pressed(vk_a) Then Initial End Sub
|
|
|
Post by Guilect on Jan 24, 2010 8:18:45 GMT -5
That is a nice effect.
|
|