Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- title: Test Game 1
- -- author: Your name here!
- -- desc: A small demo to mess around in.
- -- site: charbomber.neocities.org
- -- license: MIT License
- -- version: 1.0
- -- script: lua
- function editStartHere()
- -- this is the amount of things you have!
- thingAmount = 4
- thingGravity = 0.2
- end
- -- this is the part that you should
- -- be editing!
- function editUpdateHere()
- -- if the left button is pressed...
- if btnp(4, 16, 16) then
- -- make a new thing at the mouse
- createThing(255+math.random(1,thingAmount), mx, my)
- end
- end
- -- this stuff is more complicated,
- -- but feel free to try
- -- and edit it anyways I guess.
- function BOOT()
- t=0
- things = {}
- editStartHere()
- end
- -- this is the way that
- -- new things are made
- function createThing(type, x, y)
- -- make a new thing
- things[#things+1] = {}
- -- save the new thing
- local newThing = things[#things]
- -- set the stuff
- newThing.sprite = type
- newThing.x = x
- newThing.y = y
- newThing.velx = 0
- newThing.vely = 0
- -- make the new thing run
- newThing.update = function(self, listPos)
- -- draw the sprite
- spr(self.sprite, self.x, self.y, 0)
- -- do physics
- -- (you should probably scroll past
- -- this, it's very complicated,
- -- sorry!!)
- local safeguard = 0
- if mget(math.floor(self.x/8), math.floor((self.y+self.vely)/8)) > 0 then
- local tempy = self.vely
- self.vely = 0
- while mget(math.floor(self.x/8), math.floor((self.y+self.vely)/8)) > 0 do
- self.y = self.y + sign(self.y)*0.1
- safegaurd = safeguard + 1
- if safeguard > 1028 then break end
- end
- self.vely = tempy * -1
- end
- safeguard = 0
- if mget(math.floor((self.x+self.velx)/8), math.floor(self.y/8)) > 0 then
- local tempx = self.velx
- self.velx = 0
- while mget(math.floor((self.x+self.velx)/8), math.floor(self.y/8)) > 0 do
- self.x = self.x + sign(self.x)*0.1
- safegaurd = safeguard + 1
- if safeguard > 1028 then break end
- end
- self.velx = tempx * -1
- end
- self.x = self.x + self.velx
- self.vely = self.vely + thingGravity
- self.y = self.y + self.vely
- end
- end
- function sign(number)
- local signn = 0
- if number > 0 then signn = 1
- elseif number < 0 then signn = -1 end
- return signn
- end
- function TIC()
- -- get the mouse controls
- mx,my,button_left,button_right=mouse()
- -- do the stuff you're supposed to edit
- editUpdateHere()
- -- clear the screen
- cls(0)
- -- draw the map
- map()
- -- make things move
- for i=1,#things do
- things[i]:update(i)
- end
- -- make time move
- t=t+1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement