Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = 127/2
- y = 127/2
- xvel = 0
- yvel = 0
- spd = 3
- left = 0
- right = 1
- up = 2
- down = 3
- friction = 1.5
- spdup = spd/6
- scrsize = 127
- radius = 3
- moved = false
- bump = false
- score = 0
- targets = {}
- tarsize = 2
- tarmax = 10
- -- game loop functions
- function collide(x,y,r,xx,yy,rr)
- return (x < xx+rr and
- x+r > xx ) and
- (y < yy+rr and
- y+r > yy )
- end
- function _init()
- cls()
- end
- function negcap()
- if(xvel < 0) xvel = 0
- if(yvel < 0) yvel = 0
- end
- function _update()
- circfill(x,y,8,0)
- moved = false
- if(btn(up)) yvel -= spdup moved=true
- if(btn(down)) yvel += spdup moved=true
- if(btn(left)) xvel -= spdup moved=true
- if(btn(right)) xvel += spdup moved=true
- -- friction
- if(not moved)then
- yvel /= friction
- xvel /= friction
- end
- if(xvel > spd) xvel = spd
- if(yvel > spd) yvel = spd
- if(xvel < -spd) xvel = -spd
- if(yvel < -spd) yvel = -spd
- x += xvel
- y += yvel
- -- x collision
- if(x > scrsize-radius)then
- x = scrsize-radius
- if(moved) sfx(0)
- elseif(x <= radius)then
- x = radius
- if(moved) sfx(0)
- end
- -- y collision
- if(y > scrsize-radius)then
- y = scrsize-radius
- if(moved) sfx(0)
- elseif(y <= radius)then
- y = radius
- if(moved) sfx(0)
- end
- -- draw velocities
- rectfill(1,1,128,10,1)
- print("score: " .. score,1,1,8)
- -- game loop logic
- spawn() -- spawn targets
- -- target collision
- for i = 1, #targets do
- -- check each target for collision
- if(collide(x,y,radius,
- targets[i].x,
- targets[i].y,
- tarsize)
- )then
- del(targets,targets[i])
- xvel = xvel/2
- yvel = yvel/2
- score += 200
- sfx(1)
- break
- else
- -- clear target
- circfill(
- targets[i].x,
- targets[i].y,tarsize,0)
- -- move target
- targets[i].y += 1
- if(targets[i].y > scrsize)then
- targets[i].y = rnd(scrsize-10)+10
- targets[i].x = rnd(scrsize)
- end
- end
- end
- end
- function _draw()
- -- draw light green circle.
- circfill(x,y,radius,11)
- for i = 1, #targets do
- -- render each target
- circfill(
- targets[i].x,
- targets[i].y,
- tarsize,
- targets[i].c)
- end
- end
- -- spawn in targets
- function spawn()
- -- randomly spawn
- local spn = rnd(10)
- local rx = rnd(scrsize)
- local ry = rnd(scrsize-10)+10
- if(flr(spn) == 5 and #targets < tarmax )then
- targets[#targets+1] = {
- x = rx,
- y = ry,
- c = rnd(14)+1
- }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement