[QUOTE=GranPC;32920750]I think I'm pretty much done with mine.
[url="http://www.peniscorp.com/stuff/braekout.love"]Here[/url]'s the LÖVE file. Feel free to unzip it, rip out all my files and use my images for whatever. Feel free to use the code for learning purposes as well :v:
[url="http://www.peniscorp.com/stuff/braekout-exe.rar"]EXE file[/url] for the lazy who don't have LÖVE installed.
[editline]23rd October 2011[/editline]
By the way, you can use both mouse or keyboard input. However, in order for keyboard input to work, your mouse must not be moving.[/QUOTE]
Peniscorp?
If you want to implement bricks. Do you check for collisions for every single brick?
yes
[QUOTE=xxxkiller;32922561]If you want to implement bricks. Do you check for collisions for every single brick?[/QUOTE]
Make a 3-dimensional array/table with the bricks. Then check if there is a brick at one of the four sides of the ball. Pretty much like a tile-based game.
Well, I am going to attempt this coming from very little LUA knowledge.
[QUOTE=TheDecryptor;32922136]I did the "physics" on the ball by storing the position and velocity, then inverting the velocity when it hit something (Invert X direction when it hit a side wall, Y direction if it hit the top/paddle)[/QUOTE]
I feel stupid now. That sounds a lot easier than my rules for the 45 degree angle stuff.
[QUOTE=DrLuke;32920944]Have a free book: [url]http://www.lua.org/pil/[/url][/QUOTE]
This is an outdated and beginner-unfriendly resource.
It's good for wellrounded programmers, but for beginners I would recommended [url=http://luatut.com/crash_course.html]this[/url]; despite being very straight to the point and shallow, it's a good learning tool for people very new to programming (as long as the user reviews the [url=http://luatut.com/introduction.html]preface[/url] first).
PIL isn't that out dated and its only for helping a learner get used to lua. I see nothing wrong with it.
[QUOTE=Map in a box;32923627]PIL isn't that out dated and its only for helping a learner get used to lua. I see nothing wrong with it.[/QUOTE]
It assumes the reader has prior knowledge of programming languages; it's specifically aimed at C programmers wanting to implement Lua as a scripting language.
The terminology usage and reference to advance concepts limits its usefulness for teaching beginners.
It's outdated in that the online version is for Lua 5.0, not 5.1. Although there isn't much difference, it's still confusing for newcomers.
Once familiar with the basics of the language, it makes a good referencing resource for the more 'official' definitions of the various aspects of the language, and can be used to learn the more advanced aspects.
At this point: yes, it's fine.. but not for a beginner.
My ball physics were super simple. If goingleft is true the ball goes left. If not, the ball goes right. If the ball hits the right wall goingleft is true, if it hits the left wall goingleft is false. Same thing with the top and paddle.
[QUOTE=elih595;32921156]How do you assign this
[code]
function CheckCollision(box1x, box1y, box1w, box1h, box2x, box2y, box2w, box2h)
if box1x > box2x + box2w - 1 or -- Is box1 on the right side of box2?
box1y > box2y + box2h - 1 or -- Is box1 under box2?
box2x > box1x + box1w - 1 or -- Is box2 on the right side of box1?
box2y > box1y + box1h - 1 -- Is b2 under b1?
then
return false -- No collision. Yay!
else
return true -- Yes collision. Ouch!
end
end
[/code]
To 2 drawn objects, not sprites.[/QUOTE]
Just saying that this only returns true or false if it is colliding at ANY point meaning, if the ball hits the side of the paddle it wont tell you if it hit the sides, top , or bottom. That said put it in your update loop.
[QUOTE=Stary2001;32920267]to set the background colour, you use love.graphics.setBackgroundColor(r,g,b)[/QUOTE]
Oh, now I feel really dumb.
EDIT: Wait, is it supposed to look like this? I keep getting syntax errors.
[QUOTE]love.graphics.setBackgroundColor(55, 170, 255)[/QUOTE]
[QUOTE=All0utWar;32924792]Oh, now I feel really dumb.
EDIT: Wait, is it supposed to look like this? I keep getting syntax errors.[/QUOTE]
That should work fine.
[QUOTE=All0utWar;32924792]Oh, now I feel really dumb.
EDIT: Wait, is it supposed to look like this? I keep getting syntax errors.[/QUOTE]
[url]http://love2d.org/wiki/love.graphics.setBackgroundColor[/url]
love.graphics.setBackgroundColor( rgb )
table rgb
A numerical indexed table with the red, green and blue values as numbers.
[editline]23rd October 2011[/editline]
[QUOTE=BlkDucky;32924920]That should work fine.[/QUOTE]
It would work if he was using love 0.8.0 which is not released
[QUOTE=All0utWar;32924792]Oh, now I feel really dumb.
EDIT: Wait, is it supposed to look like this? I keep getting syntax errors.[/QUOTE]
love.graphics.setBackgroundColor({55, 170, 255})
try that
[QUOTE=FlashStock;32924945][url]http://love2d.org/wiki/love.graphics.setBackgroundColor[/url]
love.graphics.setBackgroundColor( rgb )
table rgb
A numerical indexed table with the red, green and blue values as numbers.
[editline]23rd October 2011[/editline]
It would work if he was using love 0.8.0 which is not released[/QUOTE]
Oh right. Yeah. I'm using 0.8.0, so :v:
setBackgroundColor(r, g, b) works all the time. setBackgroundColor(colortable) works since 0.7.0. setBackgroundColor(r, g, b, a) works since 0.8.0, although I don't really know what the alpha component actually does. :P
[QUOTE=Jawalt;32924981]love.graphics.setBackgroundColor({55, 170, 255})
try that[/QUOTE]
"Syntax error: main.lua:17:<name> or '...' expected near '{'"
Line 17 just says, function love.graphics.setBackgroundColor({55, 170, 255})
[QUOTE=All0utWar;32925173]"Syntax error: main.lua:17:<name> or '...' expected near '{'"
Line 17 just says, function love.graphics.setBackgroundColor({55, 170, 255})[/QUOTE]
function? That shouldn't be there.
[editline]23rd October 2011[/editline]
[QUOTE=slime73;32925124]setBackgroundColor(r, g, b) works all the time. setBackgroundColor(colortable) works since 0.7.0. setBackgroundColor(r, g, b, a) works since 0.8.0, [B]although I don't really know what the alpha component actually does.[/B] :P[/QUOTE]
I remember asking this in #love. No-one seemed to know. v:v:v
[QUOTE=BlkDucky;32925209]function? That shouldn't be there.
[editline]23rd October 2011[/editline]
I remember asking this in #love. No-one seemed to know. v:v:v[/QUOTE]
I keep getting another error on the word 'end'.
EDIT: Nevermind, I figured that shit out like a boss.
Right got the ball bouncing round the window like a child on acid, now I just need to figure out how to get it to collide with the paddle.
Okay, I have yet another problem. This time, I have just figured out how to make the pictures (sprites or whatever) move. The problem is, whenever I start the game the paddle is at the top of the screen. Well, when I try to put it at the bottom of the screen, I can't move the paddle at all!
[QUOTE]function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
elseif love.keyboard.isDown("left") then
x =x - (speed * dt)
end
end[/QUOTE]
Then here is the code I'm trying to change which makes the paddle immobile. (I'm trying to change the x and y coordinates.)
[QUOTE] love.graphics.draw(paddle, x, y)[/QUOTE]
So I've got the ball(doesn't move), and I've got the paddle (does move), and I've got it to play A-Ha's Take On Me, but I don't know how to get the ball to move. :O
[QUOTE=All0utWar;32927146]Okay, I have yet another problem. This time, I have just figured out how to make the pictures (sprites or whatever) move. The problem is, whenever I start the game the paddle is at the top of the screen. Well, when I try to put it at the bottom of the screen, I can't move the paddle at all!
Then here is the code I'm trying to change which makes the paddle immobile. (I'm trying to change the x and y coordinates.)[/QUOTE]
Show complete code. Use pastebin or something if it's too long.
[QUOTE=BlkDucky;32927250]Show complete code. Use pastebin or something if it's too long.[/QUOTE]
[QUOTE]function love.load()
love.graphics.setMode(640, 480, false, true, 0)
love.graphics.setCaption("THIS. GAME. IS. FUN.")
player = love.graphics.newImage("player.png")
love.graphics.setBackgroundColor(55, 170, 255)
paddle = love.graphics.newImage("player.png")
x = 50
speed = 300
end
function love.draw()
love.graphics.print("Press Enter to begin!", 250, 175)
love.graphics.print("Press Escape to quit.", 250, 400)
Font = love.graphics.newFont(14)
love.graphics.setFont(14)
love.graphics.draw(paddle, x, y)
end
function love.keypressed(key)
if key == "escape" then
love.event.push("q")
end
end
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
elseif love.keyboard.isDown("left") then
x =x - (speed * dt)
end
end[/QUOTE]
It says "Press Enter to begin!" because I don't know how to add a main menu so I just left it there until I figure out how.
Also, why does it take so long to close out the game when I press Escape?[editline][/editline]
y is not set anywhere
You're not defining y anywhere. Works fine here when you add:
y = love.graphics:getHeight() - paddle:getHeight()
under x = 50.
[editline]23rd October 2011[/editline]
[QUOTE=All0utWar;32927660] Also, why does it take so long to close out the game when I press Escape?[editline][/editline][/QUOTE]
Doesn't for me. Instant.
Oh thanks. Didn't even think about y, which I should have.
EDIT: Apparently it was slow because I was using text incorrectly. At least, that's why I think it was slow. (Still not sure how to use it because it was confusing.)
[QUOTE=All0utWar;32927660]It says "Press Enter to begin!" because I don't know how to add a main menu so I just left it there until I figure out how.
Also, why does it take so long to close out the game when I press Escape?[editline][/editline][/QUOTE]
Ewww redefining the Font variable every draw call. Put that shit in load().
Speaking of which, it's not used and then being overridden with a setFont variant.
And speaking of that variant:
[quote]This variant creates a new font using the default font and the size specified, and sets it as the current font. [b]Do not use this function in love.update or love.draw.[/b] That would create a new font every frame, eating up memory very quickly.
love.graphics.setFont( size )[/quote]
I've got the ball moving but I have no idea how I can do the collision stuff.
Sorry, you need to Log In to post a reply to this thread.