Jo Engine  2024.04.28
Jo Sega Saturn Engine
hitbox.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2024, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
34 #ifndef __JO_HITBOX_H__
35 # define __JO_HITBOX_H__
36 
46 static __jo_force_inline bool jo_hitbox_detection(const int sprite_id1, const int x1, const int y1, const int sprite_id2, const int x2, const int y2)
47 {
48  return jo_square_intersect(x1 - JO_DIV_BY_2(__jo_sprite_def[sprite_id1].width),
49  y1 - JO_DIV_BY_2(__jo_sprite_def[sprite_id1].height),
50  __jo_sprite_def[sprite_id1].width,
51  __jo_sprite_def[sprite_id1].height,
52  x2 - JO_DIV_BY_2(__jo_sprite_def[sprite_id2].width),
53  y2 - JO_DIV_BY_2(__jo_sprite_def[sprite_id2].height),
54  __jo_sprite_def[sprite_id2].width,
55  __jo_sprite_def[sprite_id2].height);
56 
57 }
58 
69 static __jo_force_inline bool jo_hitbox_detection_custom_boundaries(const int sprite_id1, const int x1, const int y1, const int x2, const int y2, const int w2, const int h2)
70 {
71  return jo_square_intersect(x1 - JO_DIV_BY_2(__jo_sprite_def[sprite_id1].width),
72  y1 - JO_DIV_BY_2(__jo_sprite_def[sprite_id1].height),
73  __jo_sprite_def[sprite_id1].width,
74  __jo_sprite_def[sprite_id1].height,
75  x2 - JO_DIV_BY_2(w2),
76  y2 - JO_DIV_BY_2(h2),
77  w2,
78  h2);
79 
80 }
81 
82 #endif /* !__JO_HITBOX_H__ */
83 
84 /*
85 ** END OF FILE
86 */
jo_hitbox_detection_custom_boundaries
static __jo_force_inline bool jo_hitbox_detection_custom_boundaries(const int sprite_id1, const int x1, const int y1, const int x2, const int y2, const int w2, const int h2)
Fast method to get if the sprite intersects with the box (HitBox processing)
Definition: hitbox.h:69
JO_DIV_BY_2
#define JO_DIV_BY_2(X)
Devide a variable by 2.
Definition: math.h:144
jo_hitbox_detection
static __jo_force_inline bool jo_hitbox_detection(const int sprite_id1, const int x1, const int y1, const int sprite_id2, const int x2, const int y2)
Fast method to get if two sprites intersects (HitBox processing)
Definition: hitbox.h:46
jo_square_intersect
static __jo_force_inline bool jo_square_intersect(const int x1, const int y1, const int w1, const int h1, const int x2, const int y2, const int w2, const int h2)
Fast method to get if two square intersects (HitBox processing)
Definition: math.h:1747
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
__jo_sprite_def
jo_texture_definition __jo_sprite_def[JO_MAX_SPRITE]
(internal engine usage)