update dino, add to ru game center

This commit is contained in:
rgimad 2025-01-12 15:50:54 +03:00
parent cf354ec8d3
commit cb733c6d1d
6 changed files with 22 additions and 41 deletions

View File

@ -16,6 +16,7 @@ Freecell=games/freecell,68
Pong=games/pong,101
Pong3=games/pong3,12
Arcanii=/kg/arcanii,12
Dino=games/dino,129
[€àª ¤ë]
LaserTank=/kg/lasertank/lasertank,72

View File

@ -7,7 +7,7 @@ KTCC = $(KTCC_DIR)/bin/kos32-tcc
KPACK = kpack
SRC = $(wildcard *.c)
FLAGS= -B$(KTCC_DIR)/bin -I $(KLIBC)/include -Wall -stack=20480
FLAGS= -B$(KTCC_DIR)/bin -I $(KLIBC)/include -Wall# -stack=20480
LIBS = -limg
all: $(SRC)

View File

@ -2,6 +2,7 @@
#define CONFIG_H
#define DEFAULT_WIDTH 600
#define DEFAULT_HEIGHT 200
#define FPS 60
#define DELTA_MS_DEFAULT 20

View File

@ -2,15 +2,12 @@
#include "sprites.h"
#include <assert.h>
/*static*/ ksys_colors_table_t sys_color_table;
/*static*/ ksys_pos_t win_pos;
/*static*/ Image* screenImage;
/*static*/ Image* spriteAtlas;
Image* screenImage;
static Image* spriteAtlas;
void graphicsInit() {
win_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS);
_ksys_get_system_colors(&sys_color_table);
spriteAtlas = img_decode((void*)sprites100, sizeof(sprites100), 0);
*((uint8_t*)spriteAtlas->Palette + 3) = 0; // set black as transparent
// for (int i = 0; i < 16; i++) {
@ -24,23 +21,12 @@ void graphicsInit() {
}
}
dbg_printf("spriteAtlas->Type = %d\n", spriteAtlas->Type);
screenImage = img_create(DEFAULT_WIDTH, 200, IMAGE_BPP32);
screenImage = img_create(DEFAULT_WIDTH, DEFAULT_HEIGHT, IMAGE_BPP32);
// asm_inline("emms"); // doenst need bec. libimg functions used here does not use mmx (=> does not currept fpu state)
}
// void save_fpu_state(void *fpustate) {
// __asm__("fsave %0" : "=m" (*fpustate) : : "memory");
// }
// void restore_fpu_state(const void *fpustate) {
// __asm__("fnsave %0" : : "m" (*fpustate));
// }
void graphicsBlitAtlasImage(int atlasX, int atlasY, int destX, int destY, int w, int h, bool center) {
// dbg_printf("start graphicsBlitAtlasImage ax = %d ay = %d dx = %d dy = %d w = %d h = %d %x %x\n", atlasX, atlasY, destX, destY, w, h, screenImage, spriteAtlas);
// asm_inline("int $3");
int screen_width = (int)screenImage->Width;
int screen_height = (int)screenImage->Height;
@ -76,12 +62,6 @@ void graphicsBlitAtlasImage(int atlasX, int atlasY, int destX, int destY, int w,
//printf("start graphicsBlitAtlasImage ax = %d ay = %d dx = %d dy = %d w = %d h = %d %x %x\n\n", atlasX, atlasY, destX, destY, w, h, screenImage, spriteAtlas);
// asm_inline("int $3");
/*unsigned char buf[512];
save_fpu_state(buf);
img_blend(screenImage, spriteAtlas, destX, destY, atlasX, atlasY, w, h);
restore_fpu_state(buf);*/
img_blend(screenImage, spriteAtlas, destX, destY, atlasX, atlasY, w, h);
asm_inline("emms");
@ -94,13 +74,7 @@ void graphicsFillBackground(unsigned r, unsigned g, unsigned b) {
void graphicsRender() {
// don't redraw window on each frame. redraw window only when redraw event (called when widow moved e.g.)
//_ksys_start_draw();
//_ksys_create_window(win_pos.x, win_pos.y, screenImage->Width + 10, screenImage->Height + 29, WINDOW_TITLE, sys_color_table.work_area, 0x54); // 0x54. note: C = 1 !!
img_draw(screenImage, 5, 24, screenImage->Width, screenImage->Height, 0, 0);
//ksys_draw_bitmap_palette(screenImage->Data, 5, 24, screenImage->Width, screenImage->Height, 32, 0, 0);
// ksys_blitter_params_t bp = {5, 24, screenImage->Width, screenImage->Height, 0, 0, screenImage->Width, screenImage->Height, screenImage->Data, screenImage->Width*4};
// _ksys_blitter(0, &bp);
//_ksys_end_draw();
}
void graphicsDelay(int ms) {

View File

@ -31,6 +31,8 @@
#define ATLAS_STAR_X 645
#define ATLAS_STAR_Y 2
extern Image* screenImage;
void graphicsInit();
void graphicsBlitAtlasImage(int atlasX, int atlasY, int destX, int destY, int w, int h, bool center);
void graphicsFillBackground(unsigned r, unsigned g, unsigned b);

View File

@ -16,26 +16,29 @@
#include "trex.h"
#include "runner.h"
uint8_t keyboard_layout[128];
extern ksys_colors_table_t sys_color_table;
extern ksys_pos_t win_pos;
extern Image* screenImage;
extern Image* spriteAtlas;
static uint8_t keyboard_layout[128];
int main(int argc, char* args[]) {
srand((unsigned int)time(NULL)); // Seed the random number generator
ksys_pos_t win_pos = _ksys_screen_size();
win_pos.x /= 2;
win_pos.x -= DEFAULT_WIDTH/2;
win_pos.y /= 2;
win_pos.y -= DEFAULT_HEIGHT/2;
dbg_printf("wx = %d, wy = %d\n", win_pos.x, win_pos.y);
ksys_colors_table_t sys_color_table;
_ksys_get_system_colors(&sys_color_table);
_ksys_set_event_mask(0xC0000027); // !
_ksys_set_key_input_mode(KSYS_KEY_INPUT_MODE_SCANC);
_ksys_keyboard_layout(KSYS_KEYBOARD_LAYOUT_NORMAL, keyboard_layout);
graphicsInit();
runnerInit();
dbg_printf("dino started\n");
_ksys_set_event_mask(0xC0000027); // !
_ksys_set_key_input_mode(KSYS_KEY_INPUT_MODE_SCANC);
_ksys_keyboard_layout(KSYS_KEYBOARD_LAYOUT_NORMAL, keyboard_layout);
int ext_code = 0;
uint8_t old_mode = 0;