From c50577e788ecd8745471a90f8bfd4dd98b73421e Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 18 2024 13:54:06 +0000 Subject: update example --- diff --git a/example/snake.c b/example/snake.c index 97ae3e5..6d2958e 100644 --- a/example/snake.c +++ b/example/snake.c @@ -26,7 +26,7 @@ enum GameMode { int grid[WIDTH][HEIGHT]; Sprite sprites[WIDTH][HEIGHT]; -Group gridGroup, storage; +Group gridGroup; Sound nom, cut; @@ -269,19 +269,10 @@ void init() { font = createFont("data/fonts/blackcry.ttf"); textFont(font); - storage = createGroup(); - Animation tiles[6] = { tileWall, tileFood, tileHead, tileBody, tileBend, tileTail }; - for(int i = 0; i < 6; ++i) { - Sprite s = createSprite(0, 0); - spriteSetAnimation(s, tiles[i]); - groupAdd(storage, s); - } - groupSetVisibleEach(storage, FALSE); - gridGroup = createGroup(); for(int x = 0; x < WIDTH; ++x) { for(int y = 0; y < HEIGHT; ++y) { - Sprite s = createSpriteEx((x + 0.5)*SIZE, (y + 0.5)*SIZE, SIZE, SIZE); + Sprite s = createSprite((x + 0.5)*SIZE, (y + 0.5)*SIZE, SIZE, SIZE); spriteSetShapeColor(s, colorByName("transparent")); groupAdd(gridGroup, s); sprites[x][y] = s; @@ -296,8 +287,8 @@ void init() { void draw() { - double cx = worldGetWidth()/2.0; - double cy = worldGetHeight()/2.0; + double cx = windowGetWidth()/2.0; + double cy = windowGetHeight()/2.0; if (mode == PLAY) { int prevdx = snake[0][0] - snake[1][0]; @@ -318,14 +309,14 @@ void draw() { drawSprites(); fill(colorByRGBA(1, 1, 1, 0.25)); - rect(0, 0, worldGetWidth(), worldGetHeight()); + rect(0, 0, windowGetWidth(), windowGetHeight()); noFill(); textAlign(HALIGN_CENTER, HALIGN_CENTER); textSize(24); - text("Game Over", cx, cy); + text(cx, cy, "Game Over"); textSize(12); - text("press enter", cx, cy + 24); + text(cx, cy + 24, "Game Over"); if (keyWentDown("return")) mode = MENU; if (keyWentDown("escape")) mode = MENU; } else @@ -333,12 +324,12 @@ void draw() { drawSprites(); fill(colorByRGBA(1, 1, 1, 0.25)); - rect(0, 0, worldGetWidth(), worldGetHeight()); + rect(0, 0, windowGetWidth(), windowGetHeight()); noFill(); textAlign(HALIGN_CENTER, VALIGN_CENTER); textSize(24); - text("Press enter to start", cx, cy); + text(cx, cy, "Press enter to start"); if (keyWentDown("return")) mode = PLAY; if (keyWentDown("escape")) mode = MENU; } else @@ -348,29 +339,30 @@ void draw() { textSize(24); int x = cx - 100; int y = cy - 24*3; - text("Select difficulty level:", x, y); y += 24; - text("1 - very easy", x, y); y += 24; - text("2 - easy", x, y); y += 24; - text("3 - medium", x, y); y += 24; - text("4 - hard", x, y); y += 24; - text("5 - very hard", x, y); y += 24; + text(x, y, "Select difficulty level:"); y += 24; + text(x, y, "1 - very easy" ); y += 24; + text(x, y, "2 - easy" ); y += 24; + text(x, y, "3 - medium" ); y += 24; + text(x, y, "4 - hard" ); y += 24; + text(x, y, "5 - very hard" ); y += 24; difficulty = 0; - if (keyWentDown("1")) difficulty = 1; - if (keyWentDown("2")) difficulty = 2; - if (keyWentDown("3")) difficulty = 3; - if (keyWentDown("4")) difficulty = 4; - if (keyWentDown("5")) difficulty = 5; + if (keyWentDown("any 1")) difficulty = 1; + if (keyWentDown("any 2")) difficulty = 2; + if (keyWentDown("any 3")) difficulty = 3; + if (keyWentDown("any 4")) difficulty = 4; + if (keyWentDown("any 5")) difficulty = 5; if (difficulty) restart(); - if (keyWentDown("escape")) worldStop(); + if (keyWentDown("escape")) windowStop(); } } int main() { - worldSetWidth(SIZE * WIDTH); - worldSetHeight(SIZE * HEIGHT); - worldSetFrameRate(FRAMERATE); - worldSetInit(&init); - worldSetDraw(&draw); - worldRun(); - return 0; + windowSetTitle("Snake"); + windowSetWidth(SIZE * WIDTH); + windowSetHeight(SIZE * HEIGHT); + windowSetFrameRate(FRAMERATE); + windowSetInit(&init); + windowSetDraw(&draw); + windowRun(); + return 0; }