Author Topic: Programming Codea on IPAD  (Read 3921 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Programming Codea on IPAD
« on: June 11, 2012 »


Look so cool

http://www.twolivesleft.com/Codea/

<a href="http://www.youtube.com/watch?v=jaIhEXZ7WW4" target="_blank">http://www.youtube.com/watch?v=jaIhEXZ7WW4</a>
« Last Edit: June 11, 2012 by Hotshot »

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #1 on: June 11, 2012 »
Wow, that does look pretty sweet! Meaby the iPad I bought for my mom (<- cheap excuse to play around with it myself) can get me some entertainment after all. 

But then I'd really need an external keyboard (if that's even possible ::) ) and I would feel pretty lame squinting at the iPad instead of any laptop better suited to such endeavors. Still definitely going to check it out, if for nothing else then to finally play around with the accelerometers, multitouch and all that goodness. Lua looks pretty straightforward too.

Thanks for posting!  :cheers:
www.kirl.nl
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5243
  • Karma: 393
    • View Profile
Re: Programming Codea on IPAD
« Reply #2 on: June 12, 2012 »
Fuck me! They've finally got Pong running on an iPad3.  What freakin' decade is this?!

:P

Jim
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4118
  • Karma: 181
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: Programming Codea on IPAD
« Reply #3 on: June 12, 2012 »
We're just waiting for the iPad Floppy Disk Drive to be invented, and we're on our way ;)
You are our 9001st visitor.
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #4 on: June 12, 2012 »
Quote
We're just waiting for the iPad Floppy Disk Drive to be invented, and we're on our way

<a href="http://www.youtube.com/watch?v=f5TznTKZ4VY" target="_blank">http://www.youtube.com/watch?v=f5TznTKZ4VY</a>

 :)

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #5 on: September 06, 2012 »
 :goodpost:

Having a ball with codea, thanks for posting Hotshot!

The typing isn't nearly as uncomfortable as I feared. It's good fun playing around with the accelerometers and sound generation, I'm trying to port my locoroco soft bodies to lua, hunting down some strange error atm...
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #6 on: September 07, 2012 »
I got it on my Ipad but Havnt got chance to code it properly as I have learn all the commands of it ::) then code it...



Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #7 on: September 07, 2012 »
After a few obligatory evenings of confusement, I've come to like Lua. I'm missing some functionality, but there's a lot of interesting new stuff to play with too.

I really dig the Cargo Bot example game, it's the perfect kind of thing to include in a programmers toy. Very tough and interesting logic puzzles!
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #8 on: September 13, 2012 »
Here what I did

Code: [Select]
ball={}
ball.x=width/2
ball.y=height/2
ball.size=100

ellipse(ball.x.ball.y,ball.size)

function ellipse(ball.x.ball.y,ball.size)

ball.x=ball.x+gravity.y
ball.y=ball.y+gravity.x

ellipse(CurrentTouch.x,CurrentTourch.y,10)

End

I got some error and hopefully Kirl will be able help me on those :)

p.s. I been typing this out but my laptop keyboard is German! LOL


Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #9 on: September 13, 2012 »
If you start a new codea project there are two functions: setup() and draw(). The setup function is called once the program starts and the draw function is executed continuously every frame.

I'll try to put most of the explanations in the code as comments.

Code: [Select]
supportedOrientations(LANDSCAPE_LEFT) -- set orientation to horizontal (home button on the left screen)

-- called once at the start
function setup()
friction = .98  -- friction value to slow ball down over time

ball = {}       -- create ball object
ball.x = WIDTH/2 -- set x pos at center of screen
ball.y = HEIGHT/2 -- set y pos at center of screen
ball.vx = 0     -- value for ball x velocity
ball.vy = 0     -- value for ball y velocity
ball.size = 80
end

-- called every tick/frame
function draw()

background(0,0,0, 255) -- resets the background to clear the screen

-- apply basic physics
ball.vx = ball.vx + Gravity.x
ball.vy = ball.vy + Gravity.y
ball.vx = ball.vx * friction
ball.vy = ball.vy * friction

-- add velocities to the ball position
ball.x = ball.x + ball.vx
ball.y = ball.y + ball.vy 

doBound(ball)

ellipse(ball.x, ball.y, ball.size)  -- draw a circle at the location of the ball

end

-- function to collide ball with screen borders to keep it inside
function doBound(ball)

  if ball.y-ball.size/2 < 0 then -- if ball.y-radius is smaller then 0
     ball.y = ball.size/2           -- reset ball position at the border
     ball.vy = ball.vy * -1       -- reverse y velocity
  end

   -- there's only a check for one side of the screen boundary in here, try to figure the logic for the other 3 walls!   
end


I typed this up in the forum text editor, so there might be some minor errors in there I overlooked and sorry for the lack of formatting. If you need help with the other 3 screen boundaries or want some explanations let me know.

Once you got this up and running I got some interesting but very simple little additions to experiment with, like generated sounds etc. :)
« Last Edit: September 13, 2012 by Kirl »
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #10 on: September 13, 2012 »
thanks man and been typing up on my ipad :)

Run the program but it all blank screen at the moment....I going double check it :)

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #11 on: September 13, 2012 »
There was an error in these lines:
Code: [Select]
ball.x = WIDTH/2 -- set x pos at center of screen
ball.y = HEIGHT/2 -- set y pos at center of screen
Make sure the second line reads "ball.y = ...etc" like it does now, instead of "ball.x = ..." as it said previously
Sorry for that, I'll fix it in the code above too. :)
« Last Edit: September 13, 2012 by Kirl »
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #12 on: September 13, 2012 »
i got it working n loving ball physic

My goals is get the ball bouncing round on fours side and take from there  ;)

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #13 on: September 13, 2012 »
I got ball bouncing all four side :)

One things I have notice is Not Smooth......bit stop and start ball...I am sure you know what I mean

I got bit mixed up on collisions top and bottom

Code: [Select]
if ball.y>400 then
DY=-2
END

IF ball.y<0 then
    DY=2
END

how can I make smooth?
« Last Edit: September 13, 2012 by Hotshot »

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #14 on: September 14, 2012 »
Can you explain what isn't looking smooth?

I'm not sure what your DY stands for, if it's like ball.vy you can multiply it by -1 to flip it's value from positive to negative and vice versa. In reality a bit of energy would be lost in the bounce so values between -1 and 0 would be better. (-0.8 or something)

My top bottom check looks like this:
Code: [Select]

if ball.y-ball.size/2 < 0 then -- if ball bottom is below lower screen
     ball.y = ball.size/2
     ball.vy = ball.vy * -1
elseif ball.y+ball.size/2 > HEIGHT then   -- use elseif to check either top or bottom colision
    ball.y = HEIGHT - ball.size/2             --  HEIGHT gives the screen height
     ball.vy = ball.vy * -1
end

www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #15 on: September 15, 2012 »
Quote
Can you explain what isn't looking smooth?


I have run the program again and it is ok now....strange

DX and DY is speed of the Ball inside setup function.......and I should put commets on at side of it :)

this is what I put inside draw function


Code: [Select]
ball.x=ball.x+DX
ball.y=ball.y+DY

IF ball.x>700 then
DX=-2
end

if bal.x<10 then
DX=2
end

if ball.y<-100 then
DY=-2
end

if ball.y<100 then
DY=2
end

One thought....I do know it is case sensitive.

I will look at your code for top and bottom problem I having :)





Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #16 on: September 15, 2012 »
Sometimes Codea gets a little choppy, probably because of some background processes, try resetting the ipad.

Instead of hard coding the value for the right border, I prefer to use WIDTH (wich returns the screen width) so whenever the view might change size, the border changes acordingly.
Also instead of hard coding the velocity after a bounce, you can reverse it's velocity so that it bounces off with as much speed as it hit. You can do this by multiplying the speed with -1.

This would look something like this:

Code: [Select]
ball.x=ball.x+DX
ball.y=ball.y+DY

if ball.x>WIDTH then
DX= DX * -1            -- reverse x velocity
ball.x = WIDTH         -- set ball position to prevent passing the conditional check next frame
elseif bal.x<10 then  -- elseif to check one OR the other border
DX= DX * -1
ball.x = 10
end

By using an elseif for the left and right borders you ocasionally save one conditional check. You can do this because when it collides with the right border you know it can't collide with the left border as well, so you only have to check one OR the other border.

By reversing the velocity you get a more realistic bounce, however this does require you to set the ball position to prevent it from becomming stuck. Because if it still collides with the border the next frame it would keep reversing it's direction infinitely.

Keep it up and let me know if I wasn't clear on something. :)
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #17 on: September 16, 2012 »
Quote
Sometimes Codea gets a little choppy, probably because of some background processes, try resetting the ipad.

Ahhh I see and that why :)

I used SupportOridentations(LandSCAPE RIGHT) because it is my FAV as I dont have turn my ipad upside down lol

I been playing with code today and somethings that screw myself up over Height or Width for Top to bottom and now I have finally got it working !!! Phewww  :boxer:

I have try your code but then I got myself bit lost

I try my own code of learning top bottom then left and right then got it up running like Breakout style  :clap:
Here the Full CODE  :clap:

Code: [Select]
SupportOridentations(LandSCAPE RIGHT)

Function Setup()

ball.={}
ball.x=WIDTH/2
ball.y=HEIGHT/2

ball.size=80
DX=2     
DY=2

end

Function draw()

background(10,10,20)
fill(255,0,0)

ball.x=ball.x+DX
ball.y=ball.y+DY

if ball.x>HEIGHT then -- if BALL touch the right then bounce left
  DX=-2
elseif ball.x<40 then  -- if BALL touch the left then Bounce right
  DX=2
end

if ball.y>WIDTH Then -- if Ball touch at the top then bounce down
  DY=-2
elseif ball.y<40 then -- if Ball touch at the bottom then bounce up
  DY=2
end

ellipse(ball.x,ball.y,ball.size)

end

Time for Bat and drawing Brick on the Screen and I will be using all code in just one screen instead of splitting the code files up(that bit advance for me as that will come when I am ready :)  )

I have learn so quickly putting DBF Picture in the Background while the Ball is moving in foreground :D


P.S. I couldnt find dash between landscape and right because My laptop keyboard is German!


« Last Edit: September 16, 2012 by Hotshot »

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 986
  • Karma: 219
    • View Profile
    • Homepage
Re: Programming Codea on IPAD
« Reply #18 on: September 16, 2012 »
Haha, I have no idea of what is actually up or down on the ipad anymore, what with the rotating screen and all! :)
Well done dude, good luck with the rest of your game! I hope you'll post some updates.
www.kirl.nl
Challenge Trophies Won:

Offline Hotshot

  • Pentium
  • *****
  • Posts: 1814
  • Karma: 73
    • View Profile
Re: Programming Codea on IPAD
« Reply #19 on: September 16, 2012 »
Here the Picture of it :)