Pinball/src/utilities.h

122 lines
2.8 KiB
C

#ifndef UTILITIES_H
#define UTILITIES_H
#include "vector2D.h"
#include <azur/gint/render.h>
#include <math.h>
#include <num/num.h>
void azrp_draw_text(int x, int y, char const *fmt, ...) {
char str[128];
va_list args;
va_start(args, fmt);
vsnprintf(str, 128, fmt, args);
va_end(args);
extern bopti_image_t img_font;
for (int i = 0; str[i]; i++) {
if (str[i] < 32 || str[i] >= 0x7f)
continue;
int row = (str[i] - 32) >> 4;
int col = (str[i] - 32) & 15;
azrp_subimage(x + 5 * i, y, &img_font, 7 * col + 1, 9 * row + 1, 6, 8,
DIMAGE_NONE);
}
}
void azrp_draw_pinball(int x, int y, uint16_t color, char const *fmt, ...) {
char str[128];
va_list args;
va_start(args, fmt);
vsnprintf(str, 128, fmt, args);
va_end(args);
extern bopti_image_t img_font_pinball;
for (int i = 0; str[i]; i++) {
if (str[i] < 32 || str[i] >= 0x7f)
continue;
int row = (str[i] - 32) >> 4;
int col = (str[i] - 32) & 15;
azrp_subimage_p8_dye(x + 11 * i, y, &img_font_pinball, 14 * col + 1,
20 * row + 2, 11, 14, IMAGE_DYE, color);
}
}
libnum::num32 COS(libnum::num32 angle) {
float a = (float)angle;
float c = cos(a);
return libnum::num32(c);
// return cos_num32( angle );
}
libnum::num32 SIN(libnum::num32 angle) {
float a = (float)angle;
float s = sin(a);
return libnum::num32(s);
// return sin_num32( angle );
}
extern libnum::num32 flipperHeight;
extern libnum::num32 cScale;
extern libnum::num32 simWidth;
extern libnum::num32 simHeight;
/* return the scaled x component of a vector */
uint16_t CX(Vector2D pos) { return (int)(pos.x * cScale) + 25; }
/* return the scaled y component of a vector */
uint16_t CY(Vector2D pos) {
return (int)(libnum::num32(azrp_height) - pos.y * cScale);
}
/* return the scaled disctance given in argument (typically for circles radii)
*/
uint16_t CR(libnum::num distance) { return (int)(distance * cScale); }
/* Some usefull macros */
#define MIN(a, b) (((a) >= (b)) ? (b) : (a))
#define MAX(a, b) (((a) <= (b)) ? (b) : (a))
#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define SIGN(a) ((a) < 0 ? -1 : (a > 0) ? +1 : 0)
/* Some constants */
#define PI 3.14159265
/* usual colors*/
#define RGB565_BLACK 0x0000
#define RGB565_RED 0xF800
#define RGB565_GREEN 0x07E0
#define RGB565_BLUE 0x001F
#define RGB565_YELLOW 0xFFE0
#define RGB565_PURPLE 0xF81F
#define RGB565_CYAN 0x07FF
#define RGB565_WHITE 0xFFFF
/* advanced palette */
#define RGB565_DARKORANGE 0xF280
#define RGB565_ORANGE 0xF4A0
#define RGB565_LIGHORANGE 0xF5C0
#define RGB565_LEMONYELLOW 0xF7C6
#define RGB565_APPLEGREEN 0xCF25
#define RGB565_LEAFGREEN 0x6566
#define RGB565_OCEANBLUE 0x0479
#define RGB565_AZURBLUE 0x023E
#define RGB565_DEEPBLUE 0x3813
#define RGB565_DEEPPURPLE 0x8015
#define RGB565_CHERRYRED 0xA0C9
#define RGB565_BLOODYRED 0xF122
#endif