猫史档案馆


请教喵喵里的轨迹是如何实现的?

用户:我的地盘我作主我的地盘我作主查看:0 回复:4 评论:0 创建时间:2018-08-06T04:47:43


这个游戏写得非常经典,特别是轨迹非常流畅,但看了很久也没弄明白,哪位大神能帮忙详解下。首先是定义函数里的Y作者如何弄进去的?用PYTHON写的?另外能不能比较直观地讲解下该游戏轨迹如何实现的?代码如下:

import Codemao

posx = 0
posy = 500
self.旧角度 = 0
self.新角度 = 0
游戏阶段 = 0
test = 0
游戏时间 = 0
武器类型 = 1
武器可用时间 = 999
弹药增强可用时间 = 0
self.敌机x = 0
self.敌机y = 0
self.速度 = 10
self.血量 = 0
self.随机数 = 0
BOSS总血量 = 1000
BOSS血量 = 0
BOSS状态 = 0
游戏难度 = 1
游戏得分 = 0
BOSS退场时间 = 0
self.angle = 0
我的飞机速度 = 10
飞机血量 = 0
飞机总血量 = 0
排行1 = 'No1 test'
排行2 = 'No2 test'
排行3 = 'No3 test'
排行4 = 'No4 test'
排行5 = 'No5 test'
按钮显示时间 = 2

我方子弹发射参数 = [0, 0, 0, 0];
敌机生成参数 = [0, 0, 0, 0];
爆炸生成参数 = [0, 0, 0, 0, 0, 0];
敌方普通子弹生成参数 = [0, 0, 0, 0];
敌方导弹参数 = [0, 0, 0, 0];
BOSS坐标 = [0, 0];
爆炸杀伤参数 = [0, 0, 0, 0, 0];
玩家喵参数 = [0, 0, 0, 0, 0, 0];

def when_clone_made():
# 1.排他标志
# 2.位置x
# 3.位置y
# 4.类型
# 5.轨迹编号
Codemao.wait_until((敌机生成参数[0] == 1))
Codemao.set_xy(敌机生成参数[1], 敌机生成参数[2])
Codemao.change_shape_by_index((0 + 敌机生成参数[3]))
# 颜色特效对外形影响不大,这儿用于保存轨迹
Codemao.set_effect('color', 敌机生成参数[4])
# 存储血量
Codemao.set_effect('ascii', (敌机生成参数[5] * -1))
敌机生成参数[0] = 0
Codemao.show()
while True :
if (Codemao.is_out_of_stage('left') or Codemao.is_out_of_stage('right') or Codemao.is_out_of_stage('bottom')) :
Codemao.self_remove()
if Codemao.is_touched('Self', '我的飞机') :
Codemao.send_signal('飞机受损')
break
if (Codemao.is_touched('Self', '子弹1') or Codemao.is_touched('Self', '爆炸杀伤')) :
self.血量 = Codemao.value_of_object('Self', 'ascii') * -1 - 1
if (self.血量 <= 0) :
break
else :
# 作为生命用
Codemao.set_effect('ascii', (self.血量 * -1))
Codemao.set_effect('brightness', 1000)
Codemao.wait_for_sec(0.05)
Codemao.set_effect('brightness', 100)
self.敌机y = Codemao.value_of_object('Self', 'y')
敌机y = 敌机y - 10
if (Codemao.value_of_object('Self', 'color') == 1) :
self.敌机x = 轨迹1(null)
elif (Codemao.value_of_object('Self', 'color') == 2) :
self.敌机x = 轨迹2(null)
elif (Codemao.value_of_object('Self', 'color') == 3) :
self.敌机x = 轨迹3(null)
elif (Codemao.value_of_object('Self', 'color') == 4) :
self.敌机x = 轨迹4(null)
elif (Codemao.value_of_object('Self', 'color') == 5) :
self.敌机x = 轨迹5(null)
elif (Codemao.value_of_object('Self', 'color') == 6) :
self.敌机x = 轨迹6(null)
elif (Codemao.value_of_object('Self', 'color') == 7) :
self.敌机x = 轨迹7(null)
else :
self.敌机x = 轨迹8(null)
self.新角度 = Codemao.atan(-10 / (self.敌机x - Codemao.value_of_object('Self', 'x')))
if (self.新角度 > 0) :
self.新角度 = self.新角度 + 180
Codemao.set_rotation(self.新角度)
Codemao.set_xy(self.敌机x, self.敌机y)
# 每个传递参数的数组第一个值都用于排他标志
Codemao.wait_until((爆炸生成参数[0] == 0))
爆炸生成参数[0] = 1
爆炸生成参数[1] = Codemao.value_of_object('Self', 'x')
爆炸生成参数[2] = Codemao.value_of_object('Self', 'y')
爆炸生成参数[3] = 60
Codemao.make_clone_of('爆炸')
Codemao.send_signal('生成宝箱')
游戏得分 = 游戏得分 + ((100 * 游戏难度))
Codemao.self_remove()


def 轨迹1(y):
self.angle = ((y / (Codemao.value_of_stage('height') * 2)) * 3.1415926) * 180
return (-120 + (Codemao.value_of_stage('width') / 10) * math.sin(self.angle))

def 轨迹2(y):
self.angle = ((y / (Codemao.value_of_stage('height') * 2)) * 3.1415926) * 180
return (100 + (Codemao.value_of_stage('width') / 4) * math.sin(self.angle))

def 轨迹3(y):
self.angle = ((y / (Codemao.value_of_stage('height') * -2)) * 3.1415926) * 180
return (-100 + (Codemao.value_of_stage('width') / 4) * math.sin(self.angle))

y

def 轨迹4(y):
self.angle = ((y / (Codemao.value_of_stage('height') * -3)) * 3.1415926) * 180
return (-80 + (Codemao.value_of_stage('width') / 3) * math.sin(self.angle))

def 轨迹5(y):
self.angle = ((y / (Codemao.value_of_stage('height') * 2.8)) * 3.1415926) * 180
return (80 + (Codemao.value_of_stage('width') / 3) * math.sin(self.angle))

def 轨迹6(y):
self.angle = ((y / (Codemao.value_of_stage('height') * 2.7)) * 3.1415926) * 180
return (-100 + (Codemao.value_of_stage('width') / 1.7) * math.sin(self.angle))

def 轨迹7(y):
self.angle = ((y / (Codemao.value_of_stage('height') * -2.7)) * 3.1415926) * 180
return (100 + (Codemao.value_of_stage('width') / 1.7) * math.sin(self.angle))

def 轨迹8(y):
self.angle = ((y / (Codemao.value_of_stage('height') * -1.5)) * 3.1415926) * 180
return (120 + (Codemao.value_of_stage('width') / 9) * math.sin(self.angle))


回复

上一页1 页 / 共 1下一页
无形刺客无形刺客

emotion_编程猫_紧张emotion_编程猫_翻白眼emotion_编程猫_伤心emotion_雷电猴_疑问

点赞0


评论


想飞翔の鱼想飞翔の鱼

他应该是用了算法(而且是很高级的),和函数

点赞0


评论


幻_想幻_想

角度的运算

点赞0


评论


霖雨暮风霖雨暮风

emmmm三角函数??

点赞0


评论