Skip to content

Instantly share code, notes, and snippets.

View shorinji's full-sized avatar

Fredrik Fall shorinji

  • Sentor
  • Sweden
View GitHub Profile
local TOPICS=($(cat "${DIR}/../../env/broker/kafka/docker-mounts/topics.txt" | awk 'BEGIN { FS="," } !/^$/{ print $1 }' | xargs))
local OFFSET_FILE=/tmp/delete-offsets.json
local NUM_TOPICS=${#TOPICS[@]}
local TOPIC_INDEX=1
echo -n "{\"partitions\":[" > $OFFSET_FILE
for TOPIC in $TOPICS; do
echo -n "{\"topic\":\"${TOPIC}\",\"partition\":0,\"offset\":-1}" >> $OFFSET_FILE
if [[ $((TOPIC_INDEX + 1)) < $NUM_TOPICS ]]; then
echo -n "," >> $OFFSET_FILE
@shorinji
shorinji / simple-font-thing.py
Last active September 17, 2021 09:53
updated to work with current pygame
import pygame
import time
import sys
width = 800
height = 300
pygame.init()
win = pygame.display.set_mode((width, height))
@shorinji
shorinji / pygame-realign-tiles.py
Created July 5, 2020 19:16
Takes a tileset image with possible spacing and offsets, and realigns it to a proper grid
import pygame
import sys
from pygame.locals import *
TILE_PIXELS = 8
tileGroups = [
{ "x": 1, "y": 11, "tilesW": 16, "tilesH": 16, "offset": 0 },
{ "x": 130, "y": 11, "tilesW": 16, "tilesH": 16, "offset": 0 },
{ "x": 259, "y": 11, "tilesW": 16, "tilesH": 16, "offset": 0 },
@shorinji
shorinji / pygame-transitions.py
Created July 1, 2020 12:57
Simple pygame foundation for transition between different views (for a typical game)
import pygame
import sys
from pygame.locals import *
BACKGROUND_COLOR = pygame.Color(0, 0, 100)
TEXT_COLOR = pygame.Color(255, 255, 255)
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
HALF_SCREEN_WIDTH = SCREEN_WIDTH / 2
HALF_SCREEN_HEIGHT = SCREEN_HEIGHT / 2
@shorinji
shorinji / parallax.py
Created June 27, 2020 12:23
simple parallax scroll in pygame
import sys
import pygame
import math
from pygame.locals import *
TILE_SIZE = 16
HORIZONTAL_TILES = 20
VERTICAL_TILES = 10
SCREEN_WIDTH = TILE_SIZE * HORIZONTAL_TILES
SCREEN_HEIGHT = TILE_SIZE * VERTICAL_TILES
@shorinji
shorinji / dynamic-load.py
Created June 26, 2020 20:51
example snippet of building up filenames and loading images dynamically
walkRightImageCodes = ['A1', 'A2', 'A7', 'Fb9', 'Bx5']
walkRightImageData = []
# easy to read version
for code in walkRightImageCodes:
filename = "%s.png" % code
imageData = pygame.image.load(filename).convert()
walkRightImageData.append(imageData)
import sys
import pygame
import math
from pygame.locals import *
WIDTH = 800
HEIGHT = 600
BLACK = Color(0, 0, 0)
@shorinji
shorinji / pygame_move_smooth.py
Created May 30, 2020 11:59
example of smooth moving over a grid in pygame
import sys
import pygame
import math
from pygame.locals import *
TILE_SIZE = 32
WIDTH = 32 * 20
HEIGHT = 32 * 10
@shorinji
shorinji / game-idea-randomizer.py
Created May 18, 2020 12:45
To help you get (great?) ideas for a game to develop
import random
prefixes = ['',\
'Laser-shooting',\
'Kitten-filled',\
'Smooth-scrolling',\
'Action-packed',\
'Addictive'\
]
@shorinji
shorinji / pygame-water.py
Last active September 12, 2022 19:06
Simple example of an animated water surface in pygame. Updated with a little gradient to the surface
import sys
import pygame
import math
from pygame.locals import *
WIDTH = 800
HEIGHT = 600
BLACK = Color(0, 0, 0)
BLUE = Color(0, 0, 200)