• Gwilty's Programming Assignments #2
    191 replies, posted
In the last assignment you learnt a little about game programming. • The draw loop • The think loop • Input (keyboard/mouse) • Collision logic It's bonfire night, so this time we're going to be [B]making a firework simulator[/B] using [URL="http://love2d.org/"]Love[/URL]. • Clicking on a screen should fire a firework • Firework explodes, multiple particles spray from the click point • Object Orientated: Each firework particle must draw itself (see [URL="http://lua-users.org/wiki/SimpleLuaClasses"]Simple Lua Classes[/URL] - This is a big step so ask for a talk about it if you get stuck!) • Object Orientated: Each firework particle must have its own think • Can fire multiple fireworks at the same time • Do not use Love's inbuilt particle system Extra Credit • Sounds • Looks pretty • Rocket firing up, and then exploding at the point that we clicked • Any other self explored coolness Deadline • Friday 4th November 2011
Sounds fun, good luck all
You better punish Gwilty if he's late this time.
I learnt so much off the last one, gonna be fun getting stuck in on this one
[QUOTE=Zard;33040810]I learnt so much off the last one, gonna be fun getting stuck in on this one[/QUOTE] I feel the same way. I have been thinking about how I'm going to do this for the longest time now.
Okay, so I managed to make particles appear at the mouse's position, but they all fly off in the same direction because they're using the same random speed variables, and I don't know how to make it so each instance of Particle has it's own speed.
[QUOTE=ElTacoLad;33041273]Okay, so I managed to make particles appear at the mouse's position, but they all fly off in the same direction because they're using the same random speed variables, and I don't know how to make it so each instance of Particle has it's own speed.[/QUOTE] setSpread(360) or whatever you want.
I don't think he's using the built-in particle system. [editline]30th October 2011[/editline] I don't think garry means for that to be used anyway.
[QUOTE=BlkDucky;33041403]I don't think he's using the built-in particle system. [editline]30th October 2011[/editline] I don't think garry means for that to be used anyway.[/QUOTE] Now I re-read it it makes sense :v:
There's a built in particle system?
Yeah but judging by what garry said he doesn't want us to use it. Then I looked back at your problem and realised I have the same one :v:
[QUOTE=ElTacoLad;33041420]There's a built in particle system?[/QUOTE] [url]http://love2d.org/wiki/ParticleSystem[/url] Check the example .love files you probably got when you downloaded LÖVE if you want to know how to use it.
I changed the assignment, didn't realize Love had a particle system
[QUOTE=ElTacoLad;33041273]Okay, so I managed to make particles appear at the mouse's position, but they all fly off in the same direction because they're using the same random speed variables, and I don't know how to make it so each instance of Particle has it's own speed.[/QUOTE] this isn't exactly what you're asking for but you can kind of see what I mean, as you did in the last assignment you make the movement increment on a certain condition, you do the same here except you assign an angle to each of the particles, spread out evenly of course, and you use simple trig functions to work out the x increments and y increments :smile: [code]function love.load() love.mouse.setVisible(false) particles = {}; for i = 1, 11 do particles[i] = { vel_x = 2, vel_y = 2, pos_x = 400, pos_y = 400, angle = 0, angle_d = 0 } end particles[1].angle_d = 36 particles[2].angle_d = 72 particles[3].angle_d = 108 particles[4].angle_d = 144 particles[5].angle_d = 180 particles[6].angle_d = 216 particles[7].angle_d = 252 particles[8].angle_d = 288 particles[9].angle_d = 324 particles[10].angle_d = 360 particles[11].angle_d = 0 hyp = 2 end function love.update() mouse_x, mouse_y = love.mouse.getPosition() for i = 1, #particles do if love.mouse.isDown("l") then particles[i].pos_x = particles[i].pos_x + (hyp * math.cos(particles[i].angle_d)) else particles[i].pos_x = mouse_x end if love.mouse.isDown("l") then particles[i].pos_y = particles[i].pos_y + (hyp * math.sin(particles[i].angle_d)) else particles[i].pos_y = mouse_y end end end function love.draw() for i = 1, #particles do love.graphics.print("x", particles[i].pos_x, particles[i].pos_y) end end[/code]
[lua] for i = 1, #particles do love.graphics.print("x", particles[i].pos_x, particles[i].pos_y) end[/lua] Faster and nicer to iterate over them with [lua]for i, v in ipairs(particles) do love.graphics.print("x", v.pos_x, v.pos_y) end [/lua]
is the 'v in ipairs' basically saying that for all values in the table (table) do - stuff? I've seen it used before but the way I did it seemed to make more sense for my own sake
[QUOTE=Zard;33041942]is the 'v in ipairs' basically saying that for all values in the table (table) do - stuff?[/QUOTE] Yes.
What I wouldn't do to have the patience to teach myself some lua [editline]October 30 2011[/editline] Why dumb? I would really like to but I have no experience whatsoever
Holy shit, I didn't even get the last assignment done. I actually quit because I couldn't figure out how to make the ball have gravity, make it bounce or add collisions.
[QUOTE=All0utWar;33042631]Holy shit, I didn't even get the last assignment done. I actually quit because I couldn't figure out how to make the ball have gravity, make it bounce or add collisions.[/QUOTE] bouncing would be when the x or y value of the ball equals the x or y value of the wall or collision object then the velocity = - velocity, so it bounces the opposite way, the same goes for collisions.. gravity would be that when your velocity is negative ( > 0 ), and therefore the ball is rising, then a gravity variable could equal 0.9 or something, you'd then times your y-increment variable, which is getting your ball to move upwards or downwards, by that and you'd have a basic kind of gravity as when your ball is moving up the y-speed is continuously decreasing, you could do the same for it moving downwards too
[QUOTE=garry;33039800] • Do not use Love's inbuilt particle system[/QUOTE] This is like driving a car, but restricting yourself not to use the brake.
Can I perhaps have a really basic example of the classes being used in LOVE where I dunno you click and it creates the image where you click, for however many times you want. I'm sat here with 2 pieces of paper full of scribbles and I just can't get it to work how I want it too :v:. -Edit- Actually wait no scrap that I managed to get it working ho-ray.
[QUOTE=sim642;33043044]This is like driving a car, but restricting yourself not to use the brake.[/QUOTE] No, it's like making your own cheeseburger instead of buying one from a fast food chain. You can put whatever you want on it, and cook it just the way you want it. In the end, though, it's going to end up being more [url=http://en.wikipedia.org/wiki/Computational_expense]expensive.[/url] The importance to this programming lesson is learning how to cook.
[QUOTE=icemaz;33043303]Can I perhaps have a really basic example of the classes being used in LOVE where I dunno you click and it creates the image where you click, for however many times you want. I'm sat here with 2 pieces of paper full of scribbles and I just can't get it to work how I want it too :v:. -Edit- Actually wait no scrap that I managed to get it working ho-ray.[/QUOTE] The basic idea is that you'd have a global table full of particles (tables/classes). Then each draw and think you'd call a function on it. To add a new particle you'd just add to the end of the table. When the particle dies you remove from the table.
[video=youtube;PNLObEya2bc]http://www.youtube.com/watch?v=PNLObEya2bc[/video] This is fun. :eng101:
I've got my table full of fireworks themselves, but when I click to launch them it either only ever starts 1 off or does them all at once through the same co-ordinates, how would I go about it so that every time I click a different one starts moving upwards?
Finally finished my entry. [video=youtube;Fq8mWeITOvI]http://www.youtube.com/watch?v=Fq8mWeITOvI[/video] Features: • Clicking on screen to fire a firework • Firework explodes, multiple particles spray from the click point • Object Orientated: Each firework particle draws itself • Object Orientated: Each firework particle has its own think • Can fire multiple fireworks at the same time • Does not use Love's inbuilt particle system • Sounds • Looks pretty • Rocket fires up, and then explodes at the point that was clicked Download: [url]http://www.mediafire.com/?59y2l7rabygm9i0[/url]
[media]http://www.youtube.com/watch?v=oRxv_HaKa-A[/media] eh
I kind of want a Vector library/class, and I know gmod has a good one, but I can't find the source for it. Is it defined in lua or as a module (C++)?
[QUOTE=bobthe2lol;33047448]I kind of want a Vector library/class, and I know gmod has a good one, but I can't find the source for it. Is it defined in lua or as a module (C++)?[/QUOTE] I wouldn't recommend it for learning purposes, as you would learn more from writing your own, but: [url]http://love2d.org/wiki/hump[/url]
Sorry, you need to Log In to post a reply to this thread.