Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Need help!

edited December 2013 Posts: 116

I need help with my project! Run it, tap twice at the left half of the screen, set the first parameter to 200-700 and set the 'y' parameter to -1 and tap at right half if the screen. It must jump like when 'y' is 0! But it sets charx.speed to 13. I think i have done all right! Here is my project

--# Main
-- lol

-- Use this function to perform your initial setup
function setup()
parameter.integer("lol",0,1000,1000 )
parameter.integer("y",-1,1,1)
parameter.integer("x", -1,0,0)
wall = Wall(50)
char = Char(50,48,50,50,0,0,y)
charx = CharX(WIDTH - wall.width - 48,100,50,50,0,0,x)
block = Block(WIDTH,48,50,50,0,y)
blockx = BlockX(WIDTH - wall.width - 50 + 2, HEIGHT,50,50,0,x)
ground = Ground(50)
timer = false
vert = true
print("touch to start")

end

function draw()
print(charx.speed)
wall.x = lol
char.side = y
block.side = y
charx.side = x
blockx.side = x
background(40, 40, 50)
if timer == true then
if vert == true then
ground:draw()
char:draw()
block:draw()
block.x = block.x - 3
block.y = ground.y + 48
if char.y <= ground.y + ground.height -3 then
char.y = ground.y + ground.height -2
char.tappedj = false
char.speed = 0
char.a = true
end
else
wall:draw()
charx:draw()
blockx:draw()
blockx.y = blockx.y - 3
blockx.x = WIDTH - wall.width-50+2
if charx.side == 0 then
if charx.x >= wall.x - wall.width + 3 then
charx.x = wall.x - wall.width +2
charx.tappedj = false
charx.speed = 0
charx.a = true
end
else
if charx.x <= wall.x + wall.width -3 then
charx.x = wall.x + wall.width -2
charx.tappedj = false
charx.speed = 0
charx.a = true
end
end
end
end
if timer == false then
if CurrentTouch.state == BEGAN then
timer = true
end
end
if CurrentTouch.x < WIDTH/2  and CurrentTouch.state == BEGAN then
if vert == true then
--while block.y <= -51 do
--ground.y = ground.y - 3
--block.y = block.y - 3
--char.y = char.y -3
--end
vert = false
else
--while block.y >= -51 do
--ground.y = ground.y - 3
--block.y = block.y - 3
--char.y = char.y -3
--end
vert = true
end
end
end

function gameOver()
timer = false
print("Game Over!")
print("Tap to restart")
block.x = WIDTH
end
--# Char
Char = class()

function Char:init(x,y,w,h,a,s,sd)
-- you can accept and set parameters here
self.x = x
self.y = y
self.width = w
self.height = h
self.angle = a
self.speed = s
self.acc = 0.3
self.tappedj = false
self.a = true
self.side = sd
end

function Char:draw()
rect(self.x,self.y,self.width,self.height)
rotate(self.angle)
fill(255,255,255)
smooth()
noStroke()
self.y = self.y + (self.speed * self.side)
if self.speed == 0 then
self.y = ground.y - ((self.width +2) * self.side)
end
if CurrentTouch.x > WIDTH/2  and CurrentTouch.state == BEGAN then
if self.a == true then
self.speed = 13 * self.side
self.a = false
end
self.tappedj = true
end
if self.tappedj == true then
self.speed = self.speed - (self.acc * self.side)
end

--if (self.x > block.x and self.x < block.x + block.width) or (self.x < block.x + block.width - self.width and self.x > block.x - self.width) then
--if self.y < block.y + block.height then
--gameOver()
--end
--end
end

function Char:touched(touch)
-- Codea does not automatically call this method
end

--# Block
Block = class()

function Block:init(x,y,w,h,a,sd)
-- you can accept and set parameters here
self.x = x
self.y = y
self.width = w
self.height = h
self.angle = a
self.side = sd
end

function Block:draw()
rect(self.x,self.y,self.width,self.height)
rotate(self.angle)
fill(255,255,255)
smooth()
noStroke()
if self.x <= -50 then
self.x = WIDTH -- * math.random(3)
end
end

function Block:touched(touch)
-- Codea does not automatically call this method
end

--# Ground
Ground = class()

function Ground:init(h)
-- you can accept and set parameters here
self.x = 0
self.y = 0
self.width = WIDTH
self.height = h
self.angle = 0
end

function Ground:draw()
self.width = WIDTH
rect(self.x,self.y,self.width,self.height)
rotate(self.angle)
fill(255,255,255)
smooth()
noStroke()

end

function Ground:touched(touch)
-- Codea does not automatically call this method
end

--# CharX
CharX = class()

function CharX:init(x,y,w,h,a,s,sd)
-- you can accept and set parameters here
self.x = x
self.y = y
self.width = w
self.height = h
self.angle = a
self.speed = s
self.acc = 0.3
self.tappedj = false
self.a = true
self.side = sd
end

function CharX:draw()
rect(self.x,self.y,self.width,self.height)
rotate(self.angle)
fill(255,255,255)
smooth()
noStroke()
self.x = self.x - self.speed
if self.speed == 0 then
self.x = wall.x - self.width - self.width * self.side - wall.width * self.side --stay on wall
end
if CurrentTouch.x > WIDTH/2  and CurrentTouch.state == BEGAN then
if self.a == true then
self.speed = 13 * (self.side - self.side + 1)
self.a = false
end
self.tappedj = true
end
if self.tappedj == true then
--if self.side == 0 then
--  self.speed = -self.speed
--  self.speed = self.speed + self.acc
--else
self.speed = self.speed - (self.acc * (self.side - self.side + 1)) --jump acc
--end
end

--if (self.y > block.y and self.y < block.y + block.height) or (self.y < block.y + block.height - self.height and self.y > block.y - self.height) then
--if self.x > block.x - block.width then
--gameOver()
--end
--end
end

function CharX:touched(touch)
-- Codea does not automatically call this method
end

--# BlockX
BlockX = class()

function BlockX:init(x,y,w,h,a,sd)
-- you can accept and set parameters here
self.x = x
self.y = y
self.width = w
self.height = h
self.angle = a
self.side = sd
end

function BlockX:draw()
self.x = wall.x - self.width +2
rect(self.x,self.y,self.width,self.height)
rotate(self.angle)
fill(255,255,255)
smooth()
noStroke()
if self.y <= -50 then
self.y = HEIGHT -- * math.random(3)
end

end

function BlockX:touched(touch)
-- Codea does not automatically call this method
end

--# Wall
Wall = class()

function Wall:init(w)
-- you can accept and set parameters here
self.x = w
self.y = 0
self.width = 50
self.height = HEIGHT
end

function Wall:draw()
rect(self.x,self.y,self.width,self.height)
fill(255,255,255)
smooth()
stroke(255, 255, 255, 255)
strokeWidth = 8
end

function Wall:touched(touch)

end
Tagged:

• edited December 2013 Posts: 1,595

@Prynok that's much easier on the eyes, thanks.

Edit: Had a play with it but I can't see a problem, from what you described anyway.. It sets the char speed to 13 on 0 and -1 but the box collides with the wall on +1 because you're still using the left direction.

• Posts: 2,161

I formatted the code in the original post (mod abilities) and deleted the two reposts of the code.

• edited December 2013 Posts: 7,810

@TimurEke Maybe it would be easier if you describe what you're trying to do. Tell us what is supposed to happen when we touch the screen on the left side, right side, etc. When I tap the right side, the one cube jumps. I assume it's supposed to jump over the cube that moving to the left.

• Posts: 5,396

And if you post code, put three ~ on the line before the code, and another three ~ on the line after the code, and it will be formatted nicely. If you edit your original post, you will see how this has been done for you.

• Posts: 0

Cool keep improving this!

• Posts: 116

@dave1707 yes u have right at your last sentence. When y is -1 and u tap the right side of the screen the block must jump to right! But it tries to jump to left and i dont understand this cuz i set the speed to -13 here:

self.speed = 13 * (self.side - self.side +1)

• Posts: 116

@Ignatz ^
|
|
Wow it looks cool, thankz