占坑
自用代码
function key_class()constructor{
static key_fun=function()constructor{
list=[]
//static function(){}
static set=function(k){
array_push(list,k)
return self
}
static get=function(m){
var f=keyboard_check
if m=1 f=keyboard_check_pressed
if m=2 f=keyboard_check_released
var size=array_length(list)
for(var i=0;i<size;i++){
if f(list[i]) return 1
}
return 0
}
}
static add=function(k){
variable_struct_set(self,k,new key_fun())
return variable_struct_get(self,k)
}
}
globalvar key;
key=new key_class()
key.add("left").set(ord("A"))
key.add("right").set(ord("D"))
key.add("up").set(ord("W"))
key.add("down").set(ord("S"))
key.add("atk").set(ord("S")).set(ord("J"))
key.add("jump").set(ord("W")).set(ord("K"))
show_debug_message(key)
function string_load(f)//从文件读取字符串
{
var _buffer = buffer_load(f);
var _string = buffer_read(_buffer, buffer_string);
buffer_delete(_buffer);
return _string;
}
function json_load(f){//从文件读取json
try {
return json_parse(string_load(f))
} catch (e) {
show_debug_message(e)
return -1
}
}
function trace(){//输出所有内容
var l=argument_count
show_debug_message("")
show_debug_message("================")
show_debug_message("trace :"+string(current_time)+": ms")
show_debug_message(" -------------- ")
for(var i=0;i<l;i++){
show_debug_message(argument[i])
}
show_debug_message("================")
show_debug_message("")
}
function format(){//格式化文本 format("{}a{}b{}c",$1,$2,$3)
var text = argument[0];
var escape_open_brace_suffix = "|"; // Suffix open brace escape character (e.g. "{|hello}")
// Checks:
/*
// Return original text if no open curly braces are found
if !string_count("{", text) {return (text);}
// More thorough, can be less performant, return original text if all curly braces are escaped
if (string_count("{", text) - string_count("{" + string(escape_open_brace_suffix), text) == 0) {return (text);}
*/
// Simple Formatting: format("Hello {}", "World");
if string_pos("{}", text)
{
for (var i = 0; i < argument_count - 1; ++i)
{
text = string_replace(text, "{}", argument[i + 1]);
}
}
// Positional Index Formatting: format("{1} {0}", "World", "Hello");
else if string_pos("{0}", text)
{
for (var i = 0; i < argument_count - 1; ++i)
{
text = string_replace(text, "{" + string(i) + "}", argument[i + 1]);
}
}
// Variable Formatting: var x = "World"; format("Hello {x}");
else if string_pos("{", text)
{
var variable;
var count = string_count("{", text);
for (var i = 0; i < count; ++i)
{
// Get variable name between curly braces
variable = string_copy(text, string_pos("{", text) + 1, string_pos("}", text) - string_pos("{", text) - 1);
// Ignore escaped curly brace "{|"
if (string_char_at(variable, 1) == escape_open_brace_suffix)
{
continue;
}
// If variable starts with "$", get global variable
if (string_char_at(variable, 1) == "$")
{
text = string_replace(text, "{" + string(variable) + "}", string(variable_global_get(string_copy(variable, 2, string_length(variable)))));
}
// Else get local variable from the calling instance
else
{
var t = self
text = string_replace(text, "{" + string(variable) + "}", t[$variable]);
}
}
}
text = string_replace_all(text, "{" + string(escape_open_brace_suffix), "{");
return (text);
}
function t2sin(ms){//简单来讲就是在毫秒内反复0到1
ms ??=1000
var _ct = current_time mod ms;
var _ct=dsin(360/ms*_ct)
return (_ct+1)*0.5
}
4 个月 后
同上