Fix misc math bugs
This commit is contained in:
@ -295,6 +295,24 @@ void sys_map_draw(
|
||||
}
|
||||
}
|
||||
|
||||
sys_maptile sys_map_get(
|
||||
sys_map map,
|
||||
sys_i32 tile_x, sys_i32 tile_y,
|
||||
bool* flag_invalid
|
||||
) {
|
||||
if (flag_invalid != NULL) { *flag_invalid = false; }
|
||||
|
||||
if (
|
||||
tile_x < 0 || tile_y < 0 ||
|
||||
tile_x >= map.width || tile_y >= map.height
|
||||
) {
|
||||
if (flag_invalid != NULL) { *flag_invalid = true; }
|
||||
return 255;
|
||||
}
|
||||
|
||||
return map.tiles[tile_x + map.width * tile_y];
|
||||
}
|
||||
|
||||
// == internal primitives ==
|
||||
void sys_pixel_internal_set(sys_i32 x, sys_i32 y, sys_color c) {
|
||||
sys_color realc = sys_dpal[c];
|
||||
|
@ -179,4 +179,16 @@ void sys_map_draw(
|
||||
// TODO: Layers?
|
||||
);
|
||||
|
||||
/**
|
||||
* Get a single map tile, putting whether the coords were invalid into
|
||||
* flag_invalid.
|
||||
*
|
||||
* (flag_invalid may be null)
|
||||
*/
|
||||
sys_maptile sys_map_get(
|
||||
sys_map map,
|
||||
sys_i32 tile_x, sys_i32 tile_y,
|
||||
bool* flag_invalid
|
||||
);
|
||||
|
||||
#endif // CROCPARTY_SYS_GRAPHICS_H
|
||||
|
@ -25,9 +25,10 @@ bool sys_btn(DeviceButton button) {
|
||||
return sys_input_down_frames[button] >= 1;
|
||||
}
|
||||
|
||||
bool sys_btnp(DeviceButton button) {
|
||||
bool sys_btnp(DeviceButton button, bool repeat) {
|
||||
if (button >= DEVICE_BUTTON_N) { return false; }
|
||||
if (sys_input_down_frames[button] == 1) { return true; }
|
||||
if (!repeat) { return false; }
|
||||
// 31 and every 8 frames after that
|
||||
if (sys_input_down_frames[button] >= 31 && (sys_input_down_frames[button] - 31) % 8 == 0) {
|
||||
return true;
|
||||
|
@ -26,8 +26,9 @@ bool sys_btn(DeviceButton button);
|
||||
/**
|
||||
* Return whether a button was just pressed.
|
||||
*
|
||||
* Repeats after 30 frames, returning true every 8 frames after that.
|
||||
* If `repeat`, then this repeats after 30 frames, returning true every 8
|
||||
* frames after that.
|
||||
*/
|
||||
bool sys_btnp(DeviceButton button);
|
||||
bool sys_btnp(DeviceButton button, bool repeat);
|
||||
|
||||
#endif // SYS_INPUT_H
|
Reference in New Issue
Block a user