[QUOTE=Darkest_97;32976616]Instead of doing important things in school like homework:
[video=youtube;MngERy9-MQQ]http://www.youtube.com/watch?v=MngERy9-MQQ[/video]
Making the ball bounce of the bricks would require me to find out which side of the brick I hit. I dont feel like figuring that out.
Also, the 'ball' is an image of a ball. But it just draws that square the size of an image. I have this:
[CODE]ballImg = love.graphics.newImage("ball.png")
function love.draw()
love.graphics.draw(ballImg, ball.X, ball.Y)
end[/CODE]
The image is a png which I thought was fine. Do I have to do something else?
Heres the source if anyone wants to use it: [url]http://dl.dropbox.com/u/19301242/main.lua[/url][/QUOTE]
You have
[code]love.graphics.setColor(0,0,0)[/code]
above your image draw call. I suspect images are drawn blended with the current colour, hence your image [i]is[/i] being drawn, but blended with black.
If you put another setColor setting it to white above your image draw call, it should draw as you intend.
[QUOTE=tyranicmoron;32976946]You have
[code]love.graphics.setColor(0,0,0)[/code]
above your image draw call. I suspect images are drawn blended with the current colour, hence your image [i]is[/i] being drawn, but blended with black.
If you put another setColor setting it to white above your image draw call, it should draw as you intend.[/QUOTE]
To make that clear, call [code]love.graphics.setColor(255, 255, 255)[/code] just before drawing the image.
It works thanks!
You know I actually thought about the color effecting it. But then I was like 'that doesnt make sense why would the color effect an image.'
You'd be surprised how useful it can be.
Unless the image has no transparent backgrund, then you would see eg. a red square. A nice thing would be a white circle which you give a color in-game.
Witness my perfection.
[media]http://www.youtube.com/watch?v=RlC2AQgs4iM[/media]
[editline]26th October 2011[/editline]
By the way, that's a full physics environment, with no fake physical bodies.
okay so even though im late i decided to try and do this
one of my goals was to make the paddle be controlled by mouse movement
at first it didnt work but then it worked but now i dont understand what i did, could someone explain what i did here:
[code]function love.update(dt)
mouseX = love.mouse.getX()
paddle.x = (mouseX + paddle.x * dt - 60)
end[/code]
:v:
[QUOTE=raviool;32988405]okay so even though im late i decided to try and do this
one of my goals was to make the paddle be controlled by mouse movement
at first it didnt work but then it worked but now i dont understand what i did, could someone explain what i did here:
[code]function love.update(dt)
mouseX = love.mouse.getX()
paddle.x = (mouseX + paddle.x * dt - 60)
end[/code]
:v:[/QUOTE]
I see that you've got the x value from the mouse output but then I would have thought that you could make the value of the paddle equal to the output mouse x-value and just a numerical y-value, I don't really understand the '(mouseX + paddle.x * dt - 60)' part
also I'm trying this out but I'm trying to think of a way that when the ball reaches the boundary of the window, x = 600, then it would start incrementally decreasing, but I did it so that if x_position is not equal to 600 then it increments, but I try to make it so that if x_position does equal 600 then it starts to decrease by 1, but the problem there is that it will decrease by 1 and then be smaller than 600 so it will start increasing again.. what do?
[Media]http://www.youtube.com/watch?v=BvVwOfSKoFA[/media]
Well, this is what my first attempt at a love2d game is, figured is try something a bit different than everyone else
[QUOTE=Zard;32988573]I see that you've got the x value from the mouse output but then I would have thought that you could make the value of the paddle equal to the output mouse x-value and just a numerical y-value, I don't really understand the '(mouseX + paddle.x * dt - 60)' part
also I'm trying this out but I'm trying to think of a way that when the ball reaches the boundary of the window, x = 600, then it would start incrementally decreasing, but I did it so that if x_position is not equal to 600 then it increments, but I try to make it so that if x_position does equal 600 then it starts to decrease by 1, but the problem there is that it will decrease by 1 and then be smaller than 600 so it will start increasing again.. what do?[/QUOTE]
well the -60 makes the mouse be on the same line with the center of the paddle, the paddle is 120 wide and the paddle.x is the paddle's x-coord
[QUOTE=raviool;32988627]well the -60 makes the mouse be on the same line with the center of the paddle, the paddle is 120 wide and the paddle.x is the paddle's x-coord[/QUOTE]
ah I see, well I just made a mouse controllable paddle, this is what I did (I'm a serious beginner to coding so this might be a load of crap but it seems to work)
[code]function love.load()
love.mouse.setVisible(false)
love.graphics.setCaption("Mouse Controlled Paddle")
love.graphics.setBackgroundColor(100, 100, 100)
paddle = {
x = paddle_x,
y = paddle_y,
width = 100,
height = 25,
}
paddle_y = 450
end
--
function love.update()
paddle_x = love.mouse.getX()
if paddle_x <= 0 then paddle_x = paddle_x + 1
end
if paddle_x >= 400 then paddle_x = paddle_x - 102
end
end
--
function love.draw()
love.graphics.print("Y = ", 5, 40) -- input text
love.graphics.print("X = ", 5, 20)
local x, y = love.mouse.getPosition() -- Mouse position
love.graphics.print(y, 30, 40) -- output values of mouse
love.graphics.print(x, 30, 20)
love.graphics.setColor(255, 255, 255)
love.graphics.print("Paddle Test", 15, 575)
love.graphics.rectangle("fill", paddle_x, paddle_y, paddle.width, paddle.height)
end[/code]
[QUOTE=maximum tarp;32988619]Well, this is what my first attempt at a love2d game is, figured is try something a bit different than everyone else[/QUOTE]
Nice job *high fives u*
[media]http://www.youtube.com/watch?v=JPUllIIiB7E[/media]
im gonna attempt to use the physics stuff so i gotta remake most of it anyway, thanks for replying though.
[QUOTE=Nathax;32988684]Nice job *high fives u*
[media]http://www.youtube.com/watch?v=JPUllIIiB7E[/media][/QUOTE]
Make the ball, paddle ,text and other white stuff there have a negative color value of the background screen.
I'll give this a go, looks interesting.
[code]function love.load()
love.graphics.setMode(1280, 720, false, true, 0)
love.graphics.setCaption("Fucking Whore Game")
love.graphics.setBackgroundColor(255, 255, 255)
local font = love.graphics.newFont(12)
love.graphics.setFont(font)
love.mouse.setGrab(true)
love.mouse.setVisible(false)
world = love.physics.newWorld(0, 0, 1280, 720)
world:setGravity(0, 0)
world:setMeter(36)
objects = {}
objects.ceiling = {}
objects.ceiling.body = love.physics.newBody(world, 640, 0, 0, 0)
objects.ceiling.shape = love.physics.newRectangleShape(objects.ceiling.body, 0, 5, 1280, 10, 0)
objects.rightwall = {}
objects.rightwall.body = love.physics.newBody(world, 1280, 360, 0, 0)
objects.rightwall.shape = love.physics.newRectangleShape(objects.rightwall.body, -5, 0, 10, 720, 0)
objects.leftwall = {}
objects.leftwall.body = love.physics.newBody(world, 0, 360, 0, 0)
objects.leftwall.shape = love.physics.newRectangleShape(objects.leftwall.body, 5, 0, 10, 720, 0)
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 640, 10, 1, 0)
objects.ball.shape = love.physics.newCircleShape(objects.ball.body, 0, 0, 20)
objects.paddle = {}
objects.paddle.body = love.physics.newBody(world, 640, 685, 1000, 0)
objects.paddle.shape = love.physics.newPolygonShape(objects.paddle.body, 100,15, -100,15, -60,-15, 60,-15)
joint = love.physics.newMouseJoint(objects.paddle.body, 640, 685)
objects.ball.shape:setRestitution(1)
objects.ball.shape:setFriction(0)
objects.paddle.body:isDynamic(true)
objects.paddle.shape:setRestitution(0)
objects.paddle.shape:setFriction(0)
objects.ball.body:applyImpulse(0, 10)
objects.paddle.shape:setDensity(1000)
end
function love.keypressed(key)
if key == "escape" then
love.event.push("q")
end
end
function love.draw()
love.graphics.setColor(0, 0, 0, 255)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius(), 20)
love.graphics.polygon("fill", objects.paddle.shape:getPoints())
love.graphics.polygon("fill", objects.ceiling.shape:getPoints())
love.graphics.polygon("fill", objects.rightwall.shape:getPoints())
love.graphics.polygon("fill", objects.leftwall.shape:getPoints())
end
function love.update(dt)
bally = objects.ball.body:getY()
paddley = objects.paddle.body:getY()
if bally - 60 > paddley then
objects.ball.body:setPosition(640, 240)
objects.ball.body:setLinearVelocity(0, 0)
objects.ball.body:applyImpulse(0, 10)
end
world:update(dt)
mousex = love.mouse.getX()
paddlex = objects.paddle.body:getX()
joint:setTarget(paddlex - (paddlex-mousex)*100*dt, 685)
end[/code]
so this is my end result
[editline]27th October 2011[/editline]
the physics sure are a pain in the ass
I feel sorry for anyone attempting to make this proper while also using physics. I had to learn some light trig. as well as some Box2D specifics to do it correctly, but that experience is great.
It would also probably be worse if you didn't write your own vector class to assist with the math.
[editline]27th October 2011[/editline]
Oh you'll also need to write a small tick system if you want your simulation to be consistent.
Everyone is doing this too complicated.. Box2D, trigonometry, defining borders... All you have to do is checking if the ball is near the borders
[code]ball.x < 10[/code]
and if it hits the paddle
[code]ball.y > 550
ball.x > paddle.x-200
ball.y < paddle.x+200[/code]
Simplicity wins.
[QUOTE=Darkwater124;32994520]Everyone is doing this too complicated.. Box2D, trigonometry, defining borders... All you have to do is checking if the ball is near the borders
[code]ball.x < 10[/code]
and if it hits the paddle
[code]ball.y > 550
ball.x > paddle.x-200
ball.y < paddle.x+200[/code]
Simplicity wins.[/QUOTE]
Uh no
[QUOTE=Darkwater124;32994520]Everyone is doing this too complicated.. Box2D, trigonometry, [B]defining borders[/B]... All you have to do is checking if the ball is [B]near the borders[/B][/QUOTE]
[QUOTE=Darkwater124;32994520]Everyone is doing this too complicated.. Box2D, trigonometry, defining borders... All you have to do is checking if the ball is near the borders
[code]ball.x < 10[/code]
and if it hits the paddle
[code]ball.y > 550
ball.x > paddle.x-200
ball.y < paddle.x+200[/code]
Simplicity wins.[/QUOTE]
A year ago when I first started really getting into game programming, a few of my friends and I were trying to come up with a physics engine on an Android game, and at the beginning we just stored position as two floats, an x and a y. As things got more complicated, we ended up re-inventing a lot of vector math without knowing what vectors were. At some point we looked up vectors and taught ourselves everything from vector addition to cross products, and our code became a lot simpler and a lot cleaner.
So while your system might work for just bouncing on AABB inside another, you'll have to complicate things a lot once you start adding actual blocks. You'll end up re-inventing AABB collision checking, then you'll realize that hitting the corner of a block looks weird because you're treating the circle as a square.
Then you'll try some strange solution like seeing if any of the square's vertices are within the circle's radius and realize that doesn't work for side collisions, etc.
Instead, you could have learned the proper system from the beginning and saved a lot of time. You could have utilized either Separating Axis Theorem or, assuming all blocks will be axis-aligned, done a radius check with the nearest point following an AABB check.
Man I'm two days late and I haven't even started
I love this idea though, I hope there's more assignments soon
[QUOTE=robmaister12;33004934]A year ago when I first started really getting into game programming, a few of my friends and I were trying to come up with a physics engine on an Android game, and at the beginning we just stored position as two floats, an x and a y. As things got more complicated, we ended up re-inventing a lot of vector math without knowing what vectors were. At some point we looked up vectors and taught ourselves everything from vector addition to cross products, and our code became a lot simpler and a lot cleaner.
So while your system might work for just bouncing on AABB inside another, you'll have to complicate things a lot once you start adding actual blocks. You'll end up re-inventing AABB collision checking, then you'll realize that hitting the corner of a block looks weird because you're treating the circle as a square.
Then you'll try some strange solution like seeing if any of the square's vertices are within the circle's radius and realize that doesn't work for side collisions, etc.
Instead, you could have learned the proper system from the beginning and saved a lot of time. You could have utilized either Separating Axis Theorem or, assuming all blocks will be axis-aligned, done a radius check with the nearest point following an AABB check.[/QUOTE]
Make a table containing the blocks and then check the table on corresponding X and Y values of some points of the ball and check if there is a block there.
For something as simple as breakout, you don't really need a broadphase, and you would get tripped up with checking corresponding X and Y points of the ball against a block. It's the same issue as doing the radius check on the nearest block's nearest point. Half the time your block will move quite a ways into a block before collision is detected. Using your idea, the next logical step would be to double the amount of points on the circle so that corner collisions work. Finding that too inaccurate, you would either try and double the number of points again or work out another algorithm, when you could have just used the existing algorithm of an AABB check as if the ball were a square, then doing a radius check on the nearest point if the AABB check fails.
Marked Gwilty's work, gave him 7/10/. His program worked and was fully functional, but he had some problems with overlapping function ends, which meant that his Draw function was re-created every Think.
Next assignment will be posted on Sunday, and I will be aiming at teaching dynamic coding and using tables.
Did you give him a "Well done!" sticker with a smiley face?
If not, [url=http://www.primaryteaching.co.uk/search.php?action=search&super=0030BRN00107%7E0230BRN00124%7E0010CAT00446&branch=&wcategory=CAT00446&catdesc=Secondary%2BPre-Inked%2BStampers&treecode=TRE00004]I think you should probably invest in some extra stationary[/url]
You know it
[QUOTE=garry;33006795]You know it[/QUOTE]
So many red marks. It's just like every paper I received back in grade school.
And I just noticed,
love.graphics.circle("fill", ballx, bally, ballwidth) was your correction
but shouldn't it be:
love.graphics.circle("fill", ballx, bally, ballwidth/2) , as it takes a radius and not a diameter?
It wasn't used anywhere else, but technically I guess yes
So are you gunna scan these in then post them here? or pm them?
Sorry, you need to Log In to post a reply to this thread.