周末在油管上看到的一个教程,跟着学习了一段时间,后来网络不稳定放弃了,不过可以到github上下载源码,作为游戏入门挺不错的。

Topics
-Lua 
-LOVE2D -- 基于lua的游戏引擎
-Drawing Shapes
-Drawing Text
-DeltaTime and Velocity
-Game State
-Basic OOP(Object-Oriented Programming)
-Box Collision(Hitboxes)
-Sound Effects(with bfxr)

Installing love2D
https://love2d.org/#download
https://love2d.org/wiki/Getting_Started

Downloading demo code
https://github.com/games50/pong

What is Lua?
-Portuguese for "moon"; invented in 1993 in Brazil
-Flexible,lightweight scripting language focused around "tables"
-Intended for embedded use in larger applications
-Very popular in the video game industry
-Similar(ish) to JavaScript
-Excellent for storing data as well as code(data-driven design)

What is LOVE2D?
-Fast 2D game development framework written in C++
-Uses Lua as its scripting language
-Contains modules for graphics, keyboard input, math, audio, windowing, 
physics and much more
-Completely free and portable to all major desktops and Android/IOS
-Great for prototyping!

What is a game loop?
infinite loop: process input -> update game -> render

2D Coordinate System
System where objects have an X and Y coordinate(X,Y) and are drawn accordingly;
(0,0) would be the top-left of our system, with positive directions moving down
and to the right and negative values moving up and to the left.

Lecture's Scope
-Draw shapes to the screen (paddles  球拍 and ball)
-Control 2D position of paddles based on input
-Collision detection between paddles and ball to deflect ball back toward opponent.
-Collision detection between ball and map boundaries to keep ball within 
vetical bounds and to detect score (outside horizontal bounds)
-Sound effects when ball hits paddles/walls or when a point is scored for flavor
-Scorekeeping to determine winner

pong-0目录
main.lua
WINDOW_WIDTH = 1280
WINDOW_HEIGHT = 720

function love.load()
        love.window.setMode(WINDOW_WIDTH,WINDOW_HEIGHT, {
                fullscreen = false,
                resizable = false,
                vsync = true
        })
end
    
pong-0: Important Functions, p.1
-love.load()
--Used for initializing our game state at the very beginning of program execution.
-love.update(dt)
--called each frame by LOVE; dt will be the elapsed time in seconds since the last frame, and we can use this to scale any changes in our game for even behavior across frame rates.
-love.draw()
--Called each frame by LOVE after update for drawing things to the screen once they've changed.

LOVE2D expects these functions to be implemented in main.lua and calls them internally; if we don't define them, it will still fucntion, but our game will be fundamentally imcomplete, at least if update or draw are missing!

pong-0: Important functions, P.2
-love.graphics.printf(text,x,y, [width], [align])
--versatile 通用的 print function that can align text left, right,or center on the screen.
-love.window.setMode(width, height, params)
--Used to initialize the window's dimensions and to set parameters like vsync(vertical sync),  whether we're fullscreen or not, and whether the window is resizable after startup. Won't be using past this example in favor of the push virtual resolution library, which has its own method like this, but useful to know if encoutered in other code.

pong-1: Important Functions
-love.graphics.setDefaultFilter(min,mag)
--Sets the texture scaling filter when minimizing and magnifying 放大 textures and fonts; default is bilinear, 双线性  which causes blurriness, 模糊  and for our use cases we will typically want nearest-neighbor  filtering('nearest'), which results in perfect pixel upscaling and downscaling, simulating a retro feel.
-love.keypressed(key)
--A LOVE2D callback function that executes whenever we press a key, assuming we've implemented this in our main.lua, in the same vein as love.load(), love.update(dt), and love.draw().
-love.event.quit()
--Simple function that terminates the application.

Texture Filtering
-Point == Nearest neighbor ('nearest' in our source code)
-Bilinear/trilinear/anisotropic filtering cause blurriness in 2D, as seen below!

pong-2: Important Functions, p.1
-love.graphics.newFont(path, size)
--Loads a font file into memory at a specific path, setting it to a specific size, and storing it in an object we can use to globally change the currently active font that LOVE2d is using to render text (functioning like a state machine).
-love.graphics.setFont(font)
--Sets LOVE2D currently active font (of which there can only be one at a time) to a passed-in font object that we can create using love.graphics.newFont.
-love.graphics.clear(r,g,b,a)
--Wipes the entire screen whith a color defined by an RGBA set, each component of which being from 0-255

pong-2: Important Functions, p.2
--love.graphics.rectangle(mode, x,y,width,height)
--Draws a rectangle onto the screen using whichever our active color is (love.graphics.setColor, which we don't need to use in this particular project since most everyting is white, the default LOVE2D color).
mode can be set to 'fill' or 'line', which result in a filled or outlined rectangle, respectively, and the other four parameters are its position and size dimensions.
This is the cornerstone drawing function of the entirely of oure Pong implementation!

pong-3: Important Functions
-love.keyboard.isDown(key)
--Returs true or false depending on whether the specified key is currently held down;
differs from love.keypressed(key) in that this can be called arbitrarily and will continuously return true if the key is pressed down, where love.keypressed(key) will only fire its code once every time the key is initially pressed down. However, since we want to be able to move our paddles up and down by holding down the appropriate keys, we need a function to test for longer periods of input, hence the use of love.leyboard.isDown(key)!

love2d 乒乓球游戏相关推荐

  1. Python之深入解析如何使用Python Kivy实现一个“乒乓球”游戏

    一.前言 本文是基于 Kivy 开源跨平台的 Python 框架上创作的,Kivy 开源跨平台的 Python 框架能用于开发多点触控的用户界面程序,允许快速简单的交互设计,非常方便. 那么,如何使用 ...

  2. verilog or VHDL乒乓球游戏电路设计

    内容及要求: VHDL verilog都已设计验证! 设计乒乓球游戏电路,用按键与LED表示输入与输出. (1)初始时,16个LED最边上的点亮,按下键表示发球,亮的灯依次向对方移动:当到达另一边倒数 ...

  3. 基于Python3-Pygame的乒乓球游戏

    游戏界面截图: 按键控制: 空格: 暂停/开始 W: 上 S: 下 游戏玩法说明: 开始游戏之后,按键盘W/S按键控制球拍上下移动,接住球即可继续游戏,没接住的话游戏结束.结束后按空格可以重新开始游戏 ...

  4. 使用VHDL进行乒乓球游戏电路设计

    乒乓球游戏电路设计 VHDL eda技术 课程设计 ,使用quartusII .vivado.ISE等EDA工具均可. 乒乓游戏功能使用说明 1.打开GW48系统的电源: 2.下载PINPAN中的TA ...

  5. 使用Python+OpenCV实现打乒乓球游戏

    CodeBullet是我最喜欢的YouTuber之一,他曾经尝试创建一个人机对战的乒乓球游戏,但遗憾的是,对于他的成果没有对计算机视觉有太大影响.他是个很幽默及技术很强的人,如果你考虑阅读这篇文章的其 ...

  6. 乒乓球游戏-第12届蓝桥杯Scratch选拔赛真题精选

    [导读]:超平老师计划推出Scratch蓝桥杯真题解析100讲,这是超平老师解读Scratch蓝桥真题系列的第81讲. 蓝桥杯选拔赛每一届都要举行4~5次,和省赛.国赛相比,题目要简单不少,再加上篇幅 ...

  7. 计算机C语言乒乓球,C语言乒乓球游戏源码.pdf

    C 语言乒乓球游戏源码 程序说明 : 1. 程序运行时,显示游戏欢迎页- 2. 可统计游戏当前分数,并时刻进行统计和显示- 3. 可根据游戏当前分数,调整乒乓球的速度,以提高游戏难度- 4. 游戏结束 ...

  8. 数字逻辑电路与系统 课程设计:基于FPGA的乒乓球游戏

    设计目的 使用FPGA实验班设计一个数字逻辑系统,巩固数字逻辑电路的相关知识,锻炼熟练使用FPGA设计软件和硬件和独立完成项目设计的能力. 二.设计内容 2.1摘要 设计一个乒乓球游戏,实现游戏功能和 ...

  9. html制作的乒乓球游戏

    html制作的乒乓球游戏 源代码(含js文件)https://download.csdn.net/download/weixin_43250197/12195404 <script> va ...

  10. 用Python写一个乒乓球游戏!太简单了!

    好久没有写游戏系列教程了,今天恰好浏览到了 Kivy 这个开源跨平台的Python 框架,它能用于开发多点触控的用户界面程序,允许快速简单的交互设计,非常方便,于是有了制作本教程的想法. 本教程将教你 ...

最新文章

  1. 关于File.separator 文件路径:wind与linux下路径问题 .
  2. JavaScript语言基础5
  3. RecyclerView android:layout_width=match_parent无效
  4. android avd 使用方法,Android中Android Virtual Device(AVD)使用教程
  5. php开发中常用函数总结,PHP开发中常用函数总结
  6. GDAL对空间数据的管理
  7. [转]C++学习步骤
  8. 2021年中国及各省市结婚登记人数、离婚登记人数、结婚率、离婚率、婚姻的正负面效应及政策建议分析[图]
  9. 处理器后面的字母含义_CPU后面的数字和字母都是什么意思?全面解答。
  10. 疫情下的春招季:AI面试官已就位,请接招!
  11. 【python】爬虫入门:代理IP池的使用、文件的写入与网易云爬取时的注意事项
  12. 微博中如何选中#话题#
  13. Executors-四种创建线程的手段
  14. 正版微软Office应该如何选?Office 2019与Office 365区别在哪里?
  15. 如何在JavaScript中实现国际化(i18n)
  16. 邮币卡如何“做局”? 高回报诱惑下的陷阱
  17. python量化交易--择时策略
  18. 2.5、组织结构对项目的影响
  19. 服务器2003不支持流媒体,Windows Server 2003搭建流媒体服务器
  20. Odoo14免费开源ERP实施指南:CRM功能应用篇(1)

热门文章

  1. 苹果12开发者设置_App怎么上架到苹果商店(app store)?上架app的流程。
  2. 全网最全数据分析师面试干货-业务逻辑篇
  3. 【计算机组成原理】地址线和数据线
  4. c语言max函数和min,使用函数获取值,查找max,查找min并以C语言显示
  5. Photoshop如何把图片转为RGB颜色模式
  6. 实战演习(四)——网络流量系统分析简介
  7. CUDA+OpenCV 绘制朱利亚(Julia)集合图形
  8. 现代信号处理——时频分析与时频分布(短时Fourier变换)
  9. AngularJS orderBy 使用要点
  10. LDR2001电脑免驱USB转串口芯片方案