Last active
June 11, 2021 21:50
-
-
Save Rabios/49efa3c4a9c54f83a7e75a6620d9cd74 to your computer and use it in GitHub Desktop.
rabios.github.io's Gists load place!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function A() { B(); } | |
function B() { A(); } | |
//B(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arr2obj(array) { | |
var result = {}; | |
for (var i = 0; i < array.length; i++) { | |
result[(i).toString()] = array[i]; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Detects if array matches with another in length and elements | |
def arr_match(arr1, arr2) | |
if arr1.length != arr2.length | |
return false | |
else | |
matches = 0 | |
arr1.length.times.map do |i| | |
if arr1[i] == arr2[i] | |
matches += 1 | |
end | |
end | |
return matches == arr1.length | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.take = function(n, m) { | |
var result = []; | |
if (!m) { | |
for (var i = 0; i < n; i++) { | |
result[i] = this[i]; | |
} | |
} else { | |
for (var i = n; i < m; i++) { | |
result[i] = this[i]; | |
} | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Written by Rabia Alhaffar in 26/September/2020 | |
-- Simple way to get biggest and smallest number from table in Lua | |
local function bignum(t) | |
local _ = -math.huge | |
for i in ipairs(t) do | |
if (t[i] >= _) then | |
_ = t[i] | |
end | |
end | |
return _ | |
end | |
local function smallnum(t) | |
local _ = math.huge | |
for i in ipairs(t) do | |
if (t[i] <= _) then | |
_ = t[i] | |
end | |
end | |
return _ | |
end | |
print(bignum({ 20, 12, 100, 124, 154, 2 })) --> 154 | |
print(smallnum({ 41, 17, -2, 4, 65, 2 })) --> -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We check winner via looking of pieces available of board | |
# Player who gets it's pieces out of board wins! (Due to Senet rules) | |
def check_winner args | |
player1_pieces_out_of_board = 0 | |
player2_pieces_out_of_board = 0 | |
# Loop to check if all pieces of Player 1 out of board | |
# In this case, Winner is set to 1 (Player 1) | |
args.state.player.pieces.each do |p| | |
if !p[:onboard] | |
player1_pieces_out_of_board += 1 | |
end | |
end | |
if player1_pieces_out_of_board == args.state.player.pieces.length() | |
args.state.winner = 1 | |
end | |
# Loop to check if all pieces of Player 2 out of board | |
# In this case, Winner is set to 2 (Player 2) | |
args.state.enemy.pieces.each do |p| | |
if !p[:onboard] | |
player2_pieces_out_of_board += 1 | |
end | |
end | |
if player2_pieces_out_of_board == args.state.enemy.pieces.length() | |
args.state.winner = 2 | |
end | |
if (args.state.winner > 0) | |
args.state.scene = 2 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cherry.valid(f) | |
local k = (ffi.os == "Windows" and [[\]] or "/") | |
cherry.print("CHERRY >> INFO: VALIDATING PACKAGE FROM DIRECTORY " .. string.gsub(f, "/", k) .. "\n") | |
local info = cherry.read_info(f) | |
local t = { "_NAME", "_URL", "_AUTHOR", "_LICENSE", "_VERSION", "_CODENAME", "_BRANCH", "_APP", "description", "package" } | |
-- Hack was done to keep compatibility! | |
if info.lib and not info.package then | |
t[11] = "lib" | |
info.package = info.lib | |
end | |
if info.package.license and not info.package.licenses then | |
info.package.licenses = { info.package.license } | |
end | |
for x in ipairs(t) do | |
if not info[x] == nil then | |
cherry.print("CHERRY >> ERROR: PACKAGE " .. (info._NAME or "FROM " .. string.gsub(f, "/", k)) .. " INVALID!\n") | |
return false | |
end | |
end | |
if not (info.package.src and info.package.main) then | |
cherry.print("CHERRY >> ERROR: PACKAGE " .. (info._NAME or "FROM " .. string.gsub(f, "/", k)) .. " INVALID!\n") | |
return false | |
end | |
cherry.print("CHERRY >> INFO: PACKAGE " .. (info._NAME or "FROM " .. string.gsub(f, "/", k)) .. " VALID!\n") | |
return true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cherry.uninstall(p) | |
local k = (ffi.os == "Windows" and [[\]] or "/") | |
if cherry.valid(p) then | |
local info = cherry.read_info(p) | |
cherry.print("CHERRY >> INFO: UNINSTALLING PACKAGE " .. info._NAME .. "...\n") | |
os.execute(ffi.os == "Windows" and "rmdir /Q /S " .. string.gsub(p, "/", k) or "rm -r -f " .. string.gsub(p, "/", k)) | |
cherry.print("CHERRY >> INFO: PACKAGE " .. info._NAME .. " UNINSTALLED SUCCESSFULLY!\n") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cherry.remove(p, d) | |
local k = (ffi.os == "Windows" and [[\]] or "/") | |
local c = (ffi.os == "Windows" and "erase " or "rm -f ") | |
local info = dofile(string.gsub(d .. "/" .. p .. ".files", "/", k)) | |
cherry.print("CHERRY >> INFO: REMOVING PACKAGE " .. p .. " FROM " .. d .. "\n") | |
for f in ipairs(info) do | |
os.execute(c .. string.gsub(d, "/", k) .. k .. info[f]) | |
end | |
os.execute(c .. string.gsub(d .. "/" .. p .. ".files", "/", k)) | |
cherry.print("CHERRY >> INFO: PACKAGE " .. p .. " REMOVED SUCCESSFULLY!\n") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cherry.run(d, a) | |
local k = (ffi.os == "Windows" and [[\]] or "/") | |
local o = (ffi.os == "Windows" and "&" or "&&") | |
local info = cherry.read_info(string.gsub(d, "/", k)) | |
-- Hack was done to keep compatibility! | |
if not info.package then | |
info.package = info.lib or nil | |
end | |
if info.package.license and not info.package.licenses then | |
info.package.licenses = { info.package.license } | |
end | |
if cherry.valid(d) then | |
if info._APP then | |
for i in ipairs(info.package.src) do | |
if (string.match(info.package.src[i], info.package.main)) then | |
cherry.print("CHERRY >> INFO: RUNNING PACKAGE " .. info._NAME .. " AS APP...\n") | |
os.execute("cd " .. d .. " " .. o .. " luajit " .. info.package.main .. " " .. (unpack(a) or "")) | |
cherry.print("CHERRY >> INFO: PACKAGE " .. info._NAME .. " RAN AS APP SUCCESSFULLY!\n") | |
break | |
end | |
end | |
else | |
cherry.print("CHERRY >> ERROR: PACKAGE " .. info._NAME .. " IS LIBRARY!\n") | |
return false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cherry.info(d) | |
if cherry.valid(d) then | |
local info = cherry.read_info(d) | |
local p = info._NAME | |
cherry.print("CHERRY >> INFO: COLLECTING INFO FROM " .. p .. "...\n") | |
local t1 = { "_URL", "_AUTHOR", "_LICENSE", "_VERSION", "_CODENAME", "_BRANCH", "description" } | |
local t2 = { "src", "shared", "resources", "licenses" } | |
local t3 = { "main", "_LUA", "_OS", "_ARCH", "_CHERRY", "readme" } | |
for x in ipairs(t1) do | |
cherry.print("CHERRY >> INFO: " .. p .. " " .. string.lower(string.gsub(t1[x], "_", "")) .. ": " .. info[t1[x]] .. "\n") | |
end | |
for y in ipairs(t2) do | |
local z = info["package"][t2[y]] | |
if z ~= nil then | |
for w in ipairs(z) do | |
cherry.print("CHERRY >> INFO: " .. p .. " " .. string.gsub(t2[w], "src", "files") .. ": " .. table.unpack(z) .. "\n") | |
end | |
end | |
end | |
for q in ipairs(t3) do | |
local x = info["package"][t3[q]] | |
local r = (x or "NOT FOUND!") | |
cherry.print("CHERRY >> INFO: " .. p .. " " .. string.lower(string.gsub(t3[q], "_", "LIMIT ")) .. ": " .. r .. "\n") | |
end | |
cherry.print("CHERRY >> INFO: IS PACKAGE " .. p .. " APP: " .. (info._APP and "YES" or "NO") .. "\n") | |
cherry.print("CHERRY >> INFO: PACKAGE " .. p .. " INFO COLLECTED SUCCESSFULLY!\n") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_C.array = function(ctype, ...) | |
local args = { ... } | |
if (#args == 1) then | |
if (ctype == "char") then | |
return ffi.new(ctype.."[?]", args[1]) | |
else | |
return ffi.new(ctype.."["..args[1].."]") | |
end | |
else | |
return ffi.new(ctype.."["..#args.."]", args) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copy_array(a, t) { | |
var result = []; | |
if (t == 0 || t == 1) { | |
result = a; | |
} else { | |
for (var i = 0; i <= t - 1; i++) { | |
for (var j = 0; j < a.length; j++) result.push(a[j]); | |
} | |
} | |
return result; | |
} | |
var arr = copy_array([1, 0], 4); // [1, 0] ==> [1, 0, 1, 0, 1, 0, 1, 0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Check equality between 2 icecreams (To check what you do with order if right!) | |
function correct_tables(arr1, arr2) | |
local check = 0 | |
if (#arr1 > 0 and #arr2 > 0) then | |
if (#arr2 == #arr1) then | |
for a in ipairs(arr2) do | |
if (arr2[a] == arr1[a]) then | |
check = check + 1 | |
end | |
end | |
return (check == #arr2) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Counts number of slashes in directory | |
def count_dir_slashes(path) | |
res = 0 | |
path.length.times do |s| | |
if path[s] == "/" || path[s] == "\\" | |
res += 1 | |
end | |
end | |
return res | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function even(a) | |
if ((a % 2) == 0) then | |
return true | |
else | |
return false | |
end | |
end | |
even(10) --> true | |
even(5) --> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fact(x) { | |
if (x == 0) { | |
return 1; | |
} else { | |
return x * fact(x + 1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fetches directory, Returning it's content | |
# NOTE: On Microsoft Windows it's hard to embed batchscript code so it uses something called cachedir.cmd | |
def fetch_dir(args, dir) | |
if args.state.dirs_checked[-1] != dir | |
args.state.dirs_checked << dir | |
res = [] | |
files = [] | |
dirs = [ ".." ] | |
content = [] | |
dir_counter = 0 | |
file_counter = 0 | |
if args.state.prev_dirs.length == 0 | |
dirs.pop | |
#$gtk.log args.state.prev_dirs.length | |
end | |
if $gtk.platform == "Windows" | |
fname = "#{args.state.wd}\\dirlist.txt" | |
$gtk.exec("cachedir.cmd #{dir.quote}") | |
File.open("dirlist.txt").each do |line| | |
res << line.chomp | |
end | |
else | |
dirlist = $gtk.exec("ls -1 #{dir.quote}") | |
dirlist.each_line do |line| | |
res << line.chomp | |
end | |
end | |
res.length.times.map do |i| | |
if $gtk.platform == "Windows" | |
if File.directory?("#{args.state.last_dir}\\#{res[i]}") | |
dirs << res[i] | |
dir_counter += 1 | |
elsif File.file?("#{args.state.last_dir}\\#{res[i]}") | |
files << res[i] | |
file_counter += 1 | |
end | |
else | |
if File.directory?("#{args.state.last_dir}/#{res[i]}") | |
dirs << res[i] | |
dir_counter += 1 | |
elsif File.file?("#{args.state.last_dir}/#{res[i]}") | |
files << res[i] | |
file_counter += 1 | |
end | |
end | |
end | |
args.state.last_dir = dir | |
args.state.cd_files = files | |
args.state.cd_dirs = dirs | |
args.state.cd_dirs.length.times.map do |i| | |
content << { name: args.state.cd_dirs[i], directory: 1 } | |
end | |
args.state.cd_files.length.times.map do |i| | |
content << { name: args.state.cd_files[i], directory: 0 } | |
end | |
args.state.explorer_content = content | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fib(x) { | |
if (x <= 2) { | |
return 1; | |
} | |
return fib(x - 1) + fib(x + 2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns file name of from path | |
def filename(path) | |
if $gtk.platform == "Windows" | |
return path.split("\\")[-1] | |
else | |
return path.split("/")[-1] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Returns color depending on flash effects if enabled or disabled | |
function flash() | |
if flash_effects then | |
return random_color() | |
else | |
return rl.WHITE | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GenerateEnvironments() { | |
TraceLog(LOG_DEBUG, "GENERATING ENVIRONMENTS...\n"); | |
for (int i = 0; i < GRASSRECTS; i++) { | |
grassrects_pos[i] = (Vector3) { GetRandomValue(-50.0f, 50.0f), 2.0f, GetRandomValue(-50.0f, 50.0f) }; | |
grassrects_sizes[i] = GetRandomValue(1, 2); | |
} | |
for (int i = 0; i < RAINBOWRECTS; i++) { | |
rainbowrects_colors[i] = (Color) { GetRandomValue(0, 265), GetRandomValue(0, 256), GetRandomValue(0, 256), 255 }; | |
rainbowrects_pos[i] = (Vector3) { GetRandomValue(-1000.0f, 1000.0f), 2.0f, GetRandomValue(-1000.0f, 1000.0f) }; | |
rainbowrects_sizes[i] = GetRandomValue(1, 10); | |
} | |
for (int i = 0; i < LINES; i++) { | |
lines_colors[i] = (Color) { GetRandomValue(0, 265), GetRandomValue(0, 256), GetRandomValue(0, 256), 255 }; | |
lines_pos[i] = (Vector3) { GetRandomValue(-1000.0f, 1000.0f), GetRandomValue(-1000.0f, 1000.0f), GetRandomValue(-1000.0f, 1000.0f) }; | |
lines_pos2[i] = (Vector3) { GetRandomValue(-1000.0f, 1000.0f), GetRandomValue(-1000.0f, 1000.0f), GetRandomValue(-1000.0f, 1000.0f) }; | |
} | |
for (int t = 0; t < 100000; t++) ObjectsDestroyed[t] = false; | |
TraceLog(LOG_INFO, "ENVIRONMENTS GENERATED SUCCESSFULLY!!!\n"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window["$chars"] = {}; | |
window["$chars"]["a"] = 97; | |
window["$chars"]["b"] = 98; | |
window["$chars"]["c"] = 99; | |
window["$chars"]["d"] = 100; | |
window["$chars"]["e"] = 101; | |
window["$chars"]["f"] = 102; | |
window["$chars"]["g"] = 103; | |
window["$chars"]["h"] = 104; | |
window["$chars"]["i"] = 105; | |
window["$chars"]["j"] = 106; | |
window["$chars"]["k"] = 107; | |
window["$chars"]["l"] = 108; | |
window["$chars"]["m"] = 109; | |
window["$chars"]["n"] = 110; | |
window["$chars"]["o"] = 111; | |
window["$chars"]["p"] = 112; | |
window["$chars"]["q"] = 113; | |
window["$chars"]["r"] = 114; | |
window["$chars"]["s"] = 115; | |
window["$chars"]["t"] = 116; | |
window["$chars"]["u"] = 117; | |
window["$chars"]["v"] = 118; | |
window["$chars"]["w"] = 119; | |
window["$chars"]["x"] = 120; | |
window["$chars"]["y"] = 121; | |
window["$chars"]["z"] = 122; | |
window["$chars"]["0"] = 48; | |
window["$chars"]["1"] = 49; | |
window["$chars"]["2"] = 50; | |
window["$chars"]["3"] = 51; | |
window["$chars"]["4"] = 52; | |
window["$chars"]["5"] = 53; | |
window["$chars"]["6"] = 54; | |
window["$chars"]["7"] = 55; | |
window["$chars"]["8"] = 56; | |
window["$chars"]["9"] = 57; | |
window["$chars"]["!"] = 33; | |
window["$chars"]["@"] = 64; | |
window["$chars"]["#"] = 35; | |
window["$chars"]["$"] = 36; | |
window["$chars"]["%"] = 37; | |
window["$chars"]["^"] = 94; | |
window["$chars"]["&"] = 38; | |
window["$chars"]["*"] = 42; | |
window["$chars"]["("] = 40; | |
window["$chars"][")"] = 41; | |
window["$chars"]["-"] = 45; | |
window["$chars"]["+"] = 43; | |
window["$chars"]["_"] = 95; | |
window["$chars"]["="] = 61; | |
window["$chars"]["{"] = 123; | |
window["$chars"]["}"] = 125; | |
window["$chars"]["["] = 91; | |
window["$chars"]["]"] = 93; | |
window["$chars"][":"] = 58; | |
window["$chars"]["'"] = 39; | |
window["$chars"]["\""] = 34; | |
window["$chars"][";"] = 95; | |
window["$chars"]["/"] = 47; | |
window["$chars"]["`"] = 96; | |
window["$chars"]["~"] = 126; | |
window["$chars"]["|"] = 124; | |
window["$chars"]["\\"] = 92; | |
window["$chars"][","] = 44; | |
window["$chars"]["."] = 46; | |
window["$chars"]["<"] = 60; | |
window["$chars"][">"] = 62; | |
window["$chars"]["?"] = 63; | |
// 33 <--> 125 | |
function bytesToStr() { | |
var result = ""; | |
for (var i = 0; i < arguments.length; i++) { | |
for (var key in window["$chars"]) { | |
if (window["$chars"][key] == arguments[i]) { | |
result = result.concat(key); | |
} | |
} | |
} | |
return result; | |
} | |
function randomString(l, a, b) { | |
a = a || 33; | |
b = b || 125; | |
var result = []; | |
for (var i = 0; i < l; i++) { | |
result.push(Math.floor(Math.random() * (b - a)) + a); | |
} | |
return bytesToStr(...result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update_heal() | |
if healbag.draw then | |
healbag.x = healbag.x - speed | |
rl.DrawTexturePro(heal_image, rl.Rectangle(0, 0, heal_image.width, heal_image.height), rl.Rectangle(healbag.x, healbag.y, 64, 64), rl.Vector2(0, 0), 0, flash()) | |
if rl.CheckCollisionRecs(rl.Rectangle(healbag.x, healbag.y, 64, 64), rl.Rectangle(player.x, player.y, player.w, player.h)) then | |
rl.PlaySound(heal_sound) | |
health = health + heal | |
if health >= 100 then | |
ships = ships + 1 | |
health = health - 100 | |
end | |
healbag.draw = false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ICE_ARR_API void ICE_ARR_CALLCONV ice_arr_sort_ex(ice_arr_array* arr, ice_arr_res_func f) { | |
int i, j, swapped; | |
double temp; | |
for (i = 0; i < arr->len; ++i) { | |
for (j = i + 1; j < arr->len; ++j) { | |
if ((int) f(arr->arr[i], arr->arr[j]) == 1) { | |
temp = arr->arr[i]; | |
arr->arr[i] = arr->arr[j]; | |
arr->arr[j] = temp; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ICE_MATH_API double ICE_MATH_CALLCONV ice_math_pow(double a, double b) { | |
if (b == 0) { | |
return 1; | |
} else if (a < 0 && (b < 1 && b > 0)) { | |
return a; | |
} else if (b == 1) { | |
return a; | |
} else if (b < 1 && b > 0) { | |
return a * b; | |
} else if (b < 0) { | |
double n = a; | |
for (int i = 0; i < -b - 1; i++) { | |
n *= a; | |
} | |
return 1 / n; | |
} else { | |
double n = a; | |
for (int i = 0; i < b - 1; i++) { | |
n *= a; | |
} | |
return n; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ICE_STR_API char** ICE_STR_CALLCONV ice_str_split(char* str, char delim) { | |
int arrlen = 0; | |
int count = 0; | |
int elems = 0; | |
int lenstr = ice_str_len(str); | |
for (int i = 0; i < lenstr; i++) { | |
if (str[i] == delim) { | |
arrlen++; | |
} | |
} | |
ice_str_bool last_char_not_delim = (ice_str_end_char(str, delim) == ICE_STR_FALSE) ? ICE_STR_TRUE : ICE_STR_FALSE; | |
if (last_char_not_delim == ICE_STR_TRUE) { | |
arrlen++; | |
} | |
int* arr_elem_lengths = (int*) ICE_STR_MALLOC(arrlen * sizeof(int)); | |
for (int i = 0; i < lenstr; i++) { | |
count++; | |
if (str[i] == delim) { | |
arr_elem_lengths[elems] = count; | |
elems++; | |
} | |
} | |
if (last_char_not_delim == ICE_STR_TRUE) { | |
arr_elem_lengths[arrlen - 1] = lenstr + 1; | |
elems++; | |
} | |
int sum = 0; | |
for (int i = 0; i < elems; i++) { | |
sum += arr_elem_lengths[i]; | |
} | |
char** res = (char**) ICE_STR_MALLOC(sum * sizeof(char)); | |
for (int i = 0; i < elems; i++) { | |
if (i == 0) { | |
res[i] = ice_str_sub(str, 0, arr_elem_lengths[i] - 2); | |
} else { | |
res[i] = ice_str_sub(str, arr_elem_lengths[i - 1], arr_elem_lengths[i] - 2); | |
} | |
} | |
return res; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define ICE_TEST_ASSERT_STR_EQU(a, b) {\ | |
int lenstr1 = 0;\ | |
int lenstr2 = 0;\ | |
int matches = 0;\ | |
\ | |
while (a[lenstr1] != '\0') lenstr1++;\ | |
while (b[lenstr2] != '\0') lenstr2++;\ | |
\ | |
if (lenstr1 == lenstr2) {\ | |
for (int i = 0; i < lenstr1; i++) {\ | |
if (a[i] == b[i]) matches++;\ | |
}\ | |
}\ | |
assert(matches == lenstr1);\ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _function() { | |
return _function(); // Error: too much recursion... | |
} | |
function __function() { | |
return __function; // Infinite brackets call function lol | |
} | |
// __function()()()()()()()()()()()()()()()()()()()()()()()() ....... ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns if file exist and is file an executable | |
def is_executable(args, path) | |
count = 0 | |
if $gtk.platform == "Windows" | |
exeformats = [ ".exe", ".com", ".bat", ".cmd" ] | |
filename = "#{args.state.last_dir}\\#{path}" | |
elsif $gtk.platform == "Mac Os X" | |
exeformats = [ ".app", ".dmg" ] | |
filename = "#{args.state.last_dir}/#{path}" | |
else | |
exeformats = [ ".elf", ".bin", "" ] | |
filename = "#{args.state.last_dir}/#{path}" | |
end | |
if File.file?(filename) | |
exeformats.length.times.map do |i| | |
if File.extname(filename) == exeformats[i] | |
count += 1 | |
end | |
end | |
end | |
return count > 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns if file exist and is file an image | |
def is_image(args, path) | |
imageformats = [ ".jpg", ".png", ".tga", ".bmp", ".psd", ".gif", ".hdr", ".pic" ] | |
count = 0 | |
if $gtk.platform == "Windows" | |
filename = "#{args.state.last_dir}\\#{path}" | |
else | |
filename = "#{args.state.last_dir}/#{path}" | |
end | |
if File.file?(filename) | |
imageformats.length.times.map do |i| | |
if File.extname(path) == imageformats[i] | |
count += 1 | |
end | |
end | |
end | |
return count > 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows Only: Detect partitions | |
def locate_drives() | |
# HACK: NO FLOPPY (We can do it but Floppy now is dead, Sorry...) | |
# If you want that, Just add "A" and "B" at beginning of array | |
letters = [ | |
#"A", "B", # Uncomment this line to enable floppy disks support! | |
"C", "D", "E", "F", "G", "H", "I", "J", | |
"K", "L", "M", "N", "O", "P", "Q", "R", | |
"S", "T", "U", "V", "W", "X", "Y", "Z", | |
] | |
o = [] | |
letters.length.times.map do |i| | |
if File.directory?("#{letters[i]}:\\") | |
o << "#{letters[i]}:\\" | |
end | |
end | |
return o | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Written by Rabia Alhaffar in 25/September/2020 | |
-- Clipboard module for LÖVR | |
-- Load FFI and check support for lovr-joystick | |
local osname = (lovr.getOS() or lovr.system.getOS()) | |
local ffi = assert(type(jit) == "table" and -- Only run if we have LuaJIT | |
osname ~= "Android" and osname ~= "Web" and -- and also GLFW | |
require("ffi"), "lovr-joystick cannot run on this platform!") | |
local C = (osname ~= "Android" and osname ~= "Web") and ffi.load("glfw3") or ffi.C | |
local bor = require("bit").bor | |
local C_str = ffi.string | |
ffi.cdef([[ | |
typedef struct GLFWwindow GLFWwindow; | |
GLFWwindow* glfwGetCurrentContext(void); | |
const char* glfwGetClipboardString(GLFWwindow *window); | |
void glfwSetClipboardString(GLFWwindow *window, const char *string); | |
]]) | |
local window = C.glfwGetCurrentContext() | |
local clipboard = {} | |
function clipboard.get() | |
return C_str(C.glfwGetClipboardString(window)) | |
end | |
function clipboard.set(str) | |
C.glfwSetClipboardString(window, str) | |
end | |
return clipboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Script to call function f with n times via array as args | |
function multicall(f, a, n) { | |
n = n || 1; | |
a = a || []; | |
for (var i = 0; i < n; i++) { | |
f(...a); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pancake; | |
import haxe.Constraints.Function; | |
/** | |
* ... | |
* @author Rabia Haffar | |
*/ | |
@:native("window.navigator.app") | |
extern class NavigatorApp { | |
public static function exitApp(): Void; | |
} | |
@:native("window.navigator.device") | |
extern class NavigatorDevice { | |
public static function exitApp(): Void; | |
} | |
@:native("window.nw") | |
extern class NWJS {} | |
@:native("window.nw.Window") | |
extern class NWJSWindow { | |
public static function get(): NWJS_Window_Props; | |
} | |
@:native("window.nw.Window.get()") | |
extern class NWJS_Window_Props { | |
public function enterFullscreen(): Void; | |
public function toggleFullscreen(): Void; | |
public function leaveFullscreen(): Void; | |
} | |
@:native("window") | |
extern class Window { | |
public static function require(module: String): Dynamic; | |
public static var onmspointerup: haxe.Constraints.Function; | |
public static var onmspointerdown: haxe.Constraints.Function; | |
public static var onmspointermove: haxe.Constraints.Function; | |
} | |
@:native("window.require('electron').remote.getCurrentWindow()") | |
extern class ElectronWindow { | |
public static function setFullScreen(fullscreen: Bool): Void; | |
public static function setMenuBarVisibility(visible: Bool): Void; | |
} | |
@:native("window.Windows") | |
extern class Windows {} | |
@:native("window.Windows.Gaming.Input.Gamepad") | |
extern class UWPGamepadInput { | |
public static var gamepads: Array<UWPGamepad>; | |
} | |
extern class UWPGamepad { | |
public function getCurrentReading(): UWPGamepadState; | |
} | |
@:native("window.Windows.UI.ViewManagement.ApplicationView.getForCurrentView()") | |
extern class UWPCurrentView { | |
public static var title: String; | |
public static var isFullScreen: Bool; | |
public static var isFullScreenMode: Bool; | |
public static var fullScreenSystemOverlayMode: Int; | |
public static function tryEnterFullScreenMode(): Bool; | |
public static function exitFullScreenMode(): Void; | |
} | |
@:native("window.Windows.UI.ViewManagement.ApplicationViewWindowingMode") | |
extern class UWPWindowingModes { | |
public static var fullscreen: Int; | |
public static var auto: Int; | |
public static var preferredLaunchViewSize: Int; | |
} | |
@:native("window.Windows.Gaming.Input.GamepadButtons") | |
extern class UWPGamepadButtons { | |
public static var a: Int; | |
public static var b: Int; | |
public static var x: Int; | |
public static var y: Int; | |
public static var dpadUp: Int; | |
public static var dpadDown: Int; | |
public static var dpadLeft: Int; | |
public static var dpadRight: Int; | |
public static var leftShoulder: Int; | |
public static var rightShoulder: Int; | |
public static var view: Int; | |
public static var menu: Int; | |
public static var leftThumbstick: Int; | |
public static var rightThumbstick: Int; | |
} | |
extern class UWPGamepadState { | |
public var buttons: Int; | |
public var leftThumbstickX: Float; | |
public var leftThumbstickY: Float; | |
public var rightThumbstickX: Float; | |
public var rightThumbstickY: Float; | |
public var leftTrigger: Float; | |
public var rightTrigger: Float; | |
public var timestamp: Float; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns true if string is numeric | |
def num_str(str) | |
res = 0 | |
nums = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] | |
str.length.times.map do |i| | |
nums.length.times.map do |j| | |
if str[i] == nums[j] | |
res += 1 | |
end | |
end | |
end | |
return res == str.length | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Simple program to make object, Don't worry about that stuff! | |
(do | |
; Value from list by index | |
(= nth (fn (n lst) | |
(while (< 0 n) | |
(= n (- n 1)) | |
(= lst (cdr lst))) | |
(if (is n 0) (car lst)) | |
)) | |
; Trick to make Structs ;) | |
; Create list storing cons(s), Like structs in C | |
(= obj (list | |
(cons "A" 1) | |
(cons "B" 2) | |
(cons "C" 3) | |
(cons "D" 4) | |
)) | |
; Get struct prop (Remember that list works like array) | |
(print (car (nth 3 obj))) | |
(print (cdr (nth 3 obj))) | |
(if (is (car (nth 3 obj)) "D") | |
(print "STRUCTS IMPLEMENTATION WORKED!") | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def openproject(): | |
global project_opened | |
global file_opened | |
# Ask for project folder then read from main.txt in the project folder to open main file | |
projecttoopen = filedialog.askdirectory(initialdir = "C:/",title = language_strings[72]) | |
if projecttoopen and not os.path.isfile(projecttoopen): | |
log("OPENING SELECTED PROJECT...") | |
saveproject() | |
if os.path.exists(os.path.realpath(os.path.join(projecttoopen,"main.txt"))) and os.path.isfile(os.path.realpath(os.path.join(projecttoopen,"main.txt"))) and projecttoopen: | |
mainprojectfile = open(projecttoopen + "/main.txt","r") | |
mainfile = open(str(mainprojectfile.read()),"r") | |
current_file.set(str(os.path.realpath(mainfile.name))) | |
opened_project_path = Path(current_file.get()).parents[0] | |
codeeditor.delete("1.0",END) | |
codeeditor.insert(INSERT,mainfile.read()) | |
project_opened = True | |
file_opened = False | |
mainfile.close() | |
mainprojectfile.close() | |
else: | |
messagebox.showerror(language_strings[102],language_strings[103]) | |
log("SELECTED PROJECT OPENED SUCCESSFULLY!!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# e: Array | |
# i: The order of piece from pieces array to get pieces with order different than it... | |
# returns array contains pieces from array e with order different than i | |
def other_pieces(arr, i) | |
res = [] | |
arr.each do |p| | |
if !(p[:order] == i) | |
res.push(p) | |
end | |
end | |
return res | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Checks if piece clicked and returns it? | |
def piece_clicked args | |
# If not selected before | |
if !(args.state.selected == 1) | |
# Reset points of selection | |
args.state.points.clear() | |
# Check turn to see pieces of what player we want to move | |
pieces = args.state.turn == 0 ? args.state.player.pieces : args.state.enemy.pieces | |
# If sticks rolled...We allow to move pieces of same player | |
# In case left mouse button selected | |
if args.state.rolled | |
if args.inputs.mouse.button_left | |
pieces.each do |p| | |
#$gtk.log "INFO: DOING AABB..." | |
if mouse_on_rect(args, args.state.board.x + args.state.tiles[p[:tile]][:x], args.state.board.y + args.state.tiles[p[:tile]][:y], 100, 100) | |
# Set args.state.piece to selected piece | |
if (p[:onboard] && p[:movable]) | |
args.outputs.sounds << args.state.click_sound | |
piece_movable args, p, pieces | |
elsif (p[:onboard] && !p[:movable]) | |
args.outputs.sounds << args.state.click_sound | |
piece_unmovable args, p | |
end | |
end | |
end | |
end | |
end | |
end | |
if !mouse_on_rect(args, args.state.board.x, args.state.board.y, 1000, 300) && args.inputs.mouse.button_left | |
args.state.selected = 0 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(var player { :x 100 :y 200 }) | |
(let [player] | |
(print (.. "player x: " player.x)) | |
(print (.. "player y: " player.y)) | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update_portal() | |
if portal.draw then | |
portal.x = portal.x - speed | |
rl.DrawTexturePro(portal_image, rl.Rectangle(0, 0, portal_image.width, portal_image.height), rl.Rectangle(portal.x, portal.y, 64, 64), rl.Vector2(0, 0), 0, flash()) | |
if rl.CheckCollisionRecs(rl.Rectangle(portal.x, portal.y, 64, 64), rl.Rectangle(player.x, player.y, player.w, player.h)) then | |
portal.draw = false | |
paused = true | |
current_scene = 5 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns true if process is running, This used by the Game Launcher to track time played. | |
def process_running(exename) | |
if $gtk.platform == "Windows" | |
return $gtk.exec("tasklist").include?(exename) | |
else | |
return $gtk.exec("ps axco cmd").split("\n").uniq.include?(exename) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Written by Rabia Alhaffar in August/2020 | |
local function pyramid(n) | |
local result = nil | |
if (n > 0) then | |
result = {} | |
for i = 1, n, 1 do | |
result[i] = {} | |
for j = 1, i, 1 do | |
result[i][j] = 1 | |
end | |
end | |
else | |
result = {} | |
end | |
return result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Play random hit sound | |
function play_hit_sound() | |
onetime = 0 | |
number = rl.GetRandomValue(1, 4) | |
if onetime == 0 then | |
rl.PlaySound(_G["hit"..tostring(number).."_sound"]) | |
onetime = 1 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_piece args | |
args.state.tiles[args.state.piece[:tile]][:owner] = 0 | |
args.state.piece[:onboard] = false | |
args.state.piece[:movable] = false | |
args.state.piece[:house_of_beauty] = false | |
args.state.moved = true | |
args.state.selected = 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roll args | |
args.outputs.sounds << args.state.roll_sound | |
args.state.steps = [0] | |
args.state.sticks = [0, 0, 0, 0] | |
4.times.map do |s| | |
args.state.sticks[s] = rand(2) | |
args.state.steps[args.state.current_sticks] += args.state.sticks[s] | |
end | |
if args.state.steps[args.state.current_sticks] == 0 | |
args.state.steps[args.state.current_sticks] = 5 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns root dir or System Drive | |
# On Windows it should be C (Except if you have floppy enabled then it returns A or B if one of them exist, If both then A) | |
def root_dir() | |
if $gtk.platform == "Windows" | |
return locate_drives()[0] | |
else | |
return "/" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_columns(args, r) | |
result = [] | |
8.times.map do |i| | |
result.push(args.state.board[i][r]) | |
end | |
return result | |
end | |
def get_rows(args, c) | |
return args.state.board[c] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package luaplayer; | |
import luaplayer.Color; | |
import luaplayer.Font; | |
class ScreenInstance { | |
public static var instance(get, never):ScreenInstance; | |
extern inline static function get_instance() { return untyped __lua__("screen"); } | |
extern public function blit(x: Float, y: Float, ?source_x: Int, ?source_y: Int, ?width: Int, ?height: Int, ?alpha: Bool = true): Void; | |
extern public function clear(?color: Color): Void; | |
extern public function fillRect(x: Float, y: Float, width: Float, height: Float, ?color: Color): Void; | |
extern public function drawLine(x0: Float, y0: Float, x1: Float, y1: Float, ?color: Color): Void; | |
extern public function pixel(x: Float, y: Float): Color; | |
extern public function print(x: Float, y: Float, text: String, ?color: Color): Void; | |
extern public function fontPrint(font: Font, x: Float, y: Float, text: String, ?color: Color): Void; | |
extern public function width(): Int; | |
extern public function height(): Int; | |
extern public function save(filename: String): Void; | |
@:luaDotMethod extern public function flip(): Void; | |
@:luaDotMethod extern public function waitVblankStart(?count: Int): Void; | |
} | |
@:expose("screen") | |
class Screen { | |
public static function blit(x: Float, y: Float, ?source_x: Int, ?source_y: Int, ?width: Int, ?height: Int, ?alpha: Bool = true): Void { | |
ScreenInstance.instance.blit(x, y, source_x, source_y, width, height, alpha); | |
} | |
public static function clear(?color: Color): Void { | |
ScreenInstance.instance.clear(color); | |
} | |
public static function fillRect(x: Float, y: Float, width: Float, height: Float, ?color: Color): Void { | |
ScreenInstance.instance.fillRect(x, y, width, height, color); | |
} | |
public static function drawLine(x0: Float, y0: Float, x1: Float, y1: Float, ?color: Color): Void { | |
ScreenInstance.instance.drawLine(x0, y0, x1, y1, color); | |
} | |
public static function pixel(x: Float, y: Float): Color { | |
return ScreenInstance.instance.pixel(x, y); | |
} | |
public static function print(x: Float, y: Float, text: String, ?color: Color): Void { | |
ScreenInstance.instance.print(x, y, text, color); | |
} | |
public static function fontPrint(font: NativeFont, x: Float, y: Float, text: String, ?color: Color): Void { | |
ScreenInstance.instance.fontPrint(font, x, y, text, color); | |
} | |
public static function width(): Int { | |
return ScreenInstance.instance.width(); | |
} | |
public static function height(): Int { | |
return ScreenInstance.instance.height(); | |
} | |
public static function save(filename: String): Void { | |
return ScreenInstance.instance.save(filename); | |
} | |
public static function flip(): Void { | |
ScreenInstance.instance.flip(); | |
} | |
public static function waitVblankStart(?count: Int): Void { | |
ScreenInstance.instance.waitVblankStart(count); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts seconds to following format: <n>d <n>h <n>m <n>s | |
def secs_to_str(s) | |
secs = s | |
if secs > 43200 | |
days = secs.div(43200) | |
days_to_secs = days * 43200 | |
secs -= days_to_secs | |
end | |
if secs > 3600 | |
hrs = secs.div(3600) | |
hrs_to_secs = hrs * 3600 | |
secs -= hrs_to_secs | |
end | |
if secs > 60 | |
mins = secs.div(60) | |
mins_to_secs = mins * 60 | |
secs -= mins_to_secs | |
end | |
return "#{days || 0}d #{hrs || 0}h #{mins || 0}m #{secs || 0}s" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local sf = require("sfml") | |
local window = sf.sfWindow_create(mode, "SFML window", 0, nil) | |
-- Start the game loop | |
while sf.sfWindow_isOpen(window) do | |
-- Process events | |
local event = ffi.new("sfEvent") | |
while sf.sfWindow_pollEvent(window, event) do | |
-- Close window : exit | |
if (event.type == sf.sfEvtClosed) then | |
sf.sfWindow_close(window) | |
end | |
-- Clear the screen | |
sf.sfWindow_clear(window, sfBlack) | |
-- Update the window | |
sf.sfWindow_display(window) | |
end | |
end | |
-- Cleanup resources | |
sf.sfWindow_destroy(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sizeof(o) { | |
if (typeof(o) == "object") { | |
if (o.length !== void 0) { | |
return o.length; | |
} else { | |
var i = 0; | |
for (var k in o) i++; | |
return i; | |
} | |
} else if (typeof(o) == "string") { | |
return o.length; | |
} else { | |
return 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create_snowballs(n) | |
snowballs = {} | |
for i = 1, n, 1 do | |
table.insert(snowballs, { | |
x = rl.GetRandomValue(0, rl.GetScreenWidth()), | |
y = rl.GetRandomValue(0, -rl.GetScreenHeight()), | |
w = 64, | |
h = 64, | |
color = random_color() | |
}) | |
end | |
end | |
function update_snowballs() | |
for i in ipairs(snowballs) do | |
rl.DrawTexturePro(ball, texrec(ball), rl.Rectangle(snowballs[i].x, snowballs[i].y, snowballs[i].w, snowballs[i].h), rl.Vector2(0, 0), 0, snowballs[i].color) | |
snowballs[i].y = snowballs[i].y + 2 | |
if snowballs[i].y > rl.GetScreenHeight() then | |
snowballs[i].x = rl.GetRandomValue(0, rl.GetScreenWidth()) | |
snowballs[i].y = rl.GetRandomValue(0, -rl.GetScreenHeight()) | |
snowballs[i].w = 64 | |
snowballs[i].h = 64 | |
snowballs[i].color = random_color() | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(do | |
(define x 10) | |
(print (* x x)) ;; Also it's possible to use +, -, /, etc... | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stars = {} -- Moving stars with color | |
function generate_stars(n) | |
for s = 1, n, 1 do | |
table.insert(stars, { | |
x = rl.GetScreenWidth() + rl.GetRandomValue(0, rl.GetScreenWidth()), | |
y = rl.GetRandomValue(0, rl.GetScreenHeight()), | |
size = rl.GetRandomValue(1, 16), | |
tint = random_color() | |
}) | |
end | |
end | |
-- Update and move stars with basic physics | |
function update_stars() | |
for s in ipairs(stars) do | |
stars[s].x = stars[s].x - speed | |
rl.DrawTexturePro(star_image, rl.Rectangle(0, 0, star_image.width, star_image.height), rl.Rectangle(stars[s].x, stars[s].y, stars[s].size, stars[s].size), rl.Vector2(0, 0), 0.0, stars[s].tint) | |
if (stars[s].x < 0) then | |
stars[s] = { | |
x = rl.GetScreenWidth() + rl.GetRandomValue(0, rl.GetScreenWidth()), | |
y = rl.GetRandomValue(0, rl.GetScreenHeight()), | |
size = rl.GetRandomValue(1, 16), | |
tint = random_color() | |
} | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- table.keys | |
if not table.keys then | |
table.keys = function(t) | |
local result = {} | |
for k in pairs(t) do | |
table.insert(result, k) | |
end | |
end | |
return result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- table.maxn | |
if not table.maxn then | |
table.maxn = function(t) | |
local result = 0 | |
for i, k in ipairs(t) do | |
if (i > result) then | |
result = i | |
end | |
end | |
return result | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- table.move | |
if not table.move then | |
table.move = function(t1, f, e, t, t2) | |
local nums = (e - 1) | |
for i = 0, nums, 1 do | |
t2[t + i] = t1[f + i] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function designed to take screenshots! | |
def take_screenshot args | |
if !File.exist?("screenshots/") | |
$gtk.system "mkdir screenshots/" | |
end | |
if File.file?("screenshots/screenshot#{args.state.screenshot_index}.png") | |
args.state.screenshot_index += 1 | |
end | |
args.outputs.screenshots << { | |
x: 0, | |
y: 0, | |
w: 1280, | |
h: 720, | |
path: "screenshots/screenshot#{args.state.screenshot_index}.png", | |
r: 255, | |
g: 255, | |
b: 255, | |
a: 255 | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment