Skip to content

Instantly share code, notes, and snippets.

@Kaiochao
Kaiochao / SubPixelMovement.dm
Last active June 24, 2017 04:43
BYOND Sub-Pixel Movement allows for moving by any floating-point number of pixels.
atom/movable
var
sub_step_x = 0
sub_step_y = 0
proc
PixelMove(x, y)
var
whole_x = 0
whole_y = 0
@Kaiochao
Kaiochao / Vector2.dm
Created June 3, 2017 01:29
BYOND 2D Vectors
vector2
var
x
y
New(x = 0, y = 0)
src.x = x
src.y = y
proc
@Kaiochao
Kaiochao / PixelPositions.dm
Created June 3, 2017 01:08
BYOND Pixel Positions
atom
proc
Width()
return TileWidth
Height()
return TileHeight
LowerX()
return (x - 1) * TileWidth
@Kaiochao
Kaiochao / MousePosition.dm
Last active June 5, 2017 00:25
BYOND Mouse Position Tracking
/*
Requires TileWidth and TileHeight to be defined.
e.g. with #define or global constants to match world.icon_size (default 32x32).
Clients have a mouse: client.mouse.
(mouse.X(), mouse.Y()) is the pixel coordinate of the mouse in the screen.
The bottom-left pixel of the screen is (1, 1).
"Screen" refers to the space where atoms on the map and HUD are drawn, not the computer screen.
@Kaiochao
Kaiochao / tasks.json
Created January 10, 2017 23:09
Task runner for working with Dream Maker in Visual Studio Code: Compile in Dream Maker, Run in Dream Seeker, Run in Dream Daemon.
{
"version": "0.1.0",
"command": " ",
"isShellCommand": true,
"suppressTaskName": true,
"args": [],
"tasks": [
{
"taskName": "Compile",
"showOutput": "always",

Keyboard

by Kaiochao

Library URL: http://www.byond.com/developer/Kaiochao/Keyboard

Additions

In the Object tab of Dream Maker, enable "Show all nodes" at the bottom. Compile or Update if you haven't already. Double-click any of the nodes to go to their (latest) definition.

entity/platformer
var
max_speed
axis_smoothing
gravity = 2
jump_speed = 10
jump_time = 3
fall_jump_time = 2 // time after leaving the ground that you can still jump
entity/topdown_ship
var
max_speed
acceleration
drag
max_turn_rate
angle = 0
tmp
@Kaiochao
Kaiochao / pick_weighted.dm
Created January 18, 2015 00:30
Pseudo-randomly pick an item from a list using its associated weight.
// e.g. stuff = list(A = 25, B = 10) (null gets as 65% chance)
proc/pick_weighted(stuff[])
if(args.len > 1) stuff = args.Copy()
var random = rand() * 100, a = 0, b, chance
for(var/item in stuff)
chance = stuff[item]
b = a + chance
if(random in a to b) return item
a = b