Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setup()
- origin = vec2(0,0)
- w2 = WIDTH/2
- h2 = HEIGHT/2
- bullets = {}
- lastbullet = ElapsedTime
- end
- function draw()
- background(255, 255, 255, 255)
- if CurrentTouch.state==BEGAN then
- sprite("Planet Cute:Star",CurrentTouch.x,CurrentTouch.y)
- sound(SOUND_SHOOT,20)
- make_bullet()
- elseif CurrentTouch.state==MOVING then
- sound(SOUND_SHOOT,20)
- sprite("Planet Cute:Star",CurrentTouch.x,CurrentTouch.y)
- make_bullet()
- end
- for k, b in pairs(bullets) do
- sprite("Small World:Sword",bullets[k].x,bullets[k].y)
- bullets[k].x = bullets[k].x - (bullets[k].vx * 10)
- bullets[k].y = bullets[k].y - (bullets[k].vy * 10)
- if (bullets[k].x > WIDTH) or
- (bullets[k].x < 0) or
- (bullets[k].x > HEIGHT) or
- (bullets[k].x < 0) then
- table.remove(bullets,k)
- end
- end
- t = vec2(CurrentTouch.x-w2, CurrentTouch.y-h2)
- r = math.deg(origin:angleBetween(t))-270
- translate(w2,h2)
- rotate(r)
- sprite("Planet Cute:Heart")
- end
- --the star is the direction you should shoot and the heart is the player
- function make_bullet()
- if ElapsedTime - lastbullet > 0.5 then
- print(ElapsedTime - lastbullet)
- lastbullet = ElapsedTime
- d = vec2(CurrentTouch.x,CurrentTouch.y)
- t = vec2(WIDTH/2,HEIGHT/2)
- v = t - d
- v = v:normalize()
- table.insert(bullets, {x=w2,y=h2,vx=v.x,vy=v.y})
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement