Skip to content

Instantly share code, notes, and snippets.

from random import randint
import pygame
from pygame.locals import *
import time
W = 10
PLAYER = 20
ROBOT = 30
DEAD_ROBOT = 35
HAZARD = 40
class State:
state_handlers = {
's_open': ('h_open', 'h_num'),
's_close': ('h_close', 'h_op'),
's_num': ('h_num'),
's_op': ('h_op')
}
state_map = {
'h_open': 's_open',
@nandakoryaaa
nandakoryaaa / merge_sort_bingo.py
Last active February 16, 2023 22:02
Merge sort implementing true external sequential file/stream emulation
def read_chunk(dst, src, chunk_size, pos, len_src):
while chunk_size > 0 and pos < len_src:
dst.append(src[pos])
pos += 1
chunk_size -= 1
return pos
def get_bingo_size(pos, chunk_size, len_src):
if pos + chunk_size > len_src:
return len_src - pos
@nandakoryaaa
nandakoryaaa / apple.rs
Created March 16, 2023 18:19
Apple game initial implementation
extern crate sdl2;
use sdl2::rect::Rect;
use sdl2::pixels::Color;
use sdl2::render::WindowCanvas;
use std::time::Duration;
trait Renderer {
fn render(
& self, canvas: & mut WindowCanvas,
@nandakoryaaa
nandakoryaaa / png2font.php
Last active March 22, 2023 21:41
convert raster font image to array of bitmask bytes
<?php
$infile = $argv[1]; // font image file name
$w = $argv[2]; // font char width
$h = $argv[3]; // font char height
$color_x = $argv[4] ?? 0; // x coordinate of font color sample
$color_y = $argv[5] ?? 0; // y coordinate of font color sample
$img = imagecreatefrompng($infile);
$img_w = imagesx($img);
$img_h = imagesy($img);
@nandakoryaaa
nandakoryaaa / rotate.c
Last active February 14, 2025 22:44
Bitmap rotation in C + SDL2 using Bresenham lines
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#define SURF_W 640
#define SURF_H 640
@nandakoryaaa
nandakoryaaa / 5.c
Created June 3, 2025 09:17
A game of guessing 5-letter words (prototype)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <process.h>
#include <time.h>
#include <string.h>
#define LETTER_CNT 5
typedef enum {
@nandakoryaaa
nandakoryaaa / 5_utf16.c
Created June 7, 2025 10:24
A game of guessing 5-letter Russian words - now with Windows Unicode support
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <process.h>
#include <time.h>
#include <string.h>
#include <windows.h>
#define LETTER_CNT 5
@nandakoryaaa
nandakoryaaa / dict.c
Last active June 10, 2025 15:01
Tree-based word dictionary as a prototype for 5-letter guessing game
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <windows.h>
#define LETTER_CNT 5
#define DICT_NODE_CNT 16384
#define DICT_NIL 16384
@nandakoryaaa
nandakoryaaa / rus5.txt
Created June 10, 2025 15:00
A list of 5-letter Russian words
абака
аббат
абвер
абзац
аборт
абрек
абрис
абхаз
абцуг
абшид