TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

OO Language in 5000 lines of C++

5 pointsby turkeynecks7 months ago
This simplified example creates 4 buttons that each play a different sound, accessible with mouse, keyboard and gamepad. It&#x27;s called BooBoo. You can find it on Codeberg.<p>number sfx1 sfx2 sfx3 sfx4 mml_load sfx1 &quot;sfx&#x2F;b1.mml&quot; mml_load sfx2 &quot;sfx&#x2F;b2.mml&quot; mml_load sfx3 &quot;sfx&#x2F;b3.mml&quot; mml_load sfx4 &quot;sfx&#x2F;b4.mml&quot;<p>map c b1 b2 b3 b4 map_set c &quot;type&quot; &quot;window&quot; map_set c &quot;draw&quot; draw_window map_set c &quot;event&quot; null_event call_result b1 mkbutton &quot;Elixir&quot; sfx1 call_result b2 mkbutton &quot;Holy Water&quot; sfx2 call_result b3 mkbutton &quot;Potion&quot; sfx3 call_result b4 mkbutton &quot;Potion Omega&quot; sfx4<p>number font font_load font &quot;vga.ttf&quot; 12 1<p>number container w1 w2 w3 w4<p>widget_create container 200 200 c widget_set_accepts_focus container FALSE widget_create w1 0.5 0.5 b1 widget_set_parent w1 container widget_create w2 0.5 0.5 b2 widget_set_parent w2 container widget_create w3 0.5 0.5 b3 widget_set_break_line w3 TRUE widget_set_parent w3 container widget_create w4 0.5 0.5 b4 widget_set_parent w4 container<p>widget_set_padding w1 5 widget_set_padding w2 5 widget_set_padding w3 5 widget_set_padding w4 5<p>gui_start container<p>gui_set_focus w1<p>function draw_window x y w h focussed data { filled_rectangle 0 0 255 255 0 0 255 255 0 0 255 255 0 0 255 255 x y w h }<p>function draw_button x y w h focussed data { number r g b if (== focussed TRUE) yellow white = r 255 = g 255 = b 0 :yellow = r 255 = g 255 = b 255 :white number tw th font_width font tw [data &quot;text&quot;] font_height font th<p>number xx yy = xx (+ x (&#x2F; w 2)) - xx (&#x2F; tw 2) = yy (+ y (&#x2F; h 2)) - yy (&#x2F; th 2)<p>filled_rectangle 0 0 255 255 0 0 255 255 0 255 255 255 0 255 255 255 x y w h rectangle r g b 255 x y w h 2 font_draw font r g b 255 [data &quot;text&quot;] xx yy :draw_button }<p>function null_event type a b c d x y w h focussed data { }<p>function button_event type a b c d x y w h focussed data { if (&amp;&amp; (== type EVENT_MOUSE_DOWN) (== a 1)) play number on_button call_result on_button owned x y w h c d if (== on_button TRUE) really_play mml_play [data &quot;sfx&quot;] 1 0 :really_play :play<p>if (&amp;&amp; (== TRUE focussed) (|| (&amp;&amp; (== type EVENT_KEY_DOWN) (== KEY_RETURN a)) (&amp;&amp; (== type EVENT_JOY_DOWN) (== a JOY_A)))) play_it mml_play [data &quot;sfx&quot;] 1 0 :play_it }<p>function mkbutton text sfx { map m map_set m &quot;type&quot; &quot;button&quot; map_set m &quot;text&quot; text map_set m &quot;sfx&quot; sfx map_set m &quot;draw&quot; draw_button map_set m &quot;event&quot; button_event return m }<p>function owned wx wy ww wh x y { if (|| (&lt; x wx) (&lt; y wy) (&gt;= x (+ wx ww)) (&gt;= y (+ wy wh))) nope return FALSE :nope return TRUE }<p>function gui_event id type a b c d x y w h focussed data { call [data &quot;event&quot;] type a b c d x y w h focussed data }<p>function gui_draw id x y w h focussed data { call [data &quot;draw&quot;] x y w h focussed data }

2 comments

turkeynecks7 months ago
Yes it does accept this formatting, although it&#x27;s messed up. Here it is formatted <a href="https:&#x2F;&#x2F;pastebin.com&#x2F;ueayaFkn" rel="nofollow">https:&#x2F;&#x2F;pastebin.com&#x2F;ueayaFkn</a>
etcd7 months ago
Is this open source?
评论 #41897884 未加载