Love2D学习1

--[[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, 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},


}
]]


--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)