Example #1
0
	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2
Example #2
0
	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2
Example #3
0
def initCtrlLayer():
	global ctrlLayer, selectedCharacter, startBtn, moneyTxt, livesTxt, money, lives

	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2

	# draw the background of the ctrlLayer
	ctrlLayer.graphics.beginFill("#333333")
	ctrlLayer.graphics.lineStyle(3, "#222222")
	ctrlLayer.graphics.drawRect(0, 0, 150, stage.height)
	ctrlLayer.graphics.endFill()

	# list of our characters
	ourList = ["guanyu", "xiahoudun", "soldier1"]

	# show selectors of our characters
	selectorsLayer = Sprite()
	ctrlLayer.addChild(selectorsLayer)

	for i, v in enumerate(ourList):
		selector = Sprite()
		selector.name = v
		selectorsLayer.addChild(selector)

		# the appearance of the character
		bmp = Bitmap(BitmapData(dataList[v + "_mov"], 0, 0, 48, 48))
		selector.addChild(bmp)

		# show the cost of the character
		costTxt = TextField()
		costTxt.text = charactersData[v]["cost"]
		costTxt.textColor = "white"
		costTxt.x = (bmp.width - costTxt.width) / 2
		costTxt.y = bmp.height + 10
		selector.addChild(costTxt)

		selector.y = i * 88

		selector.addEventListener(MouseEvent.MOUSE_DOWN, selectCharacter)

	selectorsLayer.x = (ctrlLayer.width - selectorsLayer.width) / 2
	selectorsLayer.y = 40

	# add lives and money text
	livesTxt = TextField()
	livesTxt.text = "Lives: %s" % lives
	livesTxt.x = (ctrlLayer.width - livesTxt.width) / 2
	livesTxt.y = stage.height - 150
	livesTxt.textColor = "white"
	ctrlLayer.addChild(livesTxt)

	moneyTxt = TextField()
	moneyTxt.text = "Money: %s" % money
	moneyTxt.x = (ctrlLayer.width - moneyTxt.width) / 2
	moneyTxt.y = livesTxt.y + 30
	moneyTxt.textColor = "white"
	ctrlLayer.addChild(moneyTxt)

	# add a button to start game
	def clickStartBtn(e):
		global start, enemyNum

		start = True

		enemyNum = 0

		e.currentTarget.state = ButtonState.DISABLED

	normal = Sprite()
	normal.graphics.beginFill("#666666")
	normal.graphics.lineStyle(3, "#222222")
	normal.graphics.drawRect(0, 0, 100, 60)
	normal.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (normal.width - txt.width) / 2
	txt.y = (normal.height - txt.height) / 2
	normal.addChild(txt)

	over = Sprite()
	over.graphics.beginFill("#888888")
	over.graphics.lineStyle(3, "#222222")
	over.graphics.drawRect(0, 0, 100, 60)
	over.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (over.width - txt.width) / 2
	txt.y = (over.height - txt.height) / 2
	over.addChild(txt)

	disabled = Sprite()
	disabled.graphics.beginFill("#666666")
	disabled.graphics.lineStyle(3, "#222222")
	disabled.graphics.drawRect(0, 0, 100, 60)
	disabled.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "#333333"
	txt.size = 20
	txt.x = (disabled.width - txt.width) / 2
	txt.y = (disabled.height - txt.height) / 2
	disabled.addChild(txt)

	startBtn = Button(normal, over, None, disabled)
	startBtn.x = (ctrlLayer.width - startBtn.width) / 2
	startBtn.y = stage.height - 80
	ctrlLayer.addChild(startBtn)

	startBtn.addEventListener(MouseEvent.MOUSE_UP, clickStartBtn)

	ctrlLayer.x = stage.width - ctrlLayer.width
Example #4
0
def initCtrlLayer():
	global ctrlLayer, selectedCharacter, startBtn, moneyTxt, livesTxt, money, lives

	def selectCharacter(e):
		global selectedCharacter

		name = e.currentTarget.name

		# create selectedCharacter
		selectedCharacter = Sprite()
		selectedCharacter.name = name
		selectedCharacter.mouseShelter = False
		stageLayer.addChild(selectedCharacter)

		bmp = Bitmap(BitmapData(dataList[name + "_mov"], 0, 0, 48, 48))
		selectedCharacter.addChild(bmp)

		# make selectedCharacter move to mouse's position
		selectedCharacter.x = e.offsetX - selectedCharacter.width / 2
		selectedCharacter.y = e.offsetY - selectedCharacter.height / 2

	# draw the background of the ctrlLayer
	ctrlLayer.graphics.beginFill("#333333")
	ctrlLayer.graphics.lineStyle(3, "#222222")
	ctrlLayer.graphics.drawRect(0, 0, 150, stage.height)
	ctrlLayer.graphics.endFill()

	# list of our characters
	ourList = ["guanyu", "xiahoudun", "soldier1"]

	# show selectors of our characters
	selectorsLayer = Sprite()
	ctrlLayer.addChild(selectorsLayer)

	for i, v in enumerate(ourList):
		selector = Sprite()
		selector.name = v
		selectorsLayer.addChild(selector)

		# the appearance of the character
		bmp = Bitmap(BitmapData(dataList[v + "_mov"], 0, 0, 48, 48))
		selector.addChild(bmp)

		# show the cost of the character
		costTxt = TextField()
		costTxt.text = charactersData[v]["cost"]
		costTxt.textColor = "white"
		costTxt.x = (bmp.width - costTxt.width) / 2
		costTxt.y = bmp.height + 10
		selector.addChild(costTxt)

		selector.y = i * 88

		selector.addEventListener(MouseEvent.MOUSE_DOWN, selectCharacter)

	selectorsLayer.x = (ctrlLayer.width - selectorsLayer.width) / 2
	selectorsLayer.y = 40

	# add lives and money text
	livesTxt = TextField()
	livesTxt.text = "Lives: %s" % lives
	livesTxt.x = (ctrlLayer.width - livesTxt.width) / 2
	livesTxt.y = stage.height - 150
	livesTxt.textColor = "white"
	ctrlLayer.addChild(livesTxt)

	moneyTxt = TextField()
	moneyTxt.text = "Money: %s" % money
	moneyTxt.x = (ctrlLayer.width - moneyTxt.width) / 2
	moneyTxt.y = livesTxt.y + 30
	moneyTxt.textColor = "white"
	ctrlLayer.addChild(moneyTxt)

	# add a button to start game
	def clickStartBtn(e):
		global start, enemyNum

		start = True

		enemyNum = 0

		e.currentTarget.state = ButtonState.DISABLED

	normal = Sprite()
	normal.graphics.beginFill("#666666")
	normal.graphics.lineStyle(3, "#222222")
	normal.graphics.drawRect(0, 0, 100, 60)
	normal.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (normal.width - txt.width) / 2
	txt.y = (normal.height - txt.height) / 2
	normal.addChild(txt)

	over = Sprite()
	over.graphics.beginFill("#888888")
	over.graphics.lineStyle(3, "#222222")
	over.graphics.drawRect(0, 0, 100, 60)
	over.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "white"
	txt.size = 20
	txt.x = (over.width - txt.width) / 2
	txt.y = (over.height - txt.height) / 2
	over.addChild(txt)

	disabled = Sprite()
	disabled.graphics.beginFill("#666666")
	disabled.graphics.lineStyle(3, "#222222")
	disabled.graphics.drawRect(0, 0, 100, 60)
	disabled.graphics.endFill()

	txt = TextField()
	txt.text = "START"
	txt.textColor = "#333333"
	txt.size = 20
	txt.x = (disabled.width - txt.width) / 2
	txt.y = (disabled.height - txt.height) / 2
	disabled.addChild(txt)

	startBtn = Button(normal, over, None, disabled)
	startBtn.x = (ctrlLayer.width - startBtn.width) / 2
	startBtn.y = stage.height - 80
	ctrlLayer.addChild(startBtn)

	startBtn.addEventListener(MouseEvent.MOUSE_UP, clickStartBtn)

	ctrlLayer.x = stage.width - ctrlLayer.width