Advertisement
Guest User

Untitled

a guest
Nov 16th, 2011
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. function setup()
  2.     origin = vec2(0,0)
  3.     w2 = WIDTH/2
  4.     h2 = HEIGHT/2
  5.     bullets = {}
  6.     lastbullet = ElapsedTime
  7. end
  8.  
  9. function draw()
  10.     background(255, 255, 255, 255)
  11.  
  12.     if CurrentTouch.state==BEGAN then
  13.         sprite("Planet Cute:Star",CurrentTouch.x,CurrentTouch.y)
  14.         sound(SOUND_SHOOT,20)
  15.         make_bullet()
  16.     elseif CurrentTouch.state==MOVING then
  17.         sound(SOUND_SHOOT,20)
  18.         sprite("Planet Cute:Star",CurrentTouch.x,CurrentTouch.y)
  19.         make_bullet()
  20.     end
  21.     
  22.     for k, b in pairs(bullets) do
  23.           sprite("Small World:Sword",bullets[k].x,bullets[k].y)  
  24.           bullets[k].x = bullets[k].x - (bullets[k].vx * 10)
  25.           bullets[k].y = bullets[k].y - (bullets[k].vy * 10)
  26.           if (bullets[k].x > WIDTH) or
  27.             (bullets[k].x < 0) or
  28.             (bullets[k].x > HEIGHT) or
  29.             (bullets[k].x < 0) then
  30.               table.remove(bullets,k)  
  31.           end    
  32.     end    
  33.  
  34.     t = vec2(CurrentTouch.x-w2, CurrentTouch.y-h2)
  35.     r = math.deg(origin:angleBetween(t))-270
  36.  
  37.     translate(w2,h2)
  38.     rotate(r)
  39.  
  40.     sprite("Planet Cute:Heart")
  41.     
  42. end
  43.  
  44. --the star is the direction you should shoot and the heart is the player
  45.  
  46. function make_bullet()
  47.     if ElapsedTime - lastbullet > 0.5 then
  48.         print(ElapsedTime - lastbullet)
  49.         lastbullet = ElapsedTime
  50.         d = vec2(CurrentTouch.x,CurrentTouch.y)
  51.         t = vec2(WIDTH/2,HEIGHT/2)
  52.         v = t - d
  53.         v = v:normalize()
  54.         table.insert(bullets, {x=w2,y=h2,vx=v.x,vy=v.y})
  55.     end
  56. end    
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement