Look so cool
http://www.twolivesleft.com/Codea/
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:
Fuck me! They've finally got Pong running on an iPad3. What freakin' decade is this?!
:P
Jim
We're just waiting for the iPad Floppy Disk Drive to be invented, and we're on our way ;)
Quote
We're just waiting for the iPad Floppy Disk Drive to be invented, and we're on our way
:)
: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...
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...
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!
Here what I did
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
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.
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. :)
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 :)
There was an error in these lines:
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. :)
i got it working n loving ball physic
My goals is get the ball bouncing round on fours side and take from there ;)
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
if ball.y>400 then
DY=-2
END
IF ball.y<0 then
DY=2
END
how can I make smooth?
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:
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
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
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 :)
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:
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. :)
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:
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!
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.
Here the Picture of it :)
(http://www3.picturepush.com/photo/a/9638561/220/9638561.jpg)
:clap:
I am not sure on which one is the best for making Brick on the screen
Should I used
Arrays ?
or
For Loop?
Or
Data?
You can try storing the bricks using a 2 dimensional array (like a grid) and then check only the cells around the ball position. This way you don't have to check all the bricks, but only those around the ball position.
-- get cells around the ball position
xx = Math.floor( ball.x/cellSize ) -- get x index
yy = Math.floor( ball.y/cellSize ) -- get y index
currentCell = bricks[ xx ][ yy ] -- cell the ball is currently over
leftCell = bricks[ xx-1 ][ yy ] -- left neighbour cell
rightCell = bricks[ xx+1 ][ yy ] -- right neighbour cell
lowerCell = bricks[ xx ][ yy-1 ] -- lower neighbour cell
upperCell = bricks[ xx ][ yy+1 ] -- upper neighbour cell
I believe there is a breakout clone among the example games, you can try to figure out their solution too. :)
Looks great!
By the way, can we share our projects and builds?
Quote
By the way, can we share our projects and builds?
Yes, that is fine and it is good to learn from others :)
You on codea too Jace? Would love to see some of your projects! :)
I made a pretty cool procedural drawing tool of sorts, based on flowfields (which I've been playing with the last couple of days). Unfortunatly I can't attach pictures from the ipad (figures, Apple only works inside of it's own little universe), but because the code is pretty short I can share that (thanks for the blessing Hotshot, would be cool to have a sort of DBF Codea code repository).
Here's the code.
-- flowfield
function setup()
backingMode(RETAINED) -- retain screen pixels
background(0, 0, 0, 255) -- draw black background
col = color(math.random(255), math.random(255), math.random(255)) -- set random color
parameter("swirls", 1/2000, 1/50, 1/100) -- declare interactive swirlyness parameter
parameter("fade", 0, 1, 0) -- declare interactive screen fade parameter
parameter("transparency", 1, 10, 2.5) -- declare interactive line alpha parameter
watch("particles") -- watch particle count
touches = {} -- make container to track screen touches
parts = {} -- make container for particles
end
function touched(touch) -- track all screen touches
if touch.state == ENDED then
touches[touch.id] = nil
col = color(math.random(255), math.random(255), math.random(255), transparency*12.5)
else touches[touch.id] = touch
end
end
function draw()
fill(0, 0, 0, fade*100) -- set fill alpha acording to fade parameter
rect(0,0, WIDTH, HEIGHT) -- draw transparent rectangle to slowly fade screen
particles = #parts -- track nr of particles
col.alpha = transparency*12.5 -- set line alpha to transparancy parameter
fill(col)
for i, p in pairs(parts) do -- loop through particles
pixel = noise(p.x*swirls, p.y*swirls) -- define location of noisemap pixel
brightness = (pixel+1) / 2 * p.mult -- define brightness between 0-1
speed = brightness * p.mult -- get particle speed value
size = 2 + speed/2 * p.mult -- get particle size value
angle = brightness * 360 * math.pi / 180 -- get angle based on pixel brightness
p.x = p.x + math.cos(angle) * speed -- move particle over X
p.y = p.y + math.sin(angle) * speed -- move particle over Y
ellipse(p.x, p.y, size) -- draw particle
if p.x < 0 or p.x > WIDTH or p.y < 0 or p.y > HEIGHT then
table.remove(parts, i) -- remove particle if outside of screen
end
end
for i, t in pairs(touches) do -- add particles at touch position
if t.state == MOVING or t.state == BEGAN then
table.insert( parts, {x=t.x, y=t.y, mult=(1.5 + math.random() * 1.5)} )
end
end
end
Would love to hear what you think about it, you can create a bunch of really interesting effects by adjusting the sliders. :)
Quote from: Kirl on September 27, 2012
You on codea too Jace? Would love to see some of your projects! :)
Nope, but I think I must make try :P if you CAN share your projects, I think it is worth buying it
This might be of use / news to you dudes out there.
Blitz Research have a new toy out which you can create for all sorts of platforms and browser, it's called Monkey. It looks to be similar in style to Blitz Max with a few more bells and whistles. There's also a demo version in their store.
http://www.monkeycoder.co.nz/