; ; @ANO_SCRIPT_NAME gui_bobs ; @ANO_SCRIPT_VERSION 0.0.5 ; @ANO_SCRIPT_DESCRIPTION Example how to draw some bobs to window ; ; List of files to unveil if unveil() support is in use: ; ; @ANO_UNVEIL_FILES "examples/datafiles/bob_background.bob = r", \ ; "examples/datafiles/bob_test.bob = r" ; ; @ANO_FLAGS_VAR_NAME_SUBS [x] ; @ANO_FLAGS_VAR_WARN_UNUSED [ ] ; ; Copyright (c) 2016-2024, Jani Salonen ; All rights reserved. ; main { ; Global uninitialized variables var [handle] hnd_wnd var [handle] hnd_container var [handle] hnd_file var [handle] hnd_bcg var [handle] hnd_bob ; Global initialized variables mov x (1) mov y (1) mov dx (4.5) mov dy (0.1) mov gravity (0.2) mov resistance (0.99999) ; Initialize windowing system window_init ; Open main window window_open (\ title_name: "Fun with bobs", \ title_charset: NULL, \ parent_handle: NOPARENT, \ widget_stack_id: NOWIDGET, \ widget_set: NOWIDGET, \ window_refresh_divider: ACTIVE_REFRESH, \ position_x: POS_CENTERED, \ position_y: POS_CENTERED, \ size_width: 640, \ size_height: 480, \ cb_main_loop: "cb_mainloop", \ cb_expose: NULL, \ cb_key_press: NULL, \ cb_key_release: NULL, \ cb_button_press: NULL, \ cb_button_release: NULL, \ cb_client_message: NULL, \ cb_configure_notify: NULL, \ cb_destroy_notify: "cb_destroy", \ cb_motion_notify: NULL, \ cb_map_notify: NULL, \ cb_unmap_notify: NULL, \ cb_open_notify: "cb_open") } callback cb_open (_hnd) { mov hnd_wnd (_hnd) ; Create one bob container, for background and one bob bob_create_container (hnd_wnd, 0) if rc == INVALID : cb_destroy mov hnd_container (rc) ; Create background bob_init_file ("examples/datafiles/bob_background.bob") if rc == INVALID : cb_destroy mov _hnd_file (rc) bob_create_background (_hnd_file, hnd_container, 1, -1) if rc == INVALID : cb_destroy mov hnd_bcg (rc) ; Background is now ready to use and image can be freed bob_free_file (_hnd_file) ; Create bob to go with the background bob_init_file ("examples/datafiles/bob_test.bob") if rc == INVALID : cb_destroy mov hnd_file (rc) bob_create (hnd_file, hnd_container, 0, 640, 480, 0) if rc == INVALID : cb_destroy mov hnd_bob (rc) bob_set_playdirection (hnd_container, hnd_bob, \ PLAY_DIRECTION_FORWARD) bob_set_playmode (hnd_container, hnd_bob, \ PLAY_MODE_LOOP) bob_set_playskip (hnd_container, hnd_bob, 0) bob_set_playspeed (hnd_container, hnd_bob, 0.25) ; Map background and bob to display them bob_set_map (hnd_container, hnd_bcg, \ MAPPED_VISIBLE) bob_set_map (hnd_container, hnd_bob, \ MAPPED_VISIBLE) ; Map main window window_map (hnd_wnd) } callback cb_destroy { ; Free bobs, bob files and the container bob_delete (hnd_container, hnd_bob) bob_delete (hnd_container, hnd_bcg) bob_free_file (hnd_file) bob_delete_container (hnd_container) window_close (hnd_wnd) exit } callback cb_mainloop { ; Bounce the bob mul dx (resistance) add dy (gravity) mul dy (resistance) add x (dx) add y (dy) if x >= 1 : no_a neg dx no_a: if x < 600 : no_b neg dx no_b: if y >= 1 : no_c neg dy no_c: if y < 440 : no_d neg dy no_d: bob_set_position (hnd_container, hnd_bob, x, y) }