KJSKJSCE/IT/TYBTECH/SEMVI/GAP/2019-20 Experiment No.: 03 Title: Implementation of keyboard operations on sprite (Lua). (Autonomous College Affiliated to University of Mumbai) KJSKJSCE/IT/TYBTECH/SEMVI/GAP/2019-20 Batch: Roll No.: Experiment No.: 03 Aim: Implementation of keyboard operations on sprite (Lua). Resources needed: Lua, LOVE 2D Game engine, Notepad++ Theory: A sprite is a bitmap graphic that is designed to be part of a larger scene. It can either be a static image or an animated graphic. Examples of sprites include objects in 2D video games, icons that are part of an application user interface, and small images published on websites. In the 1980s and for most of the 1990s, sprites were the standard way to integrate graphics into video games. Graphic artists created small 2D images that were used to represent characters and other objects. Developers referenced these sprites in the source code and assigned properties such as when the sprites were displayed and how they interacted with other sprites. For example, in a side-scroller, such as Super Mario Bros, the sprite of an enemy Koopa would turn into a flattened Koopa when Super Mario jumped on it. Today, some video games still use 2D sprites. Sprites are also used on the Web for navigation buttons and for adding visual appeal to WebPages. In recent years, sprite sheets have become a popular way for web developers to load website graphics. By combining a large number of sprites into a single image, all the sprites can be downloaded and cached by a user's browser with a single request to the server. The images are then displayed using CSS properties that define the locations of individual sprites within the image. In gaming, sprites are usually used for animation sequences; a sprite is a single image in which individual frames of a character animation are stored. The sprite will play the animation of the character moving.. A quad in LÖVE is a specific part of an image. Because our sprite is a single image file, quads will be used to specify each of the sequences. Declartion of variables: local imageFile local frame={} local activeframe local currentframe=1 Load the sprite and genation of quad: function love.load() imageFile = love.graphics.newImage("sprite.PNG") for i=1,8 do frame[i]=love.graphics.newQuad((i-1)*31,0,31,73, 250,73) activeframe=frame[currentframe] end end (Autonomous College Affiliated to University of Mumbai) KJSKJSCE/IT/TYBTECH/SEMVI/GAP/2019-20 Draw the sprite: function love.draw() love.graphics.draw(imageFile, activeframe,200,200) end Update the sprite: local elapsedTime=0 function love.update(dt) elapsedTime = elapsedTime + dt if (elapsedTime > 1) then if(currentframe < 7) then currentframe=currentframe+1 else currentframe=1 end activeframe=frame[currentframe] elapsedTime=0 end end Implementation: Implement to fly a helicopter. Results: (Program printout with output) Questions: 1) State the application of sprite in Games. 2) Differentiate between Static and Dynamic sprites. Outcomes: (Autonomous College Affiliated to University of Mumbai) KJSKJSCE/IT/TYBTECH/SEMVI/GAP/2019-20 Conclusion: (Conclusion to be based on the objectives and outcomes achieved) Reference Books/ Websites: 1. “Love for Lua Game Programming”, www.it-ebooks.info 2. http://www.osmstudios.com/tutorials/your-first-love2d-game-in-200-lines-part-1-of-3 3. http://www.gamefromscratch.com/post/2016/03/22/Love2D-Using-SpritesTutorial.aspx 4. https://love2d.org/wiki/Tutorial:Baseline_2D_Platformer (Autonomous College Affiliated to University of Mumbai)