So heres the case im creating a game with some of my friends, however ive run into a bit of a problem, without further ado heres the code:
-- TheAdventuresOfRocky
function setup()
displayMode(FULLSCREEN)
print("Hello World!")
bounce = .1
rx = WIDTH/2 -- the x value
ry = HEIGHT/2 -- the y value
rad = 30
rocky = physics.body(CIRCLE, rad)
rocky.x = rx
rocky.y = ry
rocky.gravityScale = 1
ground = physics.body(EDGE, vec2(0,105),
vec2(WIDTH*2,105))
ground.type = STATIC
ground.restitution = bounce
move = 0
touches = {}
jump = 0
tx = WIDTH/2
ty = HEIGHT-50
end
function draw()
background(40, 40, 50)
strokeWidth(5)
ellipse(rocky.x,rocky.y,rad)
spriteMode(CORNER)
if CurrentOrientation == LANDSCAPE_LEFT or LANDSCAPE_RIGHT then
for i=0,10 do
sprite("Planet Cute:Brown Block",i*101,0)
end
elseif CurrentOrientation == PORTRAIT or PORTRAIT_UPSIDE_DOWN then
for i=0,8 do
sprite("Planet Cute:Brown Block",i*101,0)
end
end
rocky.x = rocky.x + move
rocky.y = rocky.y + jump
textSize(60)
font("AmericanTypewriter")
fontSize(60)
text("i fell from a volcano",tx,ty)
end
function touched(touch)
if touch.state == BEGAN and touch.x > WIDTH/2 + 60 and touch.y < 105 then
move = 10
touches[touch.id] = touch
end
if touch.state == BEGAN and touch.x < WIDTH/2 - 60 and touch.y < 105 then
move = -10
touches[touch.id] = touch
end
if touch.state == ENDED then
move = 0
end
end
function collide(contact)
end
--[[--============================================================
This code is by dave1707 from Codea Forums
This code demonstrates how to scroll the screen based on the position of a circle
function setup()
displayMode(FULLSCREEN)
gdx=WIDTH/2 -- grid position
gdy=HEIGHT/2
dx=0 -- circle position
dy=HEIGHT/2
end
function draw()
background(40, 40, 50)
-- scroll the grid if the circle is off the screen
if dx>WIDTH-50-gdx then
gdx=gdx-30
elseif dx<gdx*-1+50 then
gdx=gdx+30
end
translate(gdx,400) -- move grid and circle
fill(255)
ellipse(dx,100,100,100) -- move just the circle
stroke(255)
strokeWidth(4)
fontSize(30)
for x=-3000,3000,100 do
line(x,-3000,x,3000)
text(x,x,0)
end
for y=-3000,3000,100 do
line(-3000,y,3000,y)
text(y,0,y)
end
end
function touched(t)
if t.state==BEGAN then
y1=t.y
elseif t.state==MOVING then
dx=dx+t.y-y1
y1=t.y
end
end
--]]--==================================================
@dave1707 thanks for the sidescroller code
When the user taps the bottom right or bottom left, rocky moves to the respective location, although i want rocky to “jump” when the user taps the screen, another thing i cant seem to do is to scroll the screen @dave1707 i think i may have just disgraced you, anyways if i could get some insight (not necesarrily code) on how to do those things that’d be great, thanks in advance
just to recap: need help to understand how to organise touches based on their id and i need an explanation of how the side scrollikng codeuld be applied to rocky once again thanks in advance.