̮̮̮̬̮ ̮ ̮ ̬ ̮̮̬̮̮̬DD@ODD @ DD@ODDJ DD@ODD@ J DD@OJЍ DDJ >?""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""ˆ,"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""ˆ,""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̈"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""DDDD """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""DDDD """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""DDDD """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬"""""""DDDD """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""""DDDD""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""""DDDD""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬,""""""""DD """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬,""""""""DD """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬̬""""""""""  """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬̬"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̬̬"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̪"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̪"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""̪""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""","""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""",""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""B%-- title: Comprehensive Animated Sprite System -- author: profpatonildo -- desc: A comprehensive system to handle animated sprites. -- script: lua --[[ This system is built upon the default spr function and can handle: 1. Frame by frame sprite animation; 2. Scaling; 3. Rotation; 4. Blinking; 5. Outlined sprites. You can animate the scale and rotation of sprites in a frame by frame basis. The code is very commented, to make it easier to understand. Feel free to delete the comments if they seem redundant. If you find this helpful, consider buying me a coffee: https://ko-fi.com/profpatonildo70266 I would really appreciate that! :) --]] t=0 --[[ The variable above is needed only for the print function used in this demo. You can ignore it if you don't care about the custom print function. --]] dirs={ {1,0},{-1,0},{0,1},{0,-1},{1,1}, {-1,-1},{1,-1},{-1,1} } --[[ The table above is needed for the outlined sprite effect and for the print function used in this demo. --]] --[[ "character" is used as a class to be inherited by any other object that you want animated. If you are unfamiliar with object-oriented programming in Lua, look for that topic in the Lua manual: http://www.lua.org/pil/16.html --]] character={ x=130, y=45, col_key=0, -- color key for sprite def_scl=1, -- scale for sprite w=1, -- width for sprite h=1, -- height for sprite def_rot=0, -- rotation for sprite frame_t=0, -- animation frame time frame=1, -- animation current frame blink_f=0.1, -- blinking frequency blink_t=60, -- blinking default time blink=0, -- current blink time out=true, -- outline control out_col=0, -- outline color out_thin=true, -- outline thickness -- ## ANIMATIONS LIST! ## idle={ frames={256,257}, speed=30 --[[ "frames" is a table cointaining all the sprite numbers for each frame of animation. "speed" is the speed for playblack. frame_t is incremented by 1 each tic, until it is equal to speed. Then, frame_t is set to 0 and frame is incremented by 1. When frame is larger than the ammount of frames, it gets reset to 1. That makes the animation play. --]] }, walk={ frames={258,256,{258,1},256}, speed=10 --[[ You can also pass tables inside frames -> {258,1}. In that case, the first value is the sprite, and the second value is the flip argument for the spr function. This is useful because it allows you to reuse the same sprite, but flipped, on animations like walk cycles. The values accepted for flip are the same ones for the default spr function: https://github.com/nesbox/TIC-80/wiki/spr --]] }, die={ frames={256,257,259,260}, speed=5, one_shot=true --[[ You can also define "one_shot" as true if you want the animation to play only once and then stop on the last frame, instead of looping. If you want the animation to loop, just omit this "one_shot" variable. --]] }, spin={ frames={{256,0,0},{256,0,1}, {256,0,2},{256,0,3} }, speed=10 --[[ If the values inside frames are tables, the third value in each table defines a rotation for the sprite. The values accepted for this rotation are the same ones for the default spr function: https://github.com/nesbox/TIC-80/wiki/spr --]] }, scale={ frames={{256,0,0,0},{256,0,0,1}, {256,0,0,2},{256,0,0,1} }, speed=10 --[[ If the values inside frames are tables, the fourth value in each table defines a scale for the sprite. The values accepted for this scale are the same ones for the default spr function: https://github.com/nesbox/TIC-80/wiki/spr --]] } -- ## END OF ANIMATIONS LIST! ## } character.anim=character.idle --[[ The line above adds a new variable ("anim") to the class "character". "anim" holds the animation to be currently played. --]] --[[ The function below handles the animation process. It is designed to just work. All it needs is the necessary values defined in the character class. --]] function character:draw() -- increment frames self.frame_t=self.frame_t+1 if self.frame_t>=self.anim.speed then self.frame=self.frame+1 self.frame_t=0 end -- one shot or loop if self.frame>#self.anim.frames then if self.anim.one_shot then self.frame=#self.anim.frames else self.frame=1 end end -- sanity checks if type(self.anim.frames[self.frame])=="number" then self.anim.frames[self.frame]={self.anim.frames[self.frame],0} end if not self.anim.frames[self.frame][3] then self.anim.frames[self.frame][3]=0 end if not self.anim.frames[self.frame][4] then self.anim.frames[self.frame][4]=0 end -- local variables for convenience local sprite=self.anim.frames[self.frame][1] local flip=self.anim.frames[self.frame][2] local rotation=self.def_rot+self.anim.frames[self.frame][3] local scale=self.def_scl+self.anim.frames[self.frame][4] -- correct flip according to rotation if flip>0 and (rotation==1 or rotation==3) then if flip==1 then flip=2 elseif flip==2 then flip=1 end end -- blinking effect if self.blink>0 then self.blink=self.blink-1 if t%(60*self.blink_f)//(30*self.blink_f)==1 then return end end -- check outline if self.out then -- set all colors do outline color for c=0,15 do poke4(0x3FF0*2+c,self.out_col) end -- draw the outline local len=8 if self.out_thin then len=4 end for d=1,len do spr(sprite,dirs[d][1]+self.x,dirs[d][2]+self.y,self.col_key,scale,flip,rotation,self.w,self.h) end -- reset all colors for c=0,15 do poke4(0x3FF0*2+c,c) end end -- draw the sprite spr(sprite,self.x,self.y,self.col_key,scale,flip,rotation,self.w,self.h) end --[[ The function below is just for demo. It can be ignored. --]] function character:change_anim() if btnp(4) then self.frame_t=0 self.frame=1 if self.anim==self.idle then self.anim=self.walk elseif self.anim==self.walk then self.anim=self.die elseif self.anim==self.die then self.anim=self.spin elseif self.anim==self.spin then self.anim=self.scale else self.anim=self.idle end end if btnp(5) and self.blink==0 then self.blink=self.blink_t end if btnp(6) then self.out=not self.out end if btnp(2) then self.def_rot=self.def_rot-1 if self.def_rot<0 then self.def_rot=3 end end if btnp(3) then self.def_rot=self.def_rot+1 if self.def_rot>3 then self.def_rot=0 end end end --[[ Below is an example of how you can use the system on your on objects. We'll define the object "tic80", which will inherit from the "character" class and override some of its default values. This approach can be used to create any object you need to be animated in your project. --]] tic80={ x=70, y=30, col_key=14, def_scl=3, w=2, h=2, def_rot=0, frame_t=0, frame=1, blink_f=0.3, blink_t=90, blink=0, out=true, out_col=12, out_thin=false, -- ## ANIMATIONS LIST! ## move_eyes={ frames={1,3}, speed=30 } -- ## END OF ANIMATIONS LIST! ## } tic80.anim=tic80.move_eyes --[[ Below, we are overriding the function "change_anim()" from the "character" class. Because the object "tic80" has its own "change_anim()" function, LUA will ignore the code on the original "change_anim()" function from "character" and run the code below instead for the "tic80" object. This is how you override inherited functions. The content of the function itself is relevant only to this demo. --]] function tic80:change_anim() if btnp(5) and self.blink==0 then self.blink=self.blink_t end if btnp(6) then self.out=not self.out end if btnp(2) then self.def_rot=self.def_rot-1 if self.def_rot<0 then self.def_rot=3 end end if btnp(3) then self.def_rot=self.def_rot+1 if self.def_rot>3 then self.def_rot=0 end end end --[[ The line below sets "tic80" as an object from class "character". Without this line, "tic80" wouldn't be able to use the functions and variables defined for "character". --]] setmetatable(tic80,{__index=character}) function TIC() t=t+1 cls(2) --[[ Below, the functions we created are being called for our objects. --]] character:change_anim() character:draw() tic80:change_anim() tic80:draw() end --[[ Below, there's an extended print function used to display text in this demo. If you want to learn more about it, check this cart: https://tic80.com/play?cart=2538 --]] function OVR() xprint("ANIMATED SPRITE!",120,10,{5,0},false,2,false,0,true,1) xprint("A button (Z key) to change animation",120,90,{12,0},false,1,false,0) xprint("B button (X key) to blink",120,98,{12,0},false,1,false,0) xprint("<- or -> to rotate",120,106,{12,0},false,1,false,0) xprint("X button (A key) to toggle outline",120,114,{12,0},false,1,false,0) end function xprint(txt,x,y,col,fixed, scale,smallfont,align, thin,blink) if blink then if t%(60*blink)//(30*blink)==1 then return end end if not x then x=120 align=0 end if not y then y=63 end if not col then col={12,0} end if type(col)=="number" then col={col} end if not scale then scale=1 end local width=print(txt,0,-100,0,fixed, scale,smallfont) local posx=x if align==0 then posx=x-(width//2) elseif align==1 then posx=x-width end if col[2] then local len=8 if thin then len=4 end for o=1,len do print(txt,posx+dirs[o][1], y+dirs[o][2],col[2],fixed,scale, smallfont) end end print(txt,posx,y,col[1],fixed,scale, smallfont) end