Hello everybody,
This is my first time to use programming to represent ideas. I cut some code from example and try to build up the effect I think. I want that two or more people can control certain object (for example the block I made) which could influence other people’s object. I am not sure the structure of programming and how to make two ipad communicate with each other. Now, I only separate the screen to let two users to control each other. And, I also put different power for two sides to make the control area different.
I put my code below and hope someone could give me some suggestion or other examples that I can try. Thank you very much. Also, about communicating with two ipad, is it possible?
The Video : http://www.youtube.com/watch?v=y_ZZp3fCdIk
function setup()
iparameter("Fix",1,3,1)
iparameter("AHierachical",1,3,1)
iparameter("BHierachical",1,3,1)
s= (WIDTH+52)
m= (HEIGHT+32)
paddleA = PaddleAA(s/2, 200)
paddleB = PaddleBB(s/2, m - 200)
end
function draw()
people = (AHierachical)+(BHierachical)
watch("people")
change=(Fix)*80
aahierachical=(AHierachical)*40
bbhierachical=(BHierachical)*40
background(71, 71, 71, 255)
fill(81, 81, 81, 255)
stroke(181, 181, 181, 255)
strokeWidth(5)
rectMode(2)
rect(s/2, 200, 1000, 50)
rect(s/2, m - 200, 1000, 50)
stroke(94, 106, 118, 255)
line(0, m/2, 748, m/2)
local a = 40
stroke(60+(Fix)*50)
lineCapMode(SQUARE)
strokeWidth(5)
line((1*a),220,(1*a),180)
line((2*a),220,(2*a),180)
line((3*a),220,(3*a),180)
line((4*a),220,(4*a),180)
line((5*a),220,(5*a),180)
line((6*a),220,(6*a),180)
line((7*a),220,(7*a),180)
line((8*a),220,(8*a),180)
line((9*a),220,(9*a),180)
line((10*a),220,(10*a),180)
line((11*a),220,(11*a),180)
line((12*a),220,(12*a),180)
line((13*a),220,(13*a),180)
line((14*a),220,(14*a),180)
line((15*a),220,(15*a),180)
line((16*a),220,(16*a),180)
line((17*a),220,(17*a),180)
line((18*a),220,(18*a),180)
line((1*a),m - 180,(1*a),m - 220)
line((2*a),m - 180,(2*a),m - 220)
line((3*a),m - 180,(3*a),m - 220)
line((4*a),m - 180,(4*a),m - 220)
line((5*a),m - 180,(5*a),m - 220)
line((6*a),m - 180,(6*a),m - 220)
line((7*a),m - 180,(7*a),m - 220)
line((8*a),m - 180,(8*a),m - 220)
line((9*a),m - 180,(9*a),m - 220)
line((10*a),m - 180,(10*a),m - 220)
line((11*a),m - 180,(11*a),m - 220)
line((12*a),m - 180,(12*a),m - 220)
line((13*a),m - 180,(13*a),m - 220)
line((14*a),m - 180,(14*a),m - 220)
line((15*a),m - 180,(15*a),m - 220)
line((16*a),m - 180,(16*a),m - 220)
line((17*a),m - 180,(17*a),m - 220)
line((18*a),m - 180,(18*a),m - 220)
paddleA:draw()
paddleB:draw()
end
function touched(touch)
if CurrentTouch.state == MOVING and CurrentTouch.y < m/2 then
paddleA.position.x = paddleA.position.x + CurrentTouch.deltaX
paddleB.position.x = paddleA.position.x + CurrentTouch.deltaX
if paddleA.position.x < ((change)+(aahierachical))
and paddleB.position.x < ((change)+(aahierachical)) then
paddleA.position.x = ((change)+(aahierachical))
paddleB.position.x = ((change)+(aahierachical))
elseif paddleA.position.x > s - ((change)+(aahierachical))
and paddleB.position.x > s - ((change)+(aahierachical)) then
paddleA.position.x = s - ((change)+(aahierachical))
paddleB.position.x = s - ((change)+(aahierachical))
end
end
if CurrentTouch.state == MOVING and CurrentTouch.y > m/2 then
paddleB.position.x = paddleB.position.x + CurrentTouch.deltaX
paddleA.position.x = paddleB.position.x + CurrentTouch.deltaX
if paddleA.position.x < ((change)+ (bbhierachical))
and paddleB.position.x < ((change)+(bbhierachical)) then
paddleA.position.x = ((change)+(bbhierachical))
paddleB.position.x = ((change)+(bbhierachical))
elseif paddleA.position.x > s - ((change)+(bbhierachical))
and paddleB.position.x > s - ((change)+(bbhierachical)) then
paddleA.position.x = s - ((change)+(bbhierachical))
paddleB.position.x = s - ((change)+(bbhierachical))
end
end
end
PaddleAA = class()
function PaddleAA:init(x, y)
self.position = vec2(x, y)
self.deltaX = deltaX
self.width = 80
self.height = 50
end
function PaddleAA:draw()
pushStyle()
noSmooth()
strokeWidth(3)
stroke(255, 255, 255, 255)
fill(0, 255, 185, 255)
rectMode(2)
rect(self.position.x, self.position.y, self.width, self.height)
popStyle()
end
PaddleBB = class()
function PaddleBB:init(x, y)
self.position = vec2(x, y)
self.width = 80
self.height = 50
end
function PaddleBB:draw()
pushStyle()
noSmooth()
strokeWidth(3)
stroke(255, 255, 255, 255)
fill(0, 185, 255, 255)
rectMode(2)
rect(self.position.x, self.position.y, self.width, self.height)
popStyle()
end