Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(os.clock())
- player={}
- player[1]={x=10,y=10,w=5,h=40,vel=3,score=0}
- player[1].img = image.create(player[1].w,player[1].h,color.new(0,255,0))
- player[2]={x=465,y=10,w=5,h=40,vel=3,score=0}
- player[2].img = image.create(player[2].w,player[2].h,color.new(0,0,255))
- ball={x=240,y=136,w=10,h=10,ang=math.random(1,360),vel=3,dir=1,p=0}
- ball.img=image.create(ball.w,ball.h,color.new(255,0,0))
- function colision(Obj1,Obj2)
- if Obj1.x + Obj1.w >= Obj2.x and
- Obj1.x <= Obj2.x + Obj2.w and
- Obj1.y + Obj1.h >= Obj2.y and
- Obj1.y <= Obj2.y + Obj2.h then
- return true else return false
- end
- end
- ball.img:center(ball.w/2,ball.h/2)
- while true do
- controls.read()
- ejex = math.cos(math.rad(ball.ang-90))*ball.vel
- ejey = math.sin(math.rad(ball.ang-90))*ball.vel
- if ball.x-ball.w/2 <= 0 then ejex = -ejex end
- if ball.y-ball.h/2 <= 0 then ejey = -ejey end
- if ball.x+ball.w/2 >= 480 then ejex = -ejex end
- if ball.y+ball.h/2 >= 272 then ejey = -ejey end
- ball.ang = math.atan2(ejey,ejex);
- ball.img:blit(ball.x,ball.y)
- if controls.r() then
- ball.ang = ball.ang +1
- end
- if controls.l() then
- ball.ang = ball.ang -1
- end
- if not controls.start() then
- ball.x = ball.x + math.cos(math.rad(ball.ang-90))*ball.vel
- ball.y = ball.y + math.sin(math.rad(ball.ang-90))*ball.vel
- end
- for i=1, #player do
- if colision(player[i],ball) then ball.ang = ball.ang+90 end
- player[i].img:blit(player[i].x,player[i].y)
- end
- if controls.down() then player[1].y = math.min(player[1].y + player[1].vel,272-player[1].h) end
- if controls.up() then player[1].y = math.max(player[1].y - player[1].vel ,0) end
- if controls.cross() then player[2].y = math.min(player[2].y + player[2].vel,272-player[2].h) end
- if controls.triangle() then player[2].y = math.max(player[2].y - player[2].vel ,0) end
- screen.print(50,5,ball.ang)
- if controls.select() then a() end
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement