465e1cc4e558fc8a116547c4f72b829f3cfff1f1 — octaspire 5 months ago e0d7b19 v0.475.0
Bounce: implement boxes and add few of them to a level
M dev/include/octaspire/dern/octaspire_dern_config.h => dev/include/octaspire/dern/octaspire_dern_config.h +1 -1
@@ 18,7 18,7 @@ #define OCTASPIRE_DERN_CONFIG_H
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
- #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "474"
+ #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "475"
  #define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \

M release/games/octaspire-bounce.dern => release/games/octaspire-bounce.dern +55 -0
@@ 40,6 40,35 @@ (define bounce-walls     as '() [all walls in the level])
  (define bounce-platforms as '() [all platforms in the level])
  (define bounce-slopes    as '() [all slopes in the level])
+ (define bounce-boxes     as '() [all boxes in the level])
+ 
+ (define bounce-box-add as (fn (x y)
+   (define slot as (bounce-make-empty-slot) [slot for the box])
+   (define box as (chipmunk-cpBodyNew {D+1} {D+1}) [the box body])
+   (chipmunk-cpSpaceAddBody bounce-space box)
+   (define box-shape as
+     (chipmunk-cpBoxShapeNew box {D+4.0} {D+4.0} {D+0.1})
+     [box collision shape])
+   (chipmunk-cpShapeSetFriction box-shape {D+0.8})
+   (chipmunk-cpSpaceAddShape bounce-space box-shape)
+   (chipmunk-cpBodySetPosition        box (chipmunk-cpv x y))
+   (chipmunk-cpBodySetVelocity        box (chipmunk-cpv))
+   (chipmunk-cpBodySetAngularVelocity box {D+0})
+   (= slot 'body box)
+   (= slot 'x1   x)
+   (= slot 'y1   y)
+   (+= bounce-boxes slot))
+   [add new box in the level] '(x [x] y [y]) howto-no)
+ 
+ (define bounce-box-draw as (fn (slot)
+   (define body         as (ln@ slot 'body 'hash) [body of the box])
+   (define pos          as (chipmunk-cpBodyGetPosition body) [position of the box])
+   (define cx           as (* {D+10} (chipmunk-cpv-get-x pos))  [x component])
+   (define cy           as (* {D+10} (chipmunk-cpv-get-y pos))  [y component])
+   (sdl2-glColor4ub {X+0} {X+AA} {X+0} {X+FF})
+   (sdl2-gl-ortho-square-box-rotated cx cy {D+40} (chipmunk-cpBodyGetAngle body))
+   (sdl2-glColor4ub {X+FF} {X+FF} {X+FF} {X+FF}))
+   [draw a box] '(slot [slot containing the box]) howto-no)
  
  (define bounce-wall-add as (fn (x1 y1 x2 y2)
    (define slot as (bounce-make-empty-slot) [slot for the wall])


@@ 180,6 209,7 @@ (= bounce-walls     '())
    (= bounce-platforms '())
    (= bounce-slopes    '())
+   (= bounce-boxes     '())
    (define bounce-space as (chipmunk-cpSpaceNew) [chipmunk space] in (env-global))
    (define gravity as (chipmunk-cpv {D+0} {D-100}) [Gravity vector])
    (chipmunk-cpSpaceSetGravity bounce-space gravity)


@@ 315,6 345,28 @@ (for i from {D+0} to {D+5}
      (bounce-slope-add (+ {D-155} (* i {D+50})) {D+100} (+ {D-125} (* i {D+50})) {D+97})) ; top row
  
+   (bounce-box-add {D-135} {D+101})
+   (bounce-box-add {D-85}  {D+101})
+   (bounce-box-add {D-35}  {D+101})
+   (bounce-box-add {D+15}  {D+101})
+   (bounce-box-add {D+65}  {D+101})
+ 
+   (bounce-wall-add {D-155} {D+90} {D+120} {D+90}) ; separator
+   (bounce-wall-add {D-155} {D+90} {D-155} {D+94}) ; separator left end
+   (bounce-wall-add {D+120} {D+90} {D+120} {D+94}) ; separator right end
+ 
+   (for i from {D+1} to {D+5}
+     (bounce-slope-add (+ {D-155} (* i {D+50})) {D+57} (+ {D-125} (* i {D+50})) {D+60})) ; 2. row
+ 
+   (bounce-slope-add {D+125} {D+60} {D+155} {D+105})
+ 
+   (bounce-box-add {D+123} {D+64})
+   (bounce-box-add {D+123} {D+67})
+ 
+   (bounce-wall-add {D-115} {D+50} {D+120} {D+50}) ; separator
+   (bounce-wall-add {D-115} {D+50} {D-115} {D+54}) ; separator left end
+   (bounce-wall-add {D+120} {D+50} {D+120} {D+54}) ; separator right end
+ 
    (bounce-ball-add  {D-154} {D+120}))
    [load a level] '() howto-no)
  


@@ 415,6 467,9 @@ ; platforms
    (for i in bounce-platforms
         (bounce-platform-draw i))
+   ; boxes
+   (for i in bounce-boxes
+        (bounce-box-draw i))
    ; slopes
    (for i in bounce-slopes
      (bounce-slope-draw i))

M release/octaspire-dern-amalgamated.c => release/octaspire-dern-amalgamated.c +1 -1
@@ 26224,7 26224,7 @@ #define OCTASPIRE_DERN_CONFIG_H
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_MAJOR "0"
- #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "474"
+ #define OCTASPIRE_DERN_CONFIG_VERSION_MINOR "475"
  #define OCTASPIRE_DERN_CONFIG_VERSION_PATCH "0"
  
  #define OCTASPIRE_DERN_CONFIG_VERSION_STR "Octaspire Dern version " \

M release/plugins/dern_sdl2.c => release/plugins/dern_sdl2.c +106 -0
@@ 5393,6 5393,100 @@ return octaspire_dern_vm_create_new_value_boolean(vm, true);
  }
  
+ octaspire_dern_value_t *dern_sdl2_gl_ortho_square_box_rotated(
+     octaspire_dern_vm_t * const vm,
+     octaspire_dern_value_t * const arguments,
+     octaspire_dern_value_t * const environment)
+ {
+     OCTASPIRE_HELPERS_UNUSED_PARAMETER(environment);
+ 
+     size_t const         stackLength     = octaspire_dern_vm_get_stack_length(vm);
+     char   const * const dernFuncName    = "sdl2-gl-ortho-box-rotated";
+     size_t const         numArgsExpected = 4;
+ 
+     size_t const numArgs =
+         octaspire_dern_value_as_vector_get_length(arguments);
+ 
+     if (numArgs != numArgsExpected)
+     {
+         octaspire_helpers_verify_true(
+             stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+         return octaspire_dern_vm_create_new_value_error_format(
+             vm,
+             "Builtin '%s' expects %zu arguments. "
+             "%zu arguments were given.",
+             dernFuncName,
+             numArgsExpected,
+             numArgs);
+     }
+ 
+     // x y width degrees
+     float args[4] = {0};
+ 
+     for (size_t i = 0; i < numArgsExpected; ++i)
+     {
+         octaspire_dern_value_t const * arg =
+             octaspire_dern_value_as_vector_get_element_at_const(arguments, i);
+ 
+         octaspire_helpers_verify_not_null(arg);
+ 
+         if (!octaspire_dern_value_is_number(arg))
+         {
+             octaspire_helpers_verify_true(
+                 stackLength == octaspire_dern_vm_get_stack_length(vm));
+ 
+             return octaspire_dern_vm_create_new_value_error_format(
+                 vm,
+                 "Builtin '%s' expects number as %zu. argument. "
+                 "Type '%s' was given.",
+                 dernFuncName,
+                 i + 1,
+                 octaspire_dern_value_helper_get_type_as_c_string(arg->typeTag));
+         }
+ 
+         args[i] = octaspire_dern_value_as_number_get_value(arg);
+     }
+ 
+ #ifdef OCTASPIRE_DERN_SDL2_PLUGIN_USE_OPENGL2_LIBRARY
+     glPushMatrix();
+     glMatrixMode(GL_MODELVIEW);
+     glLoadIdentity();
+     glTranslatef(args[0], args[1], 0);
+     glRotatef(OCTASPIRE_RADIAN_AS_DEGREES * args[3], 0, 0, 1);
+     glTranslatef(-args[0], -args[1], 0);
+ 
+     float const hw = 0.5f * args[2];
+ 
+     glBegin(GL_LINE_LOOP);
+     glVertex2f(args[0] - hw, args[1] - hw);
+     glVertex2f(args[0] - hw, args[1] + hw);
+     glVertex2f(args[0] + hw, args[1] + hw);
+     glVertex2f(args[0] + hw, args[1] - hw);
+     glEnd();
+ 
+     // x in the middle
+     glBegin(GL_LINES);
+     glVertex2f(args[0] - hw, args[1] - hw);
+     glVertex2f(args[0] + hw, args[1] + hw);
+ 
+     glVertex2f(args[0] - hw, args[1] + hw);
+     glVertex2f(args[0] + hw, args[1] - hw);
+     glEnd();
+     glPopMatrix();
+ #else
+     octaspire_helpers_verify_true(stackLength == octaspire_dern_vm_get_stack_length(vm));
+     return octaspire_dern_vm_create_new_value_error_format(
+         vm,
+         "Builtin '%s' failed."
+         "Dern SDL2 plugin is compiled without OpenGL support.",
+         dernFuncName);
+ #endif
+ 
+     octaspire_helpers_verify_true(stackLength == octaspire_dern_vm_get_stack_length(vm));
+     return octaspire_dern_vm_create_new_value_boolean(vm, true);
+ }
+ 
  octaspire_dern_value_t *dern_sdl2_gl_ortho_star_rotated(
      octaspire_dern_vm_t * const vm,
      octaspire_dern_value_t * const arguments,


@@ 8546,6 8640,18 @@       if (!octaspire_dern_vm_create_and_register_new_builtin(
              vm,
+             "sdl2-gl-ortho-square-box-rotated",
+             dern_sdl2_gl_ortho_square_box_rotated,
+             5,
+             "(sdl2-gl-ortho-square-box-rotated x y width degrees) -> true or error",
+             true,
+             targetEnv))
+     {
+         return false;
+     }
+ 
+     if (!octaspire_dern_vm_create_and_register_new_builtin(
+             vm,
              "sdl2-gl-ortho-star-rotated",
              dern_sdl2_gl_ortho_star_rotated,
              5,