SHARE
TWEET

turkey shoot game codea codify

a guest Nov 6th, 2011 152 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --turkey shoot
  2. function setup()
  3.     ts=30 -- turkey size
  4.     mts=10 -- max turkey speed
  5.     mt=((HEIGHT*WIDTH)/ts/ts/40)
  6.     tk = {} -- turkey table
  7.     for i=1,mt do
  8.         tx=math.random() * WIDTH -- turkey x
  9.         ty=math.random() * HEIGHT -- turkey y
  10.         txv=(math.random() * mts * 2) - mts -- turkey x velocity
  11.         tyv=(math.random() * mts * 2) - mts -- turker y velocity
  12.         tk[i] = {x=tx,y=ty,cxv=txv,cyv=tyv}
  13.     end  
  14. end
  15.  
  16. function draw()
  17.     background(0, 255, 33, 255)
  18.     for i,v in ipairs(tk) do
  19.         drawturkey(tk[i].x,tk[i].y,ts)
  20.         if CurrentTouch.state == BEGAN then
  21.             if (math.abs(tk[i].x - CurrentTouch.x) < ts * 2) and
  22.                 (math.abs(tk[i].y - CurrentTouch.y) < ts * 2) then
  23.                 table.remove(tk,i)
  24.             end  
  25.         else
  26.             if (tk[i].x + tk[i].cxv < ts) or (tk[i].x + tk[i].cxv > WIDTH) or 
  27.             (tk[i].y + tk[i].cyv < ts) or (tk[i].y + tk[i].cyv > HEIGHT) then
  28.                 if (tk[i].x + tk[i].cxv < ts) then
  29.                     tk[i].cxv = mts * math.random()
  30.                 elseif (tk[i].x + tk[i].cxv > WIDTH) then
  31.                     tk[i].cxv = -mts * math.random()
  32.                 end
  33.                 if (tk[i].y + tk[i].cyv < ts) then 
  34.                     tk[i].cyv = mts * math.random()
  35.                 elseif  (tk[i].y + tk[i].cyv > HEIGHT) then       
  36.                     tk[i].cyv = -mts * math.random()
  37.                 end    
  38.             end
  39.             tk[i].x = tk[i].x + tk[i].cxv 
  40.             tk[i].y = tk[i].y + tk[i].cyv             
  41.         end  
  42.     end
  43. end       
  44.  
  45. function drawturkey(tx,ty,tsize)
  46. stroke(0, 0, 0, 255)
  47.     fill(255, 187, 0, 255)
  48.     --tail feathers
  49.     ellipse(tx+(tsize/2),ty+(tsize/2),tsize/2,tsize)
  50.     ellipse(tx-(tsize/2),ty+(tsize/2),tsize/2,tsize)
  51.     ellipse(tx+(tsize/3),ty+(tsize/2),tsize/2,tsize)
  52.     ellipse(tx-(tsize/3),ty+(tsize/2),tsize/2,tsize)
  53.     ellipse(tx+(tsize/6),ty+(tsize/2),tsize/2,tsize)
  54.     ellipse(tx-(tsize/6),ty+(tsize/2),tsize/2,tsize)
  55.     ellipse(tx,ty+(tsize/2),tsize/2,tsize)
  56.     fill(0, 0, 0, 255)
  57.     --legs
  58.     ellipse(tx+(tsize/6),ty-(tsize/2),tsize/12,tsize)
  59.     ellipse(tx-(tsize/6),ty-(tsize/2),tsize/12,tsize)
  60.     fill(255, 187, 0, 255)
  61.     --body
  62.     ellipse(tx,ty,tsize,tsize)
  63.     --shoulder
  64.     ellipse(tx,ty+(tsize/6),tsize/2,tsize/2)
  65.     --neck low
  66.     ellipse(tx,ty+(tsize/3),tsize/6,tsize*5/6)
  67.     --neck high
  68.     fill(255, 0, 0, 255)
  69.     ellipse(tx,ty+(tsize/2),tsize/6,tsize/2)
  70.     --head
  71.     fill(32, 44, 105, 255)
  72.     ellipse(tx,ty+(tsize*2/3),tsize/6,tsize/3)
  73.     --eyes
  74.     fill(232, 245, 28, 255)
  75.     ellipse(tx-(tsize/12),ty+(tsize*3/4),tsize/6,tsize/6)
  76.     ellipse(tx+(tsize/12),ty+(tsize*3/4),tsize/6,tsize/6)
  77.     --pupils
  78.     --fill(0, 0, 0, 255)
  79.     --ellipse(tx-(tsize/12),ty+(tsize*3/4),tsize/12,tsize/12)    
  80.     --ellipse(tx+(tsize/12),ty+(tsize*3/4),tsize/12,tsize/12)    
  81. end    
  82.  
  83.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top