from pylash.text import TextField, TextFormatWeight def main(): t1 = TextField() t1.x = t1.y = 50 t1.size = 30 t1.text = "Hello World!" addChild(t1) t2 = TextField() t2.x = 50 t2.y = 150 t2.text = "Hello Pylash~" t2.rotation = 30 t2.size = 50 t2.textColor = "#FF4500" t2.weight = TextFormatWeight.BOLD addChild(t2) t3 = TextField() t3.x = 300 t3.y = 130 t3.text = "Based on Python3, PyQt4" t3.alpha = 0.7 t3.size = 40 t3.textColor = "#0000FF" t3.italic = True addChild(t3) init(1000 / 60, "TextField", 800, 430, main)
bmp3 = Bitmap(BitmapData(dataList["3"])) bmp3.x = 530 bmp3.y = 460 addChild(bmp3) TweenLite.to(bmp1, 3, { "x" : 30, "alpha" : 0.5, "ease" : Easing.Sine.easeOut }) TweenLite.to(bmp2, 3, { "x" : 50, "rotation" : 360, "ease" : Easing.Back.easeIn }) TweenLite.to(bmp3, 3, { "x" : 250, "y" : 700, "scaleX" : -1, "scaleY" : -1, "ease" : Easing.Quad.easeIn }).to(bmp3, 2, { "delay" : 1, "scaleY" : 1, "y" : 460 }) init(1000 / 60, "TweenLite demo", 800, 750, main)
txt = TextField() txt.text = "RESTART" 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, 130, 60) over.graphics.endFill() txt = TextField() txt.text = "RESTART" txt.textColor = "white" txt.size = 20 txt.x = (over.width - txt.width) / 2 txt.y = (over.height - txt.height) / 2 over.addChild(txt) restartBtn = Button(normal, over) restartBtn.x = (stage.width - restartBtn.width) / 2 restartBtn.y = stage.height / 2 + 30 resultLayer.addChild(restartBtn) restartBtn.addEventListener(MouseEvent.MOUSE_UP, clickRestartBtn) init(1000 / 60, "Tower Defense", 726, 480, main)
animaSet.changeAnimation("move_down") ### # create buttons ### btnList = [ "move down", "move up", "move right", "move left", "atk down", "atk up", "atk right", "atk left" ] btnLayer = Sprite() btnLayer.x = 200 btnLayer.y = 50 addChild(btnLayer) for i, n in enumerate(btnList): btn = ButtonSample(text=n) btn.label = n btnLayer.addChild(btn) btn.addEventListener(MouseEvent.MOUSE_DOWN, onBtnClick) btn.x = (0 if (4 - i) > 0 else 1) * 150 btn.y = (i % 4) * 50 def onBtnClick(e): animaSet.changeAnimation(e.currentTarget.label.replace(" ", "_")) init(1000 / 60, "Animation demo", 600, 400, main)
global player, scoreTxt, stageLayer, keyboardEnabled keyboardEnabled = False stageLayer.removeAllEventListeners() scoreTxt.remove() player.animation.stop() resultTxt = TextField() resultTxt.text = "Final Score: %s" % score resultTxt.size = 40 resultTxt.weight = TextFormatWeight.BOLD resultTxt.textColor = "orangered" resultTxt.x = (stage.width - resultTxt.width) / 2 resultTxt.y = 250 stageLayer.addChild(resultTxt) hintTxt = TextField() hintTxt.text = "Double Click to Restart" hintTxt.size = 35 hintTxt.textColor = "red" hintTxt.x = (stage.width - hintTxt.width) / 2 hintTxt.y = 320 stageLayer.addChild(hintTxt) # add double click event to restart stageLayer.addEventListener(MouseEvent.DOUBLE_CLICK, startGame) init(1000 / 60, "Get Fruits", 800, 600, main)
{"name" : "2", "path" : "./2.jpg"}, {"name" : "3", "path" : "./3.jpg"}, {"name" : "4", "path" : "./4.jpg"} ] loadingBar = LoadingSample3() addChild(loadingBar) LoadManage.load(loadList, loadingBar.setProgress, demoInit) def demoInit(result): global loadingBar loadingBar.remove() imageList = [BitmapData(result["1"]), BitmapData(result["2"]), BitmapData(result["3"]), BitmapData(result["4"])] for i, bmpd in enumerate(imageList): bmp = Bitmap(bmpd) bmp.scaleX = bmp.scaleY = 0.3 bmp.x += i * 140 bmp.y += i * 150 addChild(bmp) sound = Sound() sound.loop = True sound.load(result["bgm"]) sound.play() init(1000 / 60, "LoadManage demo", 1000, 800, main)
txt.text = "RESTART" 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, 130, 60) over.graphics.endFill() txt = TextField() txt.text = "RESTART" txt.textColor = "white" txt.size = 20 txt.x = (over.width - txt.width) / 2 txt.y = (over.height - txt.height) / 2 over.addChild(txt) restartBtn = Button(normal, over) restartBtn.x = (stage.width - restartBtn.width) / 2 restartBtn.y = stage.height / 2 + 30 resultLayer.addChild(restartBtn) restartBtn.addEventListener(MouseEvent.MOUSE_UP, clickRestartBtn) init(1000 / 60, "Tower Defense", 726, 480, main)
hintTxt = TextField() hintTxt.text = "Tap to Start The Game" hintTxt.font = "Microsoft YaHei" hintTxt.size = 30 hintTxt.x = (stage.width - hintTxt.width) / 2 hintTxt.y = 300 beginningLayer.addChild(hintTxt) engineTxt = TextField() engineTxt.text = "- Powered by Pylash -" engineTxt.font = "Microsoft YaHei" engineTxt.size = 20 engineTxt.italic = True engineTxt.x = (stage.width - engineTxt.width) / 2 engineTxt.y = 400 beginningLayer.addChild(engineTxt) # add event that game will start when you click beginningLayer.addEventListener(MouseEvent.MOUSE_UP, startGame) def startGame(e): global beginningLayer, gameLayer beginningLayer.remove() gameLayer = GameLayer(dataList["bg"]) addChild(gameLayer) init(30, "Find Character", 700, 600, main)
layer.graphics.lineStyle(5, "green", 0.5) layer.graphics.drawCircle(475, 275, 75) layer.graphics.endFill() layer.graphics.beginFill() layer.graphics.lineStyle(5, "green", 0.2) layer.graphics.moveTo(0, 498) layer.graphics.lineTo(75, 400) layer.graphics.lineTo(150, 498) layer.graphics.lineTo(0, 498) layer.graphics.endFill() layer.graphics.beginFill() layer.graphics.lineStyle(5, "green", 0.8) layer.graphics.moveTo(200, 498) layer.graphics.lineTo(275, 400) layer.graphics.lineTo(350, 498) layer.graphics.lineTo(200, 498) layer.graphics.endFill() layer.graphics.beginFill("lightgreen") layer.graphics.lineStyle(5, "green", 0.5) layer.graphics.moveTo(400, 498) layer.graphics.lineTo(475, 400) layer.graphics.lineTo(550, 498) layer.graphics.lineTo(400, 498) layer.graphics.endFill() init(1000 / 60, "Graphics demo", 700, 600, main)
{"name" : "1", "path" : "./1.jpg"}, {"name" : "2", "path" : "./2.jpg"}, {"name" : "3", "path" : "./3.jpg"}, {"name" : "4", "path" : "./4.jpg"} ] loadingBar = LoadingSample3() addChild(loadingBar) LoadManage.load(loadList, loadingBar.setProgress, demoInit) def demoInit(result): global loadingBar loadingBar.remove() imageList = [BitmapData(result["1"]), BitmapData(result["2"]), BitmapData(result["3"]), BitmapData(result["4"])] for i, bmpd in enumerate(imageList): bmp = Bitmap(bmpd) bmp.scaleX = bmp.scaleY = 0.3 bmp.x += i * 140 bmp.y += i * 150 addChild(bmp) sound = Sound() sound.load(result["bgm"]) sound.play() init(1000 / 60, "LoadManage demo", 1000, 800, main)
def draw(self, color): sh = self.shape self.graphics.clear() self.graphics.beginFill() self.graphics.lineStyle(2, color) if isinstance(sh, Circle): self.graphics.drawCircle(sh.x, sh.y, sh.r) elif isinstance(sh, Polygon): vtx = sh.vertices self.graphics.moveTo(vtx[0].x, vtx[0].y) for v in vtx[1:]: self.graphics.lineTo(v.x, v.y) self.graphics.closePath() self.graphics.endFill() def onMouseDown(self, e): global isDragging, draggingObj isDragging = True draggingObj = self init(1000 / 60, "Collision detection", 800, 530, main)
# !/usr/bin/env python3 # -*- coding: utf-8 -*- from pylash.utils import init, addChild from pylash.display import Loader, Bitmap, BitmapData def main(): loader1 = Loader() loader1.load("./1.png") bmp1 = Bitmap(BitmapData(loader1.content)) bmp1.x = bmp1.y = 10 addChild(bmp1) loader2 = Loader() loader2.load("./2.png") bmp2 = Bitmap(BitmapData(loader2.content)) bmp2.x = 400 bmp2.y = 10 bmp2.rotation = 15 bmp2.alpha = 0.8 addChild(bmp2) init(1000 / 60, "Bitmap", 800, 550, main)
# 创建文本元素 if score < 0: # 如果得分为负,则失败 txt = "你输啦!再试一次吧!" # 设置"失败"的文本内容 temp_x = 360 temp_y = 150 resultPict_num = 0 # 设置游戏失败的图片 else: txt = "恭喜胜利!最终得分为: %s" % score # 如果得分为正,则成功 temp_x = -13 temp_y = 50 resultPict_num = 1 # 设置游戏胜利的图片 resultTxt = creatTxt(txt, 40, 195, 250, "black") # 结束时显示的文本 # 创建图片元素 resultPict = creatPict("result%d" % resultPict_num, temp_x, temp_y) # 结束时的装饰图片 # 创建文本元素 hintTxt = creatTxt("双击鼠标左键再次开始游戏", 35, 190, 320, "black") # 提示双击页面重新开始游戏 # 添加监听器 stageLayer.addEventListener(MouseEvent.DOUBLE_CLICK, startGame) # 用于监听"鼠标点击"事件,开始游戏 # 初始化函数 init(1000 / 60, "别偷吃零食", 800, 600, main) #初始化窗口,参数分别为时间轴事件更新的速度、窗口的名称、窗口的长和宽、主函数的调用 # 文件的入口
bmp2.y = 230 addChild(bmp2) bmp3 = Bitmap(BitmapData(dataList["3"])) bmp3.x = 530 bmp3.y = 460 addChild(bmp3) TweenLite.to(bmp1, 3, {"x": 30, "alpha": 0.5, "ease": Easing.Sine.easeOut}) TweenLite.to(bmp2, 3, { "x": 50, "rotation": 360, "ease": Easing.Back.easeIn }) TweenLite.to(bmp3, 3, { "x": 250, "y": 700, "scaleX": -1, "scaleY": -1, "ease": Easing.Quad.easeIn }).to(bmp3, 2, { "delay": 1, "scaleY": 1, "y": 460 }) init(1000 / 60, "TweenLite demo", 800, 750, main)