var rect=Rect2(Vector2(-14,-14),Vector2(28,28))
var debug=true
var vec=Vector2.ZERO
var keymap={"up":0,"down":0,"left":0,"right":0,'fire':0}
var level=0 #坦克的级别0最小 1中等 2是大 3是最大
var dir=0 # 0上 1下 2左 3右
var shootTime=0
var shootDelay=60
var bullets=[]
var bulletMax=1#发射最大子弹数
var bullet=Game.bullet
var isInit=false
var state=Game.tank_state.IDLE
var initStartTime=0
var initTime=1200 #ms
var isInvincible=false
var invincibleStartTime=0
var invincibleTime=8000
var isStop=false#是否停止
var playId=2 #1=1p 2=2p
var life=1 #生命默认1
var speed = 70 #移动速度
var bulletPower=Game.bulletPower.normal
var hasShip=false#是否有船
#开火
func fire():
if OS.get_system_time_msecs()-shootTime<shootDelay:
return
else:
shootTime=OS.get_system_time_msecs()
#print("dir",dir)
var del=[]
for i in bullets: #清理无效对象
#print(is_instance_valid(i))
if not is_instance_valid(i):
del.append(i)
for i in del:
bullets.remove(bullets.find(i))
if bullets.size()<bulletMax:
playShot()
var temp=bullet.instance()
temp.setType("player")
temp.position=position
temp.setPower(bulletPower)
temp.setDir(dir)
temp.setPlayerId(playId)
bullets.append(temp)
Game.mainScene.add_child(temp)
export var dir=2 # 0上 1下 2左 3右
var speed=160
var type=Game.bulletType.players
var playerID #玩家id
var power=Game.bulletPower.normal #1是基本火力 2是最强火力
#var winSize=Vector2(480,416)#屏幕大小
var size=Vector2(6,8)#图片大小
var vec= Vector2.ZERO
var isValid=false
var rect=Rect2(Vector2(-3,-4),Vector2(6,8))
for i in _tank.get_children():#检查坦克与砖块的碰撞
var rect=i.getRect()
for y in _brick.get_children():
if y.get_class()=="brick":
var type=y.getType() #装快的类型
if type==Game.brickType.bush or type==Game.brickType.ice:#草丛
continue
var rect1=y.getRect()
if rect.intersects(rect1,false): #碰撞 判断是否被包围住
if rect1.encloses(rect):#完全叠一起
continue
var dx=(y.getPos().x-i.position.x)/(y.getXSize()/2)
var dy=(y.getPos().y-i.position.y)/(y.getYSize()/2)
var absDX = abs(dx)
var absDY = abs(dy)
if abs(absDX - absDY) < .1:
if dx<0:
i.position.x=y.getPos().x+y.getXSize()/2+i.getSize()/2
else:
i.position.x=y.getPos().x-y.getXSize()/2-i.getSize()/2
if dy<0:
i.position.y=y.getPos().y+y.getYSize()/2+i.getSize()/2
else:
i.position.y=y.getPos().y-y.getYSize()/2-i.getSize()/2
elif absDX > absDY:
if dx<0:
i.position.x=y.getPos().x+y.getXSize()/2+i.getSize()/2
else:
i.position.x=y.getPos().x-y.getXSize()/2-i.getSize()/2
else:
if dy<0:
i.position.y=y.getPos().y+y.getYSize()/2+i.getSize()/2
else:
i.position.y=y.getPos().y-y.getYSize()/2-i.getSize()/2
var tanks=_tank.get_children()
for i in tanks:#坦克与坦克的碰撞
var isStop=false
for y in tanks:
if i!=y:
if i.isInit && y.isInit:
var rect=i.getRect()
var rect1=y.getRect()
var iTankDir=i.dir
var yTankDir=y.dir
var xVal =i.position.x-y.position.x
var yVal =i.position.y-y.position.y
var absXVal=abs(xVal)
var absYVal=abs(yVal)
if rect.intersects(rect1,false):
if iTankDir in [0,1]:#上下
if absYVal<i.getSize() and absYVal>i.getSize()/2:
if yVal<0 and iTankDir==1:
isStop=true
elif yVal>0and iTankDir==0:
isStop=true
#if yVal<0:
#i.position.y=y.getPos().y-y.getSize()/2-i.getSize()/2
#else:
#i.position.y=y.getPos().y+y.getSize()/2+i.getSize()/2
else:
isStop=false
pass
elif iTankDir in [2,3]:#左右
if absXVal<i.getSize() and absXVal>i.getSize()/2:
if xVal<0 and iTankDir==3:
isStop=true
elif xVal>0 and iTankDir==2:
isStop=true
#if xVal<0:
#i.position.x=y.getPos().x-y.getSize()/2-i.getSize()/2
#else:
#i.position.x=y.getPos().x+y.getSize()/2+i.getSize()/2
else:
isStop=false
pass
pass
pass
i.setStop(isStop)
func _input(event):
if event is InputEventKey:
if event.is_pressed():
if (event as InputEventKey).scancode==KEY_DOWN:
if index<2:
index+=1
setMode(index)
elif (event as InputEventKey).scancode==KEY_UP:
if index>0:
index-=1
setMode(index)
elif (event as InputEventKey).scancode==KEY_ENTER:
if _ani.get_current_animation()=="start" and \
_ani.is_playing():
_ani.play("end")
return
if mode in [1,2]:
Game.mode=mode
Game.changeSceneAni(Game._mainScene)
else:
var scene = preload("res://scenes/map.tscn")
var temp=scene.instance()
temp.mode=1
queue_free()
set_process_input(false)
get_tree().get_root().add_child(temp)
set_process_input(true)
#Game.changeSceneAni(Game._welcomeScene)
func _input(event):
if _fileDiaglog.visible or _loadDiaglog.visible or lock or mode!=1:
return
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
isPress=true
if currentItem!=-1:
if !mapRect.has_point(get_global_mouse_position()):
return
if! checkItem(get_global_mouse_position()):
addItem(get_global_mouse_position())
elif currentItem==-1:
clearItem(get_global_mouse_position())
elif !event.pressed:
isPress=false
elif event is InputEventMouseMotion:#移动
if isPress:
if currentItem!=-1:
if !mapRect.has_point(get_global_mouse_position()):
return
if! checkItem(get_global_mouse_position()):
addItem(get_global_mouse_position())
elif currentItem==-1:
clearItem(get_global_mouse_position())
pass