Love2D学习1
来源:互联网 发布:教育平台软件提供 编辑:程序博客网 时间:2024/06/10 16:46
--[[love.graphics.print("hello world",400,300)
love.graphics.print("hello",400,300)
love.graphics.setBackgroundColor(255,255,255)
love.graphics.setColor(0,0,0,255)
pacwidth = math.pi / 6 -- size of his mouth
function love.draw( )
love.graphics.setColor( 255, 255, 0 ) -- pacman needs to be yellow
love.graphics.arc( "fill", 400, 300, 20, math.pi - pacwidth, pacwidth )
end
function love.load()
hamster = love.graphics.newImage("cake.jpg")
width = hamster:getWidth()
height = hamster:getHeight()
love.graphics.setColor(0,0,0,255)
love.graphics.setBackgroundColor(255,255,255)
love.graphics.draw(hamster, 100, 100, math.rad(90), 1, 1, width/2, height/2)
end
function love.load()
love.graphics.setColor(0,0,0)
love.graphics.setBackgroundColor(255,255,0)
end
function love.draw()
love.graphics.print("This text is not black because of the line below", 100, 100)
love.graphics.setColor(255,0,0)
love.graphics.print("This text is red", 100, 200)
end
function love.load()
--image = love.graphics.newImage("cake.jpg")
--local f = love.graphics.newFont(50)
--love.graphics.setFont(f)
--love.graphics.setColor(0,0,0,255)
--love.graphics.setBackgroundColor(255,255,255)
end
function love.draw()
love.graphics.draw(image,imgx,imgy)
love.graphics.print("Click and drag the cake around or use the arrow keys", 100, 200)
end
function love.update(dt)
if love.keyboard.isDown("up") then
num = num+10*dt
end
end
static load
sound = love.audio.newSource("test.mp3")
music = love.audio.newSource("anther.mp3")
sound:setVolume(0.9)
love.audio.play(sound)
--draw order
function love.load()
scene = love.graphics.newImage("back.jpg")
icon = love.graphics.newImage("91.jpg")
player = love.graphics.newImage("cake.jpg")
end
character = {400,400}
objects = {}
objects[1] = {550,370}
objects[2] = {220,390}
objects[3] = {600,410}
objects[4] = {300,450}
objects[5] = {400,530}
function orderY(a,b)
return a[2] < b[2]
end
end
table.sort(objects, orderY)
love.graphics.draw(player, objects[i][1] - player:getWidth()/2, objects[i][2] - player:getHeight())
function love.draw()
love.graphics.draw(scene, love.graphics:getWidth() / 2 - scene:getWidth()/2,
love.graphics:getHeight() / 2 - scene:getHeight() / 2) -- draw at the center of the screen
local drawn = false -- true when the character has been drawn
for i,v in ipairs(objects) do
if not drawn and objects[i][2] > character[2] then
love.graphics.draw(icon, character[1] - icon:getWidth()/2, character[2] - icon:getHeight())
drawn = true
end
love.graphics.draw(player, objects[i][1] - player:getWidth()/2, objects[i][2] - player:getHeight())
end
if not drawn then -- if the person is below all objects it won't be drawn within the for loop
love.graphics.draw(icon, character[1] - icon:getWidth()/2, character[2] - icon:getHeight())
end
any foreground objects go here
end
]]
--[[
--**********************************************************************
--**********************************************************************
--tile-based scrolling
tile= {}
for i = 0,3 do
tile[i] = love.graphics.newImage("tile"..i..".png")
end
love.graphics.setNewFont(12)
-- map variables
map_w = 20
map_h = 20
map_x = 0
map_y = 0
map_offset_x = 30
map_offset_y = 30
map_display_w = 14
map_display_h = 10
tile_w = 48
tile_h = 48
map={
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 2, 2, 2, 0, 3, 0, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 2, 0, 2, 0, 3, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 0, 2, 2, 2, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
]]
--function draw_map()
-- for y=1, map_display_h do
-- for x=1, map_display_w do
-- love.graphics.draw(
-- tile[map[y+map_y][x+map_x]],
-- (x*tile_w)+map_offset_x,
--(y*tile_h)+map_offset_y)
--end
--end
--end
--[[
function love.draw()
draw_map()
end
love.graphics.setNewFont(20)
function love.keypressed(key, unicode)
if key == 'up' then
love.graphics.print("This text is not black because of the line below",100,200)
end
if key == 'down' then
love.graphics.print("down",50,50)
end
if key == 'left' then
love.graphics.print("left",50,50)
end
if key == 'right' then
love.graphics.print("right",50,50)
end
end
]]
love.graphics.print("hello",400,300)
love.graphics.setBackgroundColor(255,255,255)
love.graphics.setColor(0,0,0,255)
pacwidth = math.pi / 6 -- size of his mouth
function love.draw( )
love.graphics.setColor( 255, 255, 0 ) -- pacman needs to be yellow
love.graphics.arc( "fill", 400, 300, 20, math.pi - pacwidth, pacwidth )
end
function love.load()
hamster = love.graphics.newImage("cake.jpg")
width = hamster:getWidth()
height = hamster:getHeight()
love.graphics.setColor(0,0,0,255)
love.graphics.setBackgroundColor(255,255,255)
love.graphics.draw(hamster, 100, 100, math.rad(90), 1, 1, width/2, height/2)
end
function love.load()
love.graphics.setColor(0,0,0)
love.graphics.setBackgroundColor(255,255,0)
end
function love.draw()
love.graphics.print("This text is not black because of the line below", 100, 100)
love.graphics.setColor(255,0,0)
love.graphics.print("This text is red", 100, 200)
end
function love.load()
--image = love.graphics.newImage("cake.jpg")
--local f = love.graphics.newFont(50)
--love.graphics.setFont(f)
--love.graphics.setColor(0,0,0,255)
--love.graphics.setBackgroundColor(255,255,255)
end
function love.draw()
love.graphics.draw(image,imgx,imgy)
love.graphics.print("Click and drag the cake around or use the arrow keys", 100, 200)
end
function love.update(dt)
if love.keyboard.isDown("up") then
num = num+10*dt
end
end
static load
sound = love.audio.newSource("test.mp3")
music = love.audio.newSource("anther.mp3")
sound:setVolume(0.9)
love.audio.play(sound)
--draw order
function love.load()
scene = love.graphics.newImage("back.jpg")
icon = love.graphics.newImage("91.jpg")
player = love.graphics.newImage("cake.jpg")
end
character = {400,400}
objects = {}
objects[1] = {550,370}
objects[2] = {220,390}
objects[3] = {600,410}
objects[4] = {300,450}
objects[5] = {400,530}
function orderY(a,b)
return a[2] < b[2]
end
end
table.sort(objects, orderY)
love.graphics.draw(player, objects[i][1] - player:getWidth()/2, objects[i][2] - player:getHeight())
function love.draw()
love.graphics.draw(scene, love.graphics:getWidth() / 2 - scene:getWidth()/2,
love.graphics:getHeight() / 2 - scene:getHeight() / 2) -- draw at the center of the screen
local drawn = false -- true when the character has been drawn
for i,v in ipairs(objects) do
if not drawn and objects[i][2] > character[2] then
love.graphics.draw(icon, character[1] - icon:getWidth()/2, character[2] - icon:getHeight())
drawn = true
end
love.graphics.draw(player, objects[i][1] - player:getWidth()/2, objects[i][2] - player:getHeight())
end
if not drawn then -- if the person is below all objects it won't be drawn within the for loop
love.graphics.draw(icon, character[1] - icon:getWidth()/2, character[2] - icon:getHeight())
end
any foreground objects go here
end
]]
--[[
--**********************************************************************
--**********************************************************************
--tile-based scrolling
tile= {}
for i = 0,3 do
tile[i] = love.graphics.newImage("tile"..i..".png")
end
love.graphics.setNewFont(12)
-- map variables
map_w = 20
map_h = 20
map_x = 0
map_y = 0
map_offset_x = 30
map_offset_y = 30
map_display_w = 14
map_display_h = 10
tile_w = 48
tile_h = 48
map={
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 2, 2, 2, 0, 3, 0, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 2, 0, 2, 0, 3, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 0, 2, 2, 2, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
]]
--function draw_map()
-- for y=1, map_display_h do
-- for x=1, map_display_w do
-- love.graphics.draw(
-- tile[map[y+map_y][x+map_x]],
-- (x*tile_w)+map_offset_x,
--(y*tile_h)+map_offset_y)
--end
--end
--end
--[[
function love.draw()
draw_map()
end
love.graphics.setNewFont(20)
function love.keypressed(key, unicode)
if key == 'up' then
love.graphics.print("This text is not black because of the line below",100,200)
end
if key == 'down' then
love.graphics.print("down",50,50)
end
if key == 'left' then
love.graphics.print("left",50,50)
end
if key == 'right' then
love.graphics.print("right",50,50)
end
end
]]
- Love2D学习1
- love2d 学习笔记1
- Love2D学习 - 代码2
- love2d 学习 - 代码3
- 【love2d】Hello love2d!
- LOVE2D-03-完整的LOVE2D程序
- LOVE2D-02-Hello World
- Love2D conf配置文件
- love2d与imgui
- ubuntu下设置love2d开发环境
- 使用Love2D引擎开发贪吃蛇游戏
- LOVE2D-04-加载文字和图片
- Love2D——API检索表
- LOVE2D android竖屏的问题
- LOVE2D中实现一个简单的摇杆
- LOVE2D 简易生成Android的APK
- 开源跨平台2D游戏引擎Love2D介绍
- Love2d新手入门教程之贪吃蛇(附源码)
- Navicat Premium链接Oracle的一些需要注意
- 数组中是否有相同地数字哦
- ext regex 收集
- 在 Kindle Fire 小米2 上调试 android 应用 mac os 下
- 写存储过程时,同时给变量赋值
- Love2D学习1
- Python指南
- 黑马程序员-银行业务调度系统
- 最健康的作息时间表
- re模块 compile函数
- ns2一个问题:code omitted because of length
- C# WindowsForm之创建窗体(转)
- java.lang.SecurityException解决办法
- Head First 设计模式 笔记