love2d 1. 入门
官网
love2d.org
1、写个贪吃蛇
以下是main.lua的代码
snake = {}
speed = 50function init()snake = {}local head = {x=love.graphics.getWidth()/2,y=love.graphics.getHeight()/2,direction='up'}table.insert(snake,head)local tail = {x=love.graphics.getWidth()/2,y=love.graphics.getHeight()/4*3,direction='up'}table.insert(snake,tail)
endfunction love.load(arg)init()
endfunction line2line(line1_x1,line1_y1,line1_x2,line1_y2,line2_x1,line2_y1,line2_x2,line2_y2)return (not((math.max(line1_x1,line1_x2)<math.min(line2_x1,line2_x2)) or (math.min(line1_x1,line1_x2)>math.max(line2_x1,line2_x2)))) and (not((math.max(line1_y1,line1_y2)<math.min(line2_y1,line2_y2)) or (math.min(line1_y1,line1_y2)>math.max(line2_y1,line2_y2))))
endfunction love.update(dt)--head------------------------------------------------if snake[1].direction == 'up' thensnake[1].y = snake[1].y - dt*speedelseif snake[1].direction == 'down' thensnake[1].y = snake[1].y + dt*speedelseif snake[1].direction == 'left' thensnake[1].x = snake[1].x - dt*speedelseif snake[1].direction == 'right' thensnake[1].x = snake[1].x + dt*speedend--head--------------------------------------------------tail------------------------------------------------local tail_index = #snakeif snake[tail_index].direction == 'up' thensnake[tail_index].y = snake[tail_index].y - dt*speedif snake[tail_index].y <= snake[tail_index-1].y thentable.remove(snake)endelseif snake[tail_index].direction == 'down' thensnake[tail_index].y = snake[tail_index].y + dt*speedif snake[tail_index].y >= snake[tail_index-1].y thentable.remove(snake)endelseif snake[tail_index].direction == 'left' thensnake[tail_index].x = snake[tail_index].x - dt*speedif snake[tail_index].x <= snake[tail_index-1].x thentable.remove(snake)endelseif snake[tail_index].direction == 'right' thensnake[tail_index].x = snake[tail_index].x + dt*speedif snake[tail_index].x >= snake[tail_index-1].x thentable.remove(snake)endend--tail--------------------------------------------------out of range------------------------------------------------if (snake[1].x<0 or snake[1].x>love.graphics.getWidth()) or (snake[1].y<0 or snake[1].y>love.graphics.getHeight()) theninit()returnend--out of range--------------------------------------------------碰撞------------------------------------------------for i=3,#snake-1,1 do --第3个点+第4个点开始,与头(第一个点)+第二个点,是否相交--print('ppp')if line2line(snake[1].x,snake[1].y,snake[2].x,snake[2].y,snake[i].x,snake[i].y,snake[i+1].x,snake[i+1].y) theninit()returnendend--碰撞------------------------------------------------
endfunction love.draw(dt)for i=1,#snake-1,1 dolove.graphics.line(snake[i].x,snake[i].y,snake[i+1].x,snake[i+1].y)end
endfunction love.keypressed(key) --键盘检测回调函数,当键盘事件触发是调用if key == 'up' or key == 'down' thenif snake[1].direction ~= 'up' and snake[1].direction ~= 'down' thensnake[1].direction = keylocal head = {x=snake[1].x, y=snake[1].y, direction=snake[1].direction} --new headtable.insert(snake,1,head)endelseif key == 'left' or key == 'right' thenif snake[1].direction ~= 'left' and snake[1].direction ~= 'right' thensnake[1].direction = keylocal head = {x=snake[1].x, y=snake[1].y, direction=snake[1].direction} --new headtable.insert(snake,1,head)endend
end
2、打包成exe
把main.lua等同级目录的所有文件打包成xxx.zip,改名为xxx.love
放到love的文件中(love-11.3-win64)
新建build.bat,内容为
copy /b love.exe+xxx.love xxx.exe
把xxx.exe,以及love的文件中(love-11.3-win64)所有的dll,打包,发给朋友,就能愉快玩耍了!!
参考:
别人做的一个游戏
http://osmstudios.com/tutorials/your-first-love2d-game-in-200-lines-part-1-of-3
一些讨论,怎么把dll打包进exe中,结论是,不推荐
https://love2d.org/forums/viewtopic.php?t=84533
https://love2d.org/forums/viewtopic.php?t=84358
https://love2d.org/forums/viewtopic.php?t=83614
https://love2d.org/forums/viewtopic.php?t=78157
https://love2d.org/forums/viewtopic.php?t=83614
https://love2d.org/forums/viewtopic.php?t=82569
https://love2d.org/forums/viewtopic.php?t=78157
半山无极
https://www.cnblogs.com/xdao/archive/2012/12/07/2806500.html
love2d 1. 入门相关推荐
- love2d之路(一)环境配置
1.Lua环境 这里直接给个官网的链接:LuaForWindows_v5.1.4-46.exe 双击安装即可,建议第一次接触lua的稍微看下教程吧,入门蛮简单的一门语言. 2.Love2d引擎 还是直 ...
- 用Construct 2制作入门小游戏~
今天在软导课上了解到了Construct 2这个神器,本零基础菜鸟决定尝试做一个简单的小游戏(实际上是入门的教程啊= = 首先呢,肯定是到官网下载软件啊,点击我下载~ 等安装完毕后我便按照新手教程开始 ...
- Docker入门六部曲——Swarm
原文链接:http://www.dubby.cn/detail.html?id=8738 准备工作 安装Docker(版本最低1.13). 安装好Docker Compose,上一篇文章介绍过的. 安 ...
- Docker入门六部曲——Stack
原文链接:http://www.dubby.cn/detail.html?id=8739 准备知识 安装Docker(版本最低1.13). 阅读完Docker入门六部曲--Swarm,并且完成其中介绍 ...
- Docker入门六部曲——服务
原文链接:http://www.dubby.cn/detail.html?id=8735 准备 已经安装好Docker 1.13或者以上的版本. 安装好Docker Compose.如果你是用的是Do ...
- 【springboot】入门
简介: springBoot是spring团队为了整合spring全家桶中的系列框架做研究出来的一个轻量级框架.随着spring4.0推出而推出,springBoot可以説是J2SEE的一站式解决方案 ...
- SpringBoot (一) :入门篇 Hello World
什么是SpringBoot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不 ...
- 入门指南目录页 -PaddlePaddle 飞桨 入门指南 FAQ合集-深度学习问题
入门指南目录页 -PaddlePaddle 飞桨 入门指南 FAQ合集 GT_Zhang关注 0.1012019.08.01 18:43:34字数 1,874阅读 795 Hi,欢迎各位来自Paddl ...
- 5 分钟入门 Google 最强NLP模型:BERT
BERT (Bidirectional Encoder Representations from Transformers) 10月11日,Google AI Language 发布了论文 BERT: ...
- 命名实体识别入门教程(必看)
关于开发自己的命名实体识别先期思路: 虽然网上有很多相关代码,但实际如何入门材料较少,故整理下: CRF:先期可以用人民日报语料库去做,步骤如下: https://blog.csdn.net/hude ...
最新文章
- 六数码问题(广搜_队列)
- GridView绑定时通过RowDataBound事件获取数据源列值
- 如何选择SSL 证书服务
- 什么是URL?协议头、路径和端口是什么意思?
- Educational Codeforces Round 80 (Rated for Div. 2) 二分 + 状压
- 怎么查询表中BLOB字段的大小
- 谷歌游览器插件html5,谷歌丢弃浏览器插件,全面开发html5
- 计算机网络的功能分布计算,网络中心的分布计算(转帖)
- Java protected 关键字详解
- 面向对象分析与设计阅读笔记一
- 多线程总结之旅(9):线程同步之事件
- 稀疏向量计算优化小结
- iPhone的MobileTerminal使用经验
- 金盾视频加密器V2014视频加密原理分析
- python就业班-淘宝-目录.txt
- 图像分类halcon
- 通俗地讲解目标检测中AP指标
- ES8都有哪些新特性,你还在用ES6吗?
- python编程的缩进什么意思_编程缩进是什么意思
- 计算机工程与科学是sci,系统科学与系统工程有哪些sci期刊
热门文章
- 第十六周助教心得体会
- matlab 张德风,Matlab图形界面图像的旋转、平移和缩放
- swiper使用笔记-禁止某个div或slide左右切换
- 乐吾乐le5le-Topology为智慧水务可视化赋能(一)
- 浏览器渲染原理及web前端分析
- IntelliJ IDEA配置WEB浏览器
- sql注入搞事情(连载一)
- rabbitmq,stomp.js,rabbitmq-auth-backend-http,消息调研,消息设计
- Graph_Master(连通分量_C_Trajan缩点+最小路径覆盖)
- 云计算要掌握哪些知识点 该怎么学云计算开发