|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 13390163901 于 2020-10-12 09:27 编辑
直接上链接
[RenPy] 纯文本查看 复制代码 class DPClass(renpy.Displayable):
def __init__(self, child, pos, longs, **kwargs):
# 向renpy.Displayable构造器传入额外的特性(property)。
super(DPClass, self).__init__(**kwargs)
# 子组件。
self.child = renpy.displayable(child)
# 子组件的位置。
self.xpos = pos[0]
self.ypos = pos[1]
self.longs = 35 * len(longs)
#子组件速度
self.redrawtime = 0.01 # 多久刷新一次位置,越大刷新得越快
self.redrawdistance = 2 # 每次刷新的默认偏移量,越大默认误差越大
# 子组件是否运动
self.move = False
self.Move()
def render(self, width, height, st, at):
render = renpy.Render(self.longs, 35)
render.place(self.child, self.xpos, self.ypos)
return render
def event(self, ev, x, y, st):
return self.child.event(ev, x, y, st)
def Move(self):
if self.move == False:
self.move = True
Timer(0, self.Linear).start()
def Linear(self):
while(self.move and self.xpos > -self.longs):
self.xpos -= self.redrawdistance
renpy.redraw(self, 0)
time.sleep(self.redrawtime)
self.move = False
弹幕代码
[RenPy] 纯文本查看 复制代码 class DanmuClass(object):
def __init__(self):
self.dp = [[], [], []]
self.danmuBase = {}
#{"0": ["你好", "z真不错"], "1": ["草", "哈哈哈哈", "z真不错"], "2": ["2333"], "3": ["2333", "真不戳", "早上好"], "4": ["2333", "6666"], "5": ["2333"]}
def History(self):
try:
x = renpy.filter_text_tags(_history_list[len(_history_list)-1].what, allow=gui.history_allow_tags)
except:
x = ""
return x
def AddDanmu(self, j):
danmuPos = [1280, 1280, 1280]
test = 0
try:
for i in self.dp:
if i:
pos = i[len(i) - 1]
danmuPos[test] = max(pos.xpos + pos.longs, 1280)
test += 1
if danmuPos[0] - 100 > danmuPos[1]:
if danmuPos[1] - 100 > danmuPos[2]:
channel = 2
else:
channel = 1
else:
if danmuPos[0] - 100 > danmuPos[2]:
channel = 2
else:
channel = 0
self.dp[channel].append(DPClass(Text(j, style="danmu_text"), [danmuPos[channel], 35 * channel], j))
except:
pass
def Show(self):
# return
texts = self.History()
if texts:
try:
for j in self.danmuBase[texts]:
self.AddDanmu(j)
except:
pass
def Clear(self):
for j in self.dp:
for i in j:
i.move = False
del i
弹幕滚动
[RenPy] 纯文本查看 复制代码 class NodeClass(object):
def __init__(self):
self.header={'User-Agent': 'Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 75.0.3770.100Safari / 537.36', 'Content-Type': "utf8"}
self.hostname = socket.gethostname()
self.ipaddr = socket.gethostbyname(self.hostname)
self.comurl = "url"
def get(self):
self.url = self.comurl + "danmu/get"#
self.result = requests.get(url=self.url, headers=self.header, timeout=5).text
danmu.danmuBase = json.loads(self.result)
# danmu.danmuBase = self.result
def push(self, values):
self.url = self.comurl + "danmu/push"#
obj = danmu.History()
self.result = requests.get(url=self.url, headers=self.header, params={"place": obj.encode('utf8'), "texts": values.encode('utf8')}, timeout=5).text
danmu.AddDanmu(json.loads(self.result))
与后端交互
[RenPy] 纯文本查看 复制代码 var mysql = require('mysql');
exports.save = (pushin, callback) => {
var connection = mysql.createConnection({
host: 'localhost',
user : 'root',
password : '******',
database : 'new'
});
connection.connect();
console.log();
connection.query('INSERT INTO danmu(place, texts) VALUES("' + pushin.place + '", "' + pushin.texts + '")', function (error, results, fields) {
if (error) throw error;
callback(null, pushin.texts)
});
connection.end();
}
exports.find = (callback) => {
var connection = mysql.createConnection({
host: 'localhost',
user : 'root',
password : '******',
database : 'new'
});
connection.connect();
connection.query('SELECT * FROM `danmu`', function (error, results, fields) {
if (error) throw error;
var danmus = {}
for (var i of results) {
if (danmus[i.place]){
danmus[i.place].push(i.texts)
} else {
danmus[i.place] = [i.texts]
}
}
console.log(danmus);
callback(null, danmus);
});
connection.end();
}
与数据库交互
|
评分
-
查看全部评分
|