Advertisement
Charbomber

Tic-80 Example Game 1

Jul 8th, 2022
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. -- title:   Test Game 1
  2. -- author:  Your name here!
  3. -- desc:    A small demo to mess around in.
  4. -- site:    charbomber.neocities.org
  5. -- license: MIT License
  6. -- version: 1.0
  7. -- script:  lua
  8.  
  9.  
  10.  
  11. function editStartHere()
  12.  -- this is the amount of things you have!
  13.  thingAmount = 4
  14.  thingGravity = 0.2
  15.  
  16. end
  17.  
  18. -- this is the part that you should
  19. --  be editing!
  20. function editUpdateHere()
  21.  
  22.  -- if the left button is pressed...
  23.  if btnp(4, 16, 16) then
  24.      -- make a new thing at the mouse
  25.      createThing(255+math.random(1,thingAmount), mx, my)
  26.     end
  27.  
  28. end
  29.  
  30.  
  31.  
  32.  
  33. -- this stuff is more complicated,
  34. --  but feel free to try
  35. --  and edit it anyways I guess.
  36.  
  37. function BOOT()
  38.  t=0
  39.  
  40.  things = {}
  41.  editStartHere()
  42. end
  43.  
  44. -- this is the way that
  45. -- new things are made
  46. function createThing(type, x, y)
  47.  -- make a new thing
  48.  things[#things+1] = {}
  49.  -- save the new thing
  50.  local newThing = things[#things]
  51.  
  52.  -- set the stuff
  53.  newThing.sprite = type
  54.  newThing.x = x
  55.  newThing.y = y
  56.  newThing.velx = 0
  57.  newThing.vely = 0
  58.  -- make the new thing run
  59.  newThing.update = function(self, listPos)
  60.   -- draw the sprite
  61.     spr(self.sprite, self.x, self.y, 0)
  62.        
  63.        
  64.        
  65.         -- do physics
  66.         --  (you should probably scroll past
  67.         --  this, it's very complicated,
  68.         --  sorry!!)
  69.         local safeguard = 0
  70.         if mget(math.floor(self.x/8), math.floor((self.y+self.vely)/8)) > 0 then
  71.             local tempy = self.vely
  72.             self.vely = 0
  73.             while mget(math.floor(self.x/8), math.floor((self.y+self.vely)/8)) > 0 do
  74.              self.y = self.y + sign(self.y)*0.1
  75.                 safegaurd = safeguard + 1
  76.                 if safeguard > 1028 then break end
  77.             end
  78.             self.vely = tempy * -1
  79.         end
  80.         safeguard = 0
  81.         if mget(math.floor((self.x+self.velx)/8), math.floor(self.y/8)) > 0 then
  82.          local tempx = self.velx
  83.             self.velx = 0
  84.             while mget(math.floor((self.x+self.velx)/8), math.floor(self.y/8)) > 0 do
  85.              self.x = self.x + sign(self.x)*0.1
  86.                 safegaurd = safeguard + 1
  87.                 if safeguard > 1028 then break end
  88.             end
  89.             self.velx = tempx * -1
  90.         end
  91.        
  92.         self.x = self.x + self.velx
  93.        
  94.         self.vely = self.vely + thingGravity
  95.         self.y = self.y + self.vely
  96.        
  97.  end
  98.  
  99.  
  100. end
  101.  
  102. function sign(number)
  103.  local signn = 0
  104.  if number > 0 then signn = 1
  105.  elseif number < 0 then signn = -1 end
  106.  
  107.  return signn
  108. end
  109.  
  110. function TIC()
  111.    
  112.     -- get the mouse controls
  113.     mx,my,button_left,button_right=mouse()
  114.    
  115.     -- do the stuff you're supposed to edit
  116.     editUpdateHere()
  117.  
  118.  -- clear the screen
  119.     cls(0)
  120.     -- draw the map
  121.     map()
  122.    
  123.     -- make things move
  124.     for i=1,#things do
  125.         things[i]:update(i)
  126.        
  127.     end
  128.    
  129.     -- make time move
  130.     t=t+1
  131. end
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement