QB64.org Forum

QB64 Team Software => InForm-based programs => Topic started by: bplus on June 04, 2018, 02:26:26 am

Title: Lander project
Post by: bplus on June 04, 2018, 02:26:26 am
Well I have it setup the way I want to do it with InForm:

In SmallBASIC I could do a message box, here I used the _title for messages.
Code: QB64: [Select]
  1. _TITLE "Lander B+ started 2018-06-02"
  2. ' Lander update.bas SmallBASIC 0.12.11 (B+=MGA) 2018-06-01
  3.  
  4. 'modified code from my 2nd mod of:
  5. 'Lander mod 2.txt for JB v2 B+ 2018-05-29 big mod of
  6. 'Lander by Carl mod Rod mod B+.txt for JB v2 started 2018-05-26
  7. 'where I rewired controls and changed physics of Lander Model.
  8.  
  9. 'This will further depart from Carls's original by hand drawing Lander
  10. 'at different angles instead of using sprites and, alas, landscape will
  11. 'have to be updated each frame because there is no drawing on top of images
  12. 'in SmallBASIC.
  13.  
  14. ' INSTRUCTIONS:
  15. 'Use the left or right arrow keys to rotate Lander left or right.
  16. 'Use the up arrow for thruster burst. These moves cost fuel!
  17. 'The Fuel Gage is Red Horizontal line below landscape.
  18. 'The fuel level is Yellow.
  19.  
  20. 'You must make a VERY gentle and level landing
  21. 'on one of the flat areas!
  22.  
  23. 'Horizontal location, speed in green.
  24. '  Vertical location, speed inblue
  25.  
  26. DIM SHARED main&
  27. CONST xmax = 1200
  28. CONST ymax = 720
  29. main& = _NEWIMAGE(xmax, ymax, 32)
  30. SCREEN main&
  31. _SCREENMOVE 100, 10
  32.  
  33. CONST ns = 75
  34.  
  35. DIM SHARED pi, d2r
  36. pi = _PI
  37. d2r = pi / 180
  38.  
  39. 'stars
  40. DIM SHARED sx(ns), sy(ns), sr(ns), sc&(ns)
  41. 'terrain
  42. DIM SHARED terraH(xmax), terraC(xmax)
  43. 'vehicle globals
  44. DIM SHARED fuel, vda, speed, vx, vy, dx, dy, dg, dat
  45.  
  46. restart: ' =========================================   initialize Game
  47. makeStars
  48. makeTerra
  49. fuel = 500 'this is the space vehicle's fuel
  50.  
  51. 'vda is vehicle degree angle = orientation of the vehicle, mainly it's thrusters
  52. vda = 0 'the vehicle is traveling right across screen due East = 0 degrees = 0 Radians
  53. speed = 6 'this is the speed the vehicle is moving in the vda direction
  54. vx = 50 'this is current x position of vehicle 10 pixles from left side
  55. vy = 30 'this is current y position of vehicle 10 pixels down from top of screen
  56.  
  57. 'd stands for delta with stands for change dx = change in x, dy = change in y
  58. 'dg is change due to gravity (vertical)
  59. 'dat is change of acceleration due to thrust
  60. dx = speed * COS(d2r * vda) 'this is the horizontal x change on screen due to speed and angle
  61. dy = speed * SIN(d2r * vda) 'this is the vertical y change on screen due to speed and angle
  62. dg = .1 'this is the constant acceleration gravity applies to the vehicle
  63. dat = 2 'this is burst of acceleration a thrust or reverse thrust will apply to speed and angle
  64. COLOR _RGB32(0, 0, 0), _RGB32(0, 45, 90)
  65. 'buttons
  66. drwbtn 290, ymax - 80, "Rotate Left"
  67. drwbtn 500, ymax - 80, "Forward Thrust"
  68. drwbtn 710, ymax - 80, "Rotate Right"
  69.     'respond to button clicks
  70.     mx = _MOUSEX
  71.     my = _MOUSEY
  72.     mb = _MOUSEBUTTON(1)
  73.     IF mb THEN
  74.         IF my > ymax - 80 AND my < ymax - 30 THEN
  75.             IF mx > 290 AND mx < 490 THEN
  76.                 moveLeft
  77.             ELSEIF mx > 500 AND mx < 700 THEN
  78.                 moveUp
  79.             ELSEIF mx > 710 AND mx < 910 THEN
  80.                 moveRight
  81.             END IF
  82.         END IF
  83.     END IF
  84.     'respond to key press
  85.     k$ = INKEY$
  86.     IF LEN(k$) = 2 THEN
  87.         SELECT CASE ASC(RIGHT$(k$, 1))
  88.             CASE 72: moveUp
  89.             CASE 75: moveLeft
  90.             CASE 77: moveRight
  91.         END SELECT
  92.     ELSEIF LEN(k$) = 1 THEN
  93.         IF ASC(k$) = 27 THEN END
  94.     END IF
  95.     scene
  96.     'fuel line
  97.     rgb 300
  98.     recf 10, ymax - 25, xmax - 10, ymax - 5
  99.     ff = fuel / 500 * (xmax - 20)
  100.     rgb 860
  101.     recf 10, ymax - 20, ff + 10, ymax - 10
  102.     COLOR _RGB32(200, 200, 250), _RGB32(0, 45, 90)
  103.     _PRINTSTRING (10, ymax - 70), "Horizontal:" + STR$(INT(vx)) + "," + STR$(INT(dx))
  104.     _PRINTSTRING (10, ymax - 50), "  Vertical:" + STR$(INT(vy)) + "," + STR$(INT(dy))
  105.  
  106.     'vehicle falls faster and faster, because gravity effects the vertical speed
  107.     dy = dy + dg 'speed up falling due to gravity acceleration
  108.  
  109.     'new position = last postion plus the horizontal and vertical changes from momentum
  110.     vx = vx + dx
  111.     vy = vy + dy
  112.     Lander vx, vy, d2r * vda
  113.  
  114.     IF vx < 30 OR vx > xmax - 30 OR vy < -50 THEN 'edit keep Lander legs inside boundries of terraH()
  115.         _TITLE "You have drifted off screen. Press p to play again..."
  116.         EXIT WHILE
  117.     END IF
  118.  
  119.     IF vy > terraH(vx) OR fuel <= 0 THEN
  120.         crash$ = ""
  121.         IF fuel <= 0 THEN
  122.             crash$ = crash$ + "Ran out of fuel. "
  123.         ELSE
  124.             IF vda <> 270 THEN crash$ = crash$ + "Vehicle not upright. "
  125.             IF dy > 4 THEN crash$ = crash$ + "Came down too fast. "
  126.             IF ABS(dx) > 4 THEN crash$ = crash$ + "Still moving hoizontally too fast. "
  127.             IF terraH(vx - 10) <> terraH(vx + 10) THEN crash$ = crash$ + "Did not land on level site. "
  128.         END IF
  129.         IF crash$ <> "" THEN
  130.             _TITLE "You crashed! because: " + crash$ + " Press p to play again..."
  131.         ELSE
  132.             _TITLE "Nice job! Successful landing!  Press p to play again..."
  133.         END IF
  134.         EXIT WHILE
  135.     END IF
  136.     _DISPLAY
  137.     _LIMIT 10
  138. k$ = ""
  139. drwbtn 990, ymax - 80, "Restart"
  140. WHILE LEN(k$) = 0
  141.     k$ = INKEY$
  142.     mx = _MOUSEX
  143.     my = _MOUSEY
  144.     mb = _MOUSEBUTTON(1)
  145.     IF mb THEN
  146.         IF my > ymax - 80 AND my < ymax - 30 THEN
  147.             IF mx > 990 AND mx < 1190 THEN
  148.                 k$ = "p"
  149.             END IF
  150.         END IF
  151.     END IF
  152.     _LIMIT 200
  153. IF k$ = "p" THEN GOTO restart
  154.  
  155. SUB scene
  156.     rgb 101
  157.     recf 4, 4, xmax - 5, ymax - 85
  158.     FOR i = 0 TO ns
  159.         COLOR sc&(i)
  160.         fcirc sx(i), sy(i), sr(i)
  161.     NEXT
  162.     FOR i = 4 TO xmax - 5
  163.         rgb terraC(i) * 100 + terraC(i) * 10 + terraC(i)
  164.         ln i, terraH(i), i, ymax - 86
  165.     NEXT
  166. '                              arrow + esc key
  167. SUB moveUp
  168.     'here is the vertical and horizontal change from a burst of fuel for thrust
  169.     thrustx = dat * COS(d2r * vda)
  170.     thrusty = dat * SIN(d2r * vda)
  171.  
  172.     'now change the horizontal and vertical momentums from the thrust
  173.     dx = dx + thrustx
  174.     dy = dy + thrusty
  175.  
  176.     'update the position
  177.     vx = vx + dx
  178.     vy = vy + dy
  179.     rgb 990
  180.     fcirc vx, vy, 5
  181.     _DISPLAY
  182.  
  183.     'the thrust cost fuel
  184.     fuel = fuel - 10
  185.  
  186. SUB moveLeft
  187.     x1 = vx + 10 * COS(d2r * vda + .5 * pi)
  188.     y1 = vy + 10 * SIN(d2r * vda + .5 * pi)
  189.     rgb 990
  190.     fcirc x1, y1, 5
  191.     _DISPLAY
  192.     vda = vda - 22.5
  193.     IF vda < -0.01 THEN vda = 360
  194.     fuel = fuel - 10
  195.  
  196. SUB moveRight
  197.     x1 = vx + 10 * COS(d2r * vda - .5 * pi)
  198.     y1 = vy + 10 * SIN(d2r * vda - .5 * pi)
  199.     rgb 990
  200.     fcirc x1, y1, 5
  201.     _DISPLAY
  202.     vda = vda + 22.5
  203.     IF vda > 337.51 THEN vda = 0
  204.     fuel = fuel - 10
  205.  
  206. SUB Lander (x0, y0, rAngle) 'rebuilt from ground up literally!
  207.     'x0, y0 are at the base of the lander, the rocket will point rAngle up when landing
  208.     rgb 333
  209.     x1 = x0 + 10 * COS(rAngle - .5 * pi)
  210.     y1 = y0 + 10 * SIN(rAngle - .5 * pi)
  211.     x2 = x0 + 10 * COS(rAngle + .5 * pi)
  212.     y2 = y0 + 10 * SIN(rAngle + .5 * pi)
  213.     x3 = x0 + 10 * COS(rAngle)
  214.     y3 = y0 + 10 * SIN(rAngle)
  215.     x4 = x0 + 25 * COS(rAngle)
  216.     y4 = y0 + 25 * SIN(rAngle)
  217.     'legs/fins
  218.     ln x3, y3, x1, y1
  219.     ln x3, y3, x2, y2
  220.     ln x4, y4, x1, y1
  221.     ln x4, y4, x2, y2
  222.     pangle = 2 * pi / 5
  223.     COLOR _RGB32(20, 0, 0)
  224.     FOR i = 0 TO 5
  225.         SELECT CASE i
  226.             CASE 0, 5: r = 20
  227.             CASE 2, 3: r = 15
  228.             CASE 1, 4: r = 25
  229.         END SELECT
  230.         x1 = x4 + r * COS(i * pangle + rAngle)
  231.         y1 = y4 + r * SIN(i * pangle + rAngle)
  232.         IF i <> 0 THEN ln lx, ly, x1, y1
  233.         lx = x1: ly = y1
  234.     NEXT
  235.     PAINT (x4, y4), _RGB(160, 120, 120), _RGB32(20, 0, 0)
  236.  
  237. SUB ln (x1, y1, x2, y2)
  238.     LINE (x1, y1)-(x2, y2)
  239.  
  240. SUB rec (x1, y1, x2, y2)
  241.     LINE (x1, y1)-(x2, y2), , B
  242.  
  243. SUB recf (x1, y1, x2, y2)
  244.     LINE (x1, y1)-(x2, y2), , BF
  245.  
  246. SUB rgb (n) ' New (even less typing!) New Color System 1000 colors with up to 3 digits
  247.     s3$ = RIGHT$("000" + LTRIM$(STR$(n)), 3)
  248.     r = VAL(MID$(s3$, 1, 1)): IF r THEN r = 28 * r + 3
  249.     g = VAL(MID$(s3$, 2, 1)): IF g THEN g = 28 * g + 3
  250.     b = VAL(MID$(s3$, 3, 1)): IF b THEN b = 28 * b + 3
  251.     COLOR _RGB32(r, g, b)
  252.  
  253. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  254. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  255.     DIM subRadius AS LONG, RadiusError AS LONG
  256.     DIM X AS LONG, Y AS LONG
  257.  
  258.     subRadius = ABS(R)
  259.     RadiusError = -subRadius
  260.     X = subRadius
  261.     Y = 0
  262.  
  263.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  264.  
  265.     ' Draw the middle span here so we don't draw it twice in the main loop,
  266.     ' which would be a problem with blending turned on.
  267.     LINE (CX - X, CY)-(CX + X, CY), , BF
  268.  
  269.     WHILE X > Y
  270.         RadiusError = RadiusError + Y * 2 + 1
  271.         IF RadiusError >= 0 THEN
  272.             IF X <> Y + 1 THEN
  273.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  274.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  275.             END IF
  276.             X = X - 1
  277.             RadiusError = RadiusError - X * 2
  278.         END IF
  279.         Y = Y + 1
  280.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  281.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  282.     WEND
  283.  
  284. FUNCTION min (a, b)
  285.     IF a > b THEN min = b ELSE min = a
  286.  
  287. FUNCTION max (a, b)
  288.     IF a > b THEN max = a ELSE max = b
  289.  
  290. SUB drwbtn (x, y, s$)
  291.     th = 16: tw = LEN(s$) * 8
  292.     rgb 0
  293.     recf x, y, x + 200, y + 50
  294.     rgb 999
  295.     recf x, y, x + 198, y + 48
  296.     rgb 666
  297.     recf x + 2, y + 2, x + 198, y + 48
  298.     xoff = 100 - tw \ 2: yoff = 25 - th \ 2
  299.     COLOR _RGB(0, 0, 0), _RGB32(171, 171, 171)
  300.     _PRINTSTRING (x + xoff, y + yoff), s$
  301.     COLOR _RGB(0, 0, 0), _RGB(0, 0, 0)
  302.  
  303. SUB makeStars
  304.     FOR i = 0 TO ns
  305.         sx(i) = RND * (xmax - 16) + 8
  306.         sy(i) = RND * (ymax - 96) + 8
  307.         r = RND
  308.         IF r < .8 THEN
  309.             sr(i) = 1
  310.         ELSEIF r < .95 THEN
  311.             sr(i) = 2
  312.         ELSE
  313.             sr(i) = 3
  314.         END IF
  315.         sc&(i) = _RGB32(RND * 74 + 180, RND * 74 + 180, RND * 74 + 180)
  316.     NEXT
  317.  
  318. SUB makeTerra
  319.     FOR x = 4 TO xmax - 5
  320.         IF x > 5 AND RND < 0.06 THEN
  321.             xstop = min(xmax - 5, x + 50)
  322.             FOR lz = x TO xstop
  323.                 terraH(lz) = y
  324.                 c = INT(RND * 3) + 1
  325.                 terraC(lz) = c
  326.             NEXT
  327.             x = lz - 1
  328.         ELSE
  329.             xstop = min(xmax - 5, x + RND * 25)
  330.             IF RND < .5 THEN yd = 1 ELSE yd = -1
  331.             yd = yd * RND * 2
  332.             FOR xx = x TO xstop
  333.                 y = min(ymax - 90, y + yd)
  334.                 y = max(y, ymax - 240)
  335.                 terraH(xx) = y
  336.                 c = INT(RND * 2) + 1
  337.                 terraC(xx) = c
  338.             NEXT
  339.             x = xx - 1
  340.         END IF
  341.     NEXT
  342.  

2nd EDIT to fix the reasons for crash report.
3rd EDIT need ABS(dx) in crash report because could be moving too fast in minus direction.
Title: Re: Lander project
Post by: roadbloc on June 04, 2018, 07:16:55 am
This is neat! Took quite a few goes before I managed to do it. I got an error on line 130 whenever I got too close to the edge of the window. :)
Title: Re: Lander project
Post by: johnno56 on June 04, 2018, 09:17:47 am
This is pretty cool.. First time I tried it, I landed as slow as I could, then a 'restart' button pops up. I figured I landed ok because I didn't see any of the 'crash' type comments. Usually, when I play 'lander-type' games, my ship hits the ground, bounces a little, then scatters itself across the terrain... lol Landing good. Crashing bad. Still a cool game... Well done!

J

ps: Just noticed the messages popping up on the Title Bar... Hey. I did land it ok... Who woulda thought?
Title: Re: Lander project
Post by: bplus on June 04, 2018, 09:33:50 am
Hi roadbloc,

This edit should fix the boundary problem (right after Lander vx, vy updated and Lander drawn in main loop):
Code: QB64: [Select]
  1.     IF vx < 30 OR vx > xmax - 30 OR vy < -50 THEN 'edit keep Lander legs inside boundries of terraH()
  2.         _TITLE "You have drifted off screen. Press p to play again..."
  3.         EXIT WHILE
  4.     END IF
  5.  
I will change it in OP (original post). When I changed picture window and TerraH(), I forgot to update this part.
Thanks for your report and interest. (OK changed.)

Hi Johnno,

Glad you found the message center, way up top. Yikes!
Good, you are landing OK so maybe one you can win at? ;-))

Maybe points given for amount of fuel left?

And a Text Box for messages nearer the controls, maybe under the fuel gage.

Hint: the arrow keys (left right and up) work a little better than clicking buttons but with buttons it should work with touch screens.

update: my touch screen not very responsive to my button "clicks".
Title: Re: Lander project
Post by: bplus on June 04, 2018, 10:33:24 am
Found another bug due to last minute changes before post.


I was working from a list of reasons for crash, building up a report of all things wrong, that worked fine.

But when you run out of gas, all the other reasons don't make sense, so I tried to isolate that one reason with the remainder list. I used ELSEIF and meant ELSE here is the fix, that I will also use to edit OP:
Code: QB64: [Select]
  1.         IF fuel <= 0 THEN
  2.             crash$ = crash$ + "Ran out of fuel. "
  3.         ELSE
  4.             IF vda <> 270 THEN crash$ = crash$ + "Vehicle not upright. "
  5.             IF dy > 4 THEN crash$ = crash$ + "Came down too fast. "
  6.             IF dx > 4 THEN crash$ = crash$ + "Still moving hoizontally too fast. "
  7.             IF terraH(vx - 10) <> terraH(vx + 10) THEN crash$ = crash$ + "Did not land on level site. "
  8.         END IF
  9.  
Title: Re: Lander project
Post by: bplus on June 04, 2018, 11:23:46 am
Dang, another one. In crash report, it is suppose to be a crash if you moving too fast in either direction horizontally (the dx variable) correction made in 3rd edit of OP.
Title: Re: Lander project
Post by: Petr on June 04, 2018, 11:47:58 am
Nice work, Bplus!
Title: Re: Lander project
Post by: bplus on June 04, 2018, 12:00:28 pm
Thanks Petr,

I am hoping to get it going with InForm beta 7. I am hoping the buttons will work better, be more responsive to clicks. Problems are either over rotate or not rotate at all or thruster jams a bit, some of the time. Probably could be tweaked in regular code? The arrow keys work great!
Title: Re: Lander project
Post by: johnno56 on June 04, 2018, 05:08:14 pm
Bplus,

May I suggest that the 'controls' be 'not so responsive'? Just like accelerating an object, then release the thrust, then 'gradually' slow down. It may add to the 'realism' and possibly the difficulty... Hmm... Nuts! More difficult means I might crash more... How about some sound effects instead? lol

J

ps: Thought of this AFTER I logged out... Joystick. Does QB64 interface with a joystick? I know it sounds nuts, and most people may not have a 'stick', but it would be so cool... My suggestion is a wee bit selfish as my poor joystick has been gathering dust for quite some time... Fight sims of ANY kind do not pass by very often... lol
Title: Re: Lander project
Post by: Petr on June 04, 2018, 05:43:16 pm
Hi Johnno56,
 yes joystick IS supported. BUT i never try it because have none. But: STICK function return joystick coordinates, STRIG(0) return if is fire pressed, for initializing use ON STRIG GOSUB....
Hi Bplus,
For delay after mouse operations - limit it with TIMER in this way: IF _MOUSEBUTTON(1) AND TimeLimit > TIMER THEN TimeLimit = TIMER + .01 : your action
Title: Re: Lander project
Post by: johnno56 on June 04, 2018, 05:48:57 pm
Thanks Petr. I will check it out...

J
Title: Re: Lander project
Post by: johnno56 on June 04, 2018, 06:47:15 pm
I popped in the stick() and strig() commands and they worked. A little too well. x/y controls were 'very' sensitive. (a little 'heavy handed one time and the ship spun like a top... lol) Strig() worked fine. One click. One thruster burn... Took me 3 attempts before I got the hang of using a joystick... I think I might stick with the cursor keys... lol

J
Title: Re: Lander project
Post by: bplus on June 04, 2018, 07:24:31 pm
Hi Petr,

Yes I have used the delay trick many a time, not just QB64, it also will likely help Johnno with his joystick too.

I don't think a timer need be involved, just a _DELAY x might do?

I am saving that problem for later and want to see performance in InForm'd system. I have the form mapped out and plan on adding code tonight.

Hi Fellippe,

I do have a question. Under the Edit Menu of UiEditor, I found this (see attached) should I use Windows option if I have Windows?
Title: Re: Lander project
Post by: FellippeHeitor on June 04, 2018, 09:14:16 pm
Use codepage 437 for English-only programs; use codepage Windows-1252 for any programs that need to display diacritic marks, like "maçã" or something like that. I basically save my forms with codepage 1252 when I write programs in Portuguese (not related to the target operating system, despite its name - see more here: https://msdn.microsoft.com/en-us/library/cc195054.aspx (https://msdn.microsoft.com/en-us/library/cc195054.aspx)).

I mention (and demonstrate) that in the video for Beta 6. See it at ~2:33: https://youtu.be/S4d5nmu_gjQ?t=153 (https://youtu.be/S4d5nmu_gjQ?t=153)
Title: Re: Lander project
Post by: bplus on June 05, 2018, 01:30:02 am
Still have to rework numbers but basic program is working under InForm.

And! as I suspected the response to button clicking was accurate, no jamming. I have included some notes in comments in .bas file.
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 01:50:25 am
Awesome job translating your game to this new approach, bplus! I'm glad to see you understood the idea of not having a main loop but being able to use the BeforeUpdateDisplay event as a main loop of sorts. I'm also happy to see you using BeginDraw and EndDraw successfully. I hope the experience was smooth using InForm.

PS: Great idea using the ProgressBar for fuel!
Title: Re: Lander project
Post by: Ashish on June 05, 2018, 07:04:32 am
Nice game, bplus! and Nice use of Inform!
Title: Re: Lander project
Post by: bplus on June 05, 2018, 09:04:33 am
Thanks Fellippe and Ashish

Quote
'You can change the update frequency by calling SetFrameRate DesiredRate%
Dang! I am poor reader. Missed this all yesterday! So I didn't have to change the numbers, probably...

Here are my notes in .bas file for those who might want some hints for using InForm:
Quote
' notes: Do not use _display or _delay in screen repaints!
' Do not remove empty subs for form events created by UiEditor.
' Due to very fast screen updates:
' I had to reduce gravity and speeds to 1/10th except thruster acceleration.
' I had to go back and change numbers for controls so just used the updated form file.
' Also modified crash report again.
' Added code to draw flash of thruster at same time as drawing rest of scene.

Improvements using InForm:
+ Nice Fuel Gage = Progress Bar
+ Accurate response to mouse click of Buttons
+ Much easier tracking events.
+ Layout is independent and in separate file of run time workings. I was able to go back and modify numbers in the Frm file many times. Such would be OK as long as new Controls aren't added.

Designing Form:
Since I am familiar with VB the automatic naming of controls was a hindrance, I'd set the name change numbers and the name would be changed with new suffix...

When I changed font size, the width and height for label control changed and sometimes to weird numbers.

Still have not mastered how to grab control to move it around, I had numbers preplanned and just punched them in.

Oh, I am still trying to get use to pressing enter to set a control number.

To Do For Project:
Try and get original numbers working by changing frame rate.
Do something better with terrain making.
Make it more a game by possibly landing and taking off from different sites like delivering supplies across a moon.
So points for speed of getting route finished quickly with extra points for low fuel usage...
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 09:42:32 am
Quote
'You can change the update frequency by calling SetFrameRate DesiredRate%
Dang! I am poor reader. Missed this all yesterday! So I didn't have to change the numbers, probably...
The thing here is: you can increase the frame rate, but not make it less than 30fps. InForm won't allow you, especially as that would harm the interface repaints - something that's not bad if the refresh rate is higher but it's dreadful if it's lower. That said, you probably went the right route by adapting your physics.

Quote
the automatic naming of controls was a hindrance
Options -> Untick "Auto-name controls"

Quote
When I changed font size, the width and height for label control changed and sometimes to weird numbers.
Auto-sizing for labels was a feature request from TempodiBasic that I finally got around to adding in this latest beta, but I do recognize it is annoying sometimes and that's why Beta 8 will likely have an easy way to turn it off or bypass it too.

Quote
Still have not mastered how to grab control to move it around
Here you got me lost: what's to master?

Thanks a bunch and please keep the feedback coming, that's vital for a project like InForm.
Title: Re: Lander project
Post by: bplus on June 05, 2018, 10:08:57 am
Hi Fellippe,

Sorry I forgot to mention, I did find the turn off switch to auto-naming and meant to praise you for that!

BTW, I lost contact with Label2 when I set the caption to "" and had background same as form, there was nothing to click and  or grab on to change it's settings even when I figured I could tab to it but not get the properties window to see it to change it. (I had it near the left edge of screen and somehow boggled the x to a negative?)
Wait... it probably came up when I tabbed to it... just didn't see...

Yes, a turn off switch for auto-sizing while designing, but isn't there a handy auto-size property in VB?

Also I am not seeing mouseX and mouseY locations in a Picture Box, this would be needed for board games like Battleship.
I would think if Slider bars can catch the mouse so can Picture Box, maybe more Global Variables. (True, I am not seeing allot of things that might be around somewhere.)
Title: Re: Lander project
Post by: bplus on June 05, 2018, 10:28:09 am
Oh, I reread #18, I can't reduce the frame rate to less than 30 per second. Well that saved me some time and testing, thanks. I am glad I reread that.

But you can refresh even faster!
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 10:35:48 am
Use __UI_MouseLeft and __UI_MouseTop for x/y mouse locations. These are direct translations of _MOUSEX/_MOUSEY (which you shouldn't be probing yourself). To know the exact click location within a picturebox control, just subtract its .left and .top properties:

    pbMouseX = __UI_MouseLeft - Control(PictureBox).Left
    pbMouseY = __UI_MouseTop - Control(PictureBox).Top
Title: Re: Lander project
Post by: bplus on June 05, 2018, 11:31:18 am
Thanks Fellippe, the mouse stuff is good to know for future board games.

Now I am trying to use Johnno's stars.png for a background image and draw lander on top.

Dang! cls clears the stars image, I hope _put works.

UPDATE: Oh here we go, LoadImage Control(controlID) , ImageFile$

OMG that sure slowed things down!!! and it appears the image rescaled the x, y dimensions as when the lander is upright it is wider than when lander is at 90 degrees

Image looks nice though!
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 12:13:36 pm
LoadImage is supposed to be used for when you want to have static image to be shown inside a PictureBox control. It'll be stretched if the .Stretch property of the PictureBox control is set to true. If not stretched, it'll be centered, but then it can be aligned using the .Align property (that can be set to __UI_Left, __UI_Center or __UI_Right) and the .VAlign property (that can be set to __UI_Top, __UI_Middle or __UI_Bottom).

The LoadImage method can also be used to load an image to be used as an icon for a Button or MenuItem control, but then again it's a once at startup thing, not to be used in a loop.

If you want to use Johnno's bg for the game, just load it once using regular _LOADIMAGE and then, once you BeginDraw to the picturebox's surface, use _PUTIMAGE as you would in a non-InForm program.
Title: Re: Lander project
Post by: bplus on June 05, 2018, 12:22:07 pm
Thanks Fellippe,

What is destination handle, 0 or picture box handle, maybe none needed?

I will experiment...
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 12:23:10 pm
None needed. What BeginDraw does is setting the proper _DEST, so you don't need to specify it. What EndDraw does is reset _DEST to the proper one and trigger a .Redraw (If you set the .Redraw property of a control to True you force InForm to redraw its surface, which may be needed in rare occasions. To trigger a global redraw set __UI_ForceRedraw = True - usually rarely needed too).
Title: Re: Lander project
Post by: bplus on June 05, 2018, 12:52:15 pm
OK got it!

I had to load file somewhere else than what I first tried, so under the _LOAD event.

Then I did need to say _SOURCE star& before _PUTIMAGE without any arguments.

Then I still got scale changes with x, y when drawing.

So I loaded Johnno's stars into Paint stretched it to 1190 wide my Picture Box.
Then I cropped to 600 high to match my Picture Box Height.

Then saved the reconfigured image under same old name and ran with that.

Looks good so far:

Update: OH! I have to remove the old image from the frm designed file because getting missing file screen.

hmm... I could not remove the file image from Picture Box, it would not accept or change with an empty box when I hit enter.
So, I deleted the control and started over with all the old names and numbers except I changed alignments to top, left.
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 01:28:27 pm
hmm... I could not remove the file image from Picture Box, it would not accept or change with an empty box when I hit enter.
So, I deleted the control and started over with all the old names and numbers except I changed alignments to top, left.

Noted. I'll look into that. As an alternative, you could have removed the LoadImage line from the .frm file.
Title: Re: Lander project
Post by: bplus on June 05, 2018, 01:58:12 pm
Ah, I have not looked inside a frm file, just a normal text, I will assume.

I may also have been screwed up because the Save Frm only option was using the Form name listed in the Form properties box.

I was loading a renamed frm file and wondering why my changes weren't being saved, they were but under original name in frm properties... which I hadn't changed. Yikes what a run around that was until I figured it out.

PS I think Johnno's Planet will make a great image for restart button! It would be nice if all the buttons were pictures, the universal language.
Title: Re: Lander project
Post by: johnno56 on June 05, 2018, 06:14:17 pm
Oh my... Squish the planet down to a size as to fit inside the button? That is a 600x600 image down to a maximum size of 20x20... I think my editor may "down tools" in protest... lol

I will give it a try and post it... Pictures on 'all' the buttons? Oh my... Pictures at 20 pixels in height will have little to no detail. You may get away with a silhouette-type image... Suggestions for images?

Stay tuned...
Title: Re: Lander project
Post by: johnno56 on June 05, 2018, 06:27:13 pm
First of all, I should have stated 50 instead of 20...

I have attached a sample. As you can see, scaling a 600x600 image down to 48x48, had an impact on resolution.

J
Title: Re: Lander project
Post by: johnno56 on June 05, 2018, 06:47:57 pm
Threw together a complete set of buttons. Simple light blue text on a darker blue background.

J
Title: Re: Lander project
Post by: bplus on June 05, 2018, 07:25:18 pm
Hi Johnno,

You are right, shrinking down does not do Planet justice.

I was hoping for pictures not words, as they are universal language.
Title: Re: Lander project
Post by: johnno56 on June 05, 2018, 09:51:46 pm
Ok. Figured I would stick to more familiar images. Used and modified standard web page navigation icons.

J
Title: Re: Lander project
Post by: johnno56 on June 05, 2018, 10:08:26 pm
Can I make a quick suggestion? (Yes, I know the question is rhetorical, as I would have have to wait for your response to continue... lol) If the Lander runs out of fuel, would it not be correct to assume that, Sir Isaac Newton would "take over the drivers seat" and the Lander's downward motion would increase until it crashes? Just curious. Also thought of two extra animated sprites when a crash occurs. 1. If no fuel left then the lander just crumples on the ground and 2. If fuel remains... well, I think you would know what happens... lol Oh. Then there is sound. Thrusters; Landing and Crashing....

Food for thought.
Title: Re: Lander project
Post by: bplus on June 05, 2018, 10:50:23 pm
Yeah Johnno, you are right about running out of fuel, and those new picture buttons are more what I had in mind, not sure about the house, I was thinking the universal symbol for power button, circle with 12 o'clock line?

Anyway I have made a bunch of changes including the new word buttons and have an update. Here are my notes from .bas file since version 1:
Quote
' Apparently image files have to be located at root where the UiEditor.exe resides.
' To load into form at design time.

' Lander_Inform2 started 2018-06-05
' + use Johnno's Stars.png for pbScene stars background, remove star making
' + use terraH for creating a black silhoette of land profile color line at top
' + installed landing lights and adjust colors
' + 4 bases for landing are separated fairly evenly across screen
' + arrow keys will work after click a button one time, even after Restart
' + Horizontal and vertical speeds can now see beyond deciaml point
' + New crash numbers for speeds: abs(1.5) for horizontal and 1.5 max for vertical.
' + Added Image Files for buttons by Johnno,
' - Even with the shrink property set to True,
'  and the buttons designed to fit precisely don't! :(

A screen shot and the zip of the package:
Title: Re: Lander project
Post by: FellippeHeitor on June 05, 2018, 11:27:53 pm
' - Even with the shrink property set to True,
'  and the buttons designed to fit precisely don't! :(

The .Shrink property is only effective for PictureBox controls. MenuItems and Buttons will adapt the image's size so that the height fits within the button area, respecting the bevels, while maintaining the original aspect ratio. You may reconsider the button size for the images to fit nicer.

The KeyPressed event will be fired for controls that can get focus. As the picturebox control cannot, you are only able to read key presses once a button has focus. You may want to add SetFocus bRotLeft (or to any other button) in the OnLoad event, so that key presses can be accepted from the start.
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 12:51:57 am
bplus,

If the buttons are not the right size, let me know what size you need, and I'll make more...

Here is "Restart".

J
Title: Re: Lander project
Post by: bplus on June 06, 2018, 01:13:51 am
The buttons were made perfectly! The more I look, the more I see the fit, just not what I first expected.
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 02:46:19 am
May I ask what you were expecting?

J
Title: Re: Lander project
Post by: bplus on June 06, 2018, 08:01:13 am
I was expecting the image to completely fill the buttons designated area like in a picture box. When looking carefully, I think I see the beveling and possibly a rectangular "insert area" that was intended. I was not expecting white frames for dark colored button images. But! now that I know what happens I can lighten the forms background color to tone down the white frames, it does look off to the button image color and the Stars background image. Dang! when did I become an interior decorator? :D
Title: Re: Lander project
Post by: bplus on June 06, 2018, 08:29:33 am
' - Even with the shrink property set to True,
'  and the buttons designed to fit precisely don't! :(

The .Shrink property is only effective for PictureBox controls. MenuItems and Buttons will adapt the image's size so that the height fits within the button area, respecting the bevels, while maintaining the original aspect ratio. You may reconsider the button size for the images to fit nicer.

The KeyPressed event will be fired for controls that can get focus. As the picturebox control cannot, you are only able to read key presses once a button has focus. You may want to add SetFocus bRotLeft (or to any other button) in the OnLoad event, so that key presses can be accepted from the start.

I looked all over for some dang reference to setfocus in the Wiki, I did find FocusIn and FocusOut described but nothing about SetFocus which should be a word on the list there. I did not try search... now that I think of it.

Also if you have something about z order of controls (for tabbing and focus...), that is important to describe how it works and set / reset order.

Also what do you think about a board for InForm and Collecting notes for Wiki, here or at least a dedicated thread pinned. You'd probably prefer GitHub?

OK so how much area is taken away for button beveling? is it a percent or hard number? ie take off 15% or 15 pixels?
Can we assume the "insert" area for image is in same x, y ratio as width and height of button? (probably since mentioned in quote.)
Can we control the color of bevel? (because neither fore nor back color effect it and it is white before a button gets focus so focus color doesn't help.)

Also I did stumble upon a bunch of message box constants, that would imply there is message box service but not on the linked word list.

I've got to remember to try search as well as going down the linked list of key words or topics.

Update: https://github.com/FellippeHeitor/InForm/search?
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 08:36:17 am
Hmm... Beveled inserted picture boxes. Interesting. I had considered a bevel, but having a button 50 pixels in height, would mean an even smaller area for the picture. A single 'image' in the centre of a rectangular button does look a bit odd... Poor little images look a bit 'lost' in all that space. Shortening the button and increasing the height as well would lend itself to a 'fancier' button or providing space for a more detailed image. Did you have any ideas as to the kind of images you would prefer? After all, the 'text' and 'image' buttons, are basically a sample of what could be done.

Gimp, just like Photoshop, can do a LOT of stuff. If you Google 'gimp buttons' or 'gimp crystal button' you will be presented with a heap of styles. Have a look and if you see anything you like just let me know and I will see what I can do...

J

ps: Are you hinting at the possibility that 'bevel' maybe part of the button drawing process? If so, do you have to use Inform's procedure to draw it? If these are the only buttons, then either draw them the way you are used to, or just 'put' the beasties there and create 'click zones'... Just a suggestion...
Title: Re: Lander project
Post by: bplus on June 06, 2018, 08:52:41 am
Hi Johnno,

Yes, it looks like when we are designing images for buttons we have to take into account built-in beveling from InForm.
Your images do fit fine into the buttons because they had the proper ratios.
It is hard to say further what designs are needed while still exploring how Inform is working.

It may be easier to just redesign the form and button sizes than rework images.

Now that we have mouse locating code for picture box and picture box does take click events, we could put simulated buttons in the picture box but that is kind of silly.

Update: More thought, I like square buttons for picture buttons then we won't have to worry about x, y ratios.
Your thruster button looks like upside down speaker button, confusing me, I think a simple wide arrow up approach might do better.
It looks like Inform can change color when buttons have focus (maybe that's for text only buttons?).

For now, just worry about one main image design before worry about variations for mouse over or clicks. BTW you found the power button design I had in mind for restart.
Title: Re: Lander project
Post by: FellippeHeitor on June 06, 2018, 10:05:50 am
Quote
I looked all over for some dang reference to setfocus in the Wiki, I did find FocusIn and FocusOut described but nothing about SetFocus which should be a word on the list there. I did not try search... now that I think of it.
Well, a book won't get a second edition if no one's reading it. I didn't bother updating the wiki in a while because there was no feedback of anyone reading it, so I'll dedicate some time to getting it up to date with beta 7.

Quote
if you have something about z order of controls (for tabbing and focus...)
Edit -> Z-Ordering.

Quote
what do you think about a board for InForm and Collecting notes for Wiki, here or at least a dedicated thread pinned. You'd probably prefer GitHub?
GitHub does have a dedicated section for issues, but I won't force anyone to make an account. Anywhere you post about InForm here in the forum will catch my attention and I'm always willing to assist, so let's keep it going as we are and it's all good.

Quote
OK so how much area is taken away for button beveling?
In the current XP theme, it's 3 pixels from the top and 3 pixels from the bottom, that is, Control().Height - 6.

Quote
Can we control the color of bevel? (because neither fore nor back color effect it and it is white before a button gets focus so focus color doesn't help.)
Nope. Buttons follow the theme's imagery, in this case Windows XP's silver theme.

Quote
Also I did stumble upon a bunch of message box constants, that would imply there is message box service but not on the linked word list.
Not yet documented, but here goes:
FUNCTION MessageBox& (Message$, Title$, Setup AS LONG)

Not specifying Title$ will have the message box inherit the main form's title/caption.

Setup is a combination (button + icon) of:
Buttons, which can be MsgBox_OkOnly, MsgBox_OkCancel, MsgBox_AbortRetryIgnore, MsgBox_YesNoCancel, MsgBox_YesNo, MsgBox_RetryCancel, MsgBox_CancelTryagainContinue, MsgBox_CancelTryagainContinue.

Icons, which can be MsgBox_Critical, MsgBox_Question, MsgBox_Exclamation, MsgBox_Information

The possible return values are: MsgBox_Ok, MsgBox_Cancel, MsgBox_Abort, MsgBox_Retry, MsgBox_Ignore, MsgBox_Yes, MsgBox_No, MsgBox_Tryagain, MsgBox_Continue.

All combinations of the above work as expected in Windows. For macOS and Linux, you only get OkOnly and YesNo for buttons.

Quote
Now that we have mouse locating code for picture box and picture box does take click events, we could put simulated buttons in the picture box but that is kind of silly.
For goodness sake, don't. If you don't want a button with an image, just place a new PictureBox control in place of the button and respond to the Click event, which will work fine for a picturebox control, but don't _PUTIMAGE the button image onto the main canvas, as that would mean not needing InForm at all and be just silly as you put it.

If you do decide to replace buttons with picturebox controls, you can make use of the MouseEnter and MouseLeave events to use different images for hovered/not hovered, as I cover (although with labels, but the functionality is the same) in this video:
&t=1s
Title: Re: Lander project
Post by: bplus on June 06, 2018, 10:30:25 am
Oh man! Message Box will be handy for debugging. Thanks!

So the reason the buttons have even more silver (not white) showing on sides is because the 6 taken off top + bottom in total, has to be taken off each side individually.

AH! use picture boxes for image buttons. Got it!

Append: Oh hey! that means we can draw our buttons with action stuff...

Man, Inform stock just shot up with interest! We could use fire for thruster button background.
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 11:06:08 am
bplus,

I can do fancy square buttons like this one if you would prefer...

J
Title: Re: Lander project
Post by: bplus on June 06, 2018, 11:24:57 am
Oh that's nice! Red for off, yellow for mouse over and green for go!
Title: Re: Lander project
Post by: Ashish on June 06, 2018, 11:35:14 am
@bplus
Well... You can also use console for debugging. Use use $console and print value to console window. And if you want to go professional, go and check
Fellipe's vWatch64.
Title: Re: Lander project
Post by: FellippeHeitor on June 06, 2018, 12:40:18 pm
@bplus
Well... You can also use console for debugging. Use use $console and print value to console window. And if you want to go professional, go and check
Fellipe's vWatch64.

As much as I appreciate the recommendation, I must warn you guys that, given InForm's complexity, it doesn't play along well with vWATCH64 in the current version of the debugger.
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 05:44:44 pm
Oh that's nice! Red for off, yellow for mouse over and green for go!

These things look SO good when they are 300x300 pixels... Not too sure about 50x50. I will give it a bash but will also do a 100x100. Give me a little while and I will post the results. Warning: Compared to the games' current 'look', this little puppy, is going to 'stand out'. I will attempt to mock up something that will, more or less, 'fit in' with the decor... lol

Stay tuned...

J
Title: Re: Lander project
Post by: bplus on June 06, 2018, 07:08:06 pm
Oh hey Johnno,

The picture boxes on forms can shrink images to fit box, also what we loose in width (200) we can gain in height (50) so maybe 100 x 100?

Also because they are picture boxes, we might play around with some live drawing effects.
Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 07:31:42 pm
I figured you might go with 100x100.

The buttons are 'ok' at 100x100 (slightly 'grainy' for my liking...) but 50x50 is well... you can guess... lol

Here are the 3 'Restart' buttons. It took ages to make just one! But, once it was made, the second and third only needed to change the 'colour' layer of the image.

I need more coffee... Phew!

J

ps: I have saved the layered image file... just in case...
Title: Re: Lander project
Post by: bplus on June 06, 2018, 07:54:20 pm
Very nice, Johnno!

I am thinking of color coded landing lights at each of the 4 bases, each color represents a certain amount of points.

Then when refueled at base a new set of lights to choose to fly to and land... ? So you can choose your level of play as you go.

Maybe ships will experience attacks of flies!  ;-))

Title: Re: Lander project
Post by: johnno56 on June 06, 2018, 08:09:47 pm
Sounds a bit like, I think it was for a Microbee computer, a vector-type lander game. Ship launches from a pad and has to reach the next pad before running out of fuel and so on until the end. Degree of difficulty increased by extending the flightpath. Later 'way stops' for fuel was added (but not a 'full tank') to maybe get you to the next pad. Later again the introduction of 'foreign' objects to make you use more fuel in avoiding them. (no weapons... nuts)  It was a very simple game. 'Line drawings' (no colour) and the arrow keys. If I can find a link I'll share it. Game is quite old, but with a bit of 'slight of hand' and a bucket load of TLC, it could be made to 'live again'....

J

ps: The introduction of the "dark" landscape certainly adds another degree of difficulty. Good think you popped in the coloured line... Took a few 'crispy' landings to finally survive... Cool.