Author |
Topic: Example program challenge (Read 3989 times) |
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #30 on: Jan 26th, 2017, 9:44pm » |
|
on Jan 26th, 2017, 7:55pm, hellomike wrote:| feel free to comment on the updated source and then we can agree on the final version tomorrow. |
|
It seems fine on a quick test. I've only noticed one thing which may need attention: I copied ClearSans-Bold.ttf into my @lib$ folder, just to see the difference, but to my eyes the positioning looks a little low. See the image below.
Richard.

|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #31 on: Jan 27th, 2017, 09:51am » |
|
on Dec 11th, 2016, 09:55am, Richard Russell wrote:| ● Run in both BB4W and BBCSDL (so either not using any API functions, or ones that have an equivalent in both). |
|
I'd like to clarify something that has the potential for a misunderstanding. Whilst the use of API functions is acceptable, when there are equivalents in both BB4W and BBCSDL, the objective should be to make the two versions behave as similarly as possible. I do not want example programs to favour one platform over another, so I definitely won't accept conditional code designed to exploit a feature that only a subset of the platforms have, to the detriment of the others.
Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #32 on: Jan 27th, 2017, 3:00pm » |
|
It indeed looks a bit like it. The values in the TH&() array I obtained by calling "GetTextExtentExPoint" in the BB4W version, but maybe I made a thinking error.
For testing this, change the PROCPrint to Code: DEF PROCPrint LOCAL row%, col%, cell%, x0%, y0%, s$, b$, lpsize{} DIM lpsize{w%,h%} REM Clear header area and update score/best text. GCOL 1 : RECTANGLE FILL 0, WH% - HEADER%, WW% , HEADER% GCOL 15 RECTANGLE WW% - 480 - BORDER%, WH% - HEADER%, 240, 100 RECTANGLE WW% - 240 - BORDER%, WH% - HEADER%, 240, 100 OSCLI FONTCMD$ + "12" MOVE WW% - 450, WH% - 20 + BASE%: PRINT "SCORE" MOVE WW% - 190, WH% - 20 + BASE%: PRINT "BEST" s$ = STR$Score% b$ = STR$Best% OSCLI FONTCMD$ + "20" MOVE WW% - 360 - BORDER% - LENs$ * 14, WH% - 50 + BASE%: PRINT s$ MOVE WW% - 120 - BORDER% - LENb$ * 14, WH% - 50 + BASE%: PRINT b$ REM Refresh the matrix cell by cell. FOR row% = 0 TO MAX% FOR col% = 0 TO MAX% x0% = BORDER% + col% * (AREA% + BORDER%) y0% = BORDER% + (MAX% - row%) * (AREA% + BORDER%) cell% = Board&(col%, row%) COLOUR 2, R&(cell%), G&(cell%), B&(cell%) GCOL 2 : RECTANGLE FILL x0%, y0%, AREA%, AREA% IF cell% > 0 THEN GCOL 15 + 15 * (cell% < 3) OSCLI FONTCMD$ + STR$(44 + 12 * (cell% > 6) + 6 * (cell% > 9)) IF (INKEY(-256) == &57) THEN SYS "GetTextExtentExPoint",@memhdc%,STR$(2^cell%),LENSTR$(2^cell%),0,0,0,lpsize{} OSCLI FONTCMD$ + "10" MOVE x0% + 20, y0% + 40 : PRINT "w = ";lpsize.w%;" h = ";lpsize.h% TW&(cell%) = lpsize.w% : TH&(cell%) = lpsize.h% OSCLI FONTCMD$ + STR$(44 + 12 * (cell% > 6) + 6 * (cell% > 9)) ENDIF MOVE x0% + AREA% / 2 - TW&(cell%), y0% + AREA% / 2 + TH&(cell%) : PRINT ;2^cell% ENDIF NEXT NEXT ENDPROC If there is a similar call for that in SDL I would prefer that above using the TW&() and TH&() arrays of course.
Mike
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #33 on: Jan 27th, 2017, 3:05pm » |
|
and remove qq from this line in PROCSetup of course.... Code: FONTCMD$ = "FONT Cqqlear Sans Bold," ::)
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #34 on: Jan 27th, 2017, 4:07pm » |
|
on Jan 27th, 2017, 3:00pm, hellomike wrote:| If there is a similar call for that in SDL I would prefer that above using the TW&() and TH&() arrays of course. |
|
You should be able to use the SDL API TTF_SizeText (or TTF_SizeUTF8 or TTF_SizeUNICODE as appropriate). No more complicated than GetTextExtentPoint32 in Windows as far as I can see. Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #35 on: Jan 27th, 2017, 6:42pm » |
|
Ah yes. If I knew sooner I would have used it avoiding the TW&() and TH&() arrays all together. But like I said before, I had no experience with SDL other than playing with the example programs. Starting now would require new time testing etc. So lets stick to the current code.
The final version that I'm happy with is at:
But I will still be available to make modifications if needed before 0.16 is released.
https://www.dropbox.com/s/lpijt4pt3of5rwv/2048.bbc?dl=0
Thanks
Mike
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #36 on: Jan 27th, 2017, 8:00pm » |
|
on Jan 27th, 2017, 6:42pm, hellomike wrote:| But like I said before, I had no experience with SDL other than playing with the example programs. |
|
Honestly, I think the trick is not so much having experience (I have little of that myself) but the knack of knowing what to search for. I guessed that it was a TTF_ function that you needed.
Quote:| The final version that I'm happy with is at: |
|
Thanks. I'll merge in my additions and upload a release candidate.
Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #38 on: Jan 29th, 2017, 09:16am » |
|
Yes. The animation makes it more fun to play.
The next link is candidate #2. https://www.dropbox.com/s/79a2azuku11xfi9/2048rc2.bbc?dl=0
Few last minute changes / additions are:
Remark giving you credit for the animation codeRemoved 'IF Direction% > 0 AND Direction% < 5 THEN' from the main code because that test is now done in FNGetDirectionAdded a BB4W% constantNew code for PROCSpawn as the previous wasn't random enoughAdded Animate% boolean If you're fine with it, lets release it.
Mike
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #39 on: Jan 29th, 2017, 1:00pm » |
|
on Jan 29th, 2017, 09:16am, hellomike wrote:| If you're fine with it, lets release it. |
|
Yes, I'm happy with it. To be very pedantic (and it's clear that you share my preferences!) I might debate with you whether your new animate Boolean should have a global-variable-style decoration (Animate%) or a constant-style decoration (ANIMATE%). But this is splitting hairs.
Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #40 on: Jan 29th, 2017, 1:37pm » |
|
Yes, it actually is a constant. But if that turns out to be the only 'flaw' in our program (code), I'm very proud of the result. 
It was nice to cooperate like this and I'm looking forward to the release of BBCSDL 0.16.
Take care Richard.
Mike
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #41 on: Jan 29th, 2017, 2:25pm » |
|
on Jan 29th, 2017, 1:37pm, hellomike wrote:| It was nice to cooperate like this and I'm looking forward to the release of BBCSDL 0.16. |
|
All being well it should be released on 1st February (Wednesday) for Windows, Linux (x86), Mac OS-X and Android.
Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #42 on: Jan 30th, 2017, 07:26am » |
|
I now see that, since MID$(s$,0,1) seems to work as MID$(s$,1,1), a bug is avoided in PROCSpawn.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Example program challenge
« Reply #43 on: Jan 30th, 2017, 11:15am » |
|
on Jan 30th, 2017, 07:26am, hellomike wrote:| I now see that, since MID$(s$,0,1) seems to work as MID$(s$,1,1), a bug is avoided in PROCSpawn. |
|
Probably better not to rely on it though, because AFAIK it's undocumented behaviour. What modification would you suggest to make it 'kosher'?
Richard.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #44 on: Jan 30th, 2017, 5:25pm » |
|
Since inline condition is already used elsewhere in the program, e.g. like in the line immediately following it, lets change Code:i% = ASCMID$(zeros$, RND(LENzeros$), 1) to Code:i% = ASCMID$(zeros$, RND(LENzeros$) - (LENzeros$ == 1), 1) Thanks
Mike
|
|
Logged
|
|
|
|
|