• Gwilty's Programming Assignments #1
    355 replies, posted
[QUOTE=Paulendy;32905466]Seeing people making all these breakout clones makes me wish I knew something about Lua...[/QUOTE] Perfect time to learn. Gwilty knows no programming at all. He's starting at the ground floor.
[QUOTE=garry;32906915]Perfect time to learn. Gwilty knows no programming at all. He's starting at the ground floor.[/QUOTE] The math part is hard for me though, so I don't really think starting off on pong was a good idea.
[QUOTE=garry;32906915]Perfect time to learn. Gwilty knows no programming at all. He's starting at the ground floor.[/QUOTE] I'm currently doing a programming unit as part of my course at college, but it's in VB (yeah... I know) and Lua seems incredibly different. Also I have no idea where to start with learning this stuff.
Never coded anything before, yet managed to make a paddle follow the Y axis of the mouse and stay on screen, as well as draw a circle for the ball, which turned out to be easier than I expected. But I have no idea at all on how to make the ball move :suicide:
Every single time I make use of any sort of trigonometry it ends up being a complete mess that keeps flipping out :(
[QUOTE=Murkrow;32907585]Every single time I make use of any sort of trigonometry it ends up being a complete mess that keeps flipping out :([/QUOTE] My shakin bacun titlescreen using trig
[QUOTE=toaster468;32906981]The math part is hard for me though, so I don't really think starting off on pong was a good idea.[/QUOTE] What are you having trouble with? [editline]22nd October 2011[/editline] [QUOTE=Paulendy;32907093]I'm currently doing a programming unit as part of my course at college, but it's in VB (yeah... I know) and Lua seems incredibly different. Also I have no idea where to start with learning this stuff.[/QUOTE] Knowing how to teach yourself is a skill you need to learn. It's not hard. Go to Love's wiki - follow tutorials. Lua is different but all programming language fundamentals are pretty much the same. Once you learn the way to do stuff it's rare you'll find a language where you do it much different.
[media]http://www.youtube.com/watch?v=uuM8K13IxOU[/media]
I'm still not quite sure on how to make the ball move freely.
You basically store the ball position like this x = 100 y = 100 then every frame, if you want the ball to move down y = y + 1 etc.
Also IMO you should use dt when moving paddles and balls around: "First of all you will see that this function accepts a parameter called dt (an abbreviation of "delta-time") which represents the amount of time which has passed since this function was last called. It is in seconds, but because of the speed of todays processors is usually smaller than 1 (values like 0.01 are common). [b]We are using this value to move the hamster ball at the same speed, no matter how fast the player's computer is.[/b]" [url]http://love2d.org/wiki/Tutorial:Hamster_Ball[/url] so for example moving the ball in my game: [lua] bx = bx + speedBall * dt --where bx is the x position of the ball, so this increases the x value, thus moving it to the right [/lua] However this creates x values that have several decimals, so when using an if statement to check if the ball is moving too far to the right i do this: [lua] if (math.floor(bx) >= 790) then Xp = 0 -- this variable is just to determine whether the X value of the ball will increase or decrease end [/lua] this will make an x value of for example 550.12364512345 look like 550. Full source: [url]http://pastebin.com/e7kkG8iN[/url]
I decided to make mine with MicroLua for the Nintendo DS. [video=youtube;i-8qz3TkMNs]http://www.youtube.com/watch?v=i-8qz3TkMNs[/video] And here's an emulator screenshot because oh dear lord my webcam is shitty. [img]http://dl.dropbox.com/u/15665674/%21BreakoutDeluxe3000.png[/img] And the source: [url=https://www.dropbox.com/s/3dw0ju77dhrgmim/not_breakout.zip]!Breakout Deluxe 3000[/url] Edit: I should probably link to MicroLua I guess :v: MicroLua is here: [url]http://code.google.com/p/microlua/[/url] The MicroLua Simulator is here: [url]http://microlua.xooit.fr/t180-Micro-Lua-Simulator.htm[/url] As I said in the video, you'll need a flashcart of some kind to actually run it on a DS.
Made an entry! Bricks are loaded from a spritesheet, as is the paddle. Also has motion blur! [img]http://i.imgur.com/aDRIh.png[/img] The rectangles are the collision rects, for tweaking Packed executable download: [URL="http://www.filedropper.com/showdownload.php/breakout_2"]Here[/URL] .love download: [URL="http://www.filedropper.com/showdownload.php/breakout_3"]Here[/URL]
[QUOTE=FlashStock;32908448]Also IMO you should use dt when moving paddles and balls around: "First of all you will see that this function accepts a parameter called dt (an abbreviation of "delta-time") which represents the amount of time which has passed since this function was last called. It is in seconds, but because of the speed of todays processors is usually smaller than 1 (values like 0.01 are common). [b]We are using this value to move the hamster ball at the same speed, no matter how fast the player's computer is.[/b]" [url]http://love2d.org/wiki/Tutorial:Hamster_Ball[/url] so for example moving the ball in my game: [lua] bx = bx + speedBall * dt --where bx is the x position of the ball, so this increases the x value, thus moving it to the right [/lua] However this creates x values that have several decimals, so when using an if statement to check if the ball is moving too far to the right i do this: [lua] if (math.floor(bx) >= 790) then Xp = 0 -- this variable is just to determine whether the X value of the ball will increase or decrease end [/lua] this will make an x value of for example 550.12364512345 look like 550. Full source: [url]http://pastebin.com/e7kkG8iN[/url][/QUOTE] delta-time is in seconds per frame, its the opposite of FPS. So when you multiple this by a speed you get (pixels per second) x (seconds per frame) px/s * s/f The seconds cancel giving pixels per frame px/f ie the amount a object should move for each frame.
I just have one tiny question, what the hell do I start on first? EDIT: Wow, this is hard. I know nothing about coding and within 2 hours I got the paddle and ball pictures done and then just a few lines of code to make the game launch. I'm hung up on how I change the background color. This is what I have for it so far: [QUOTE]function r, g, b = love.graphics.getBackgroundColor( ) number_r (255) number_g (255) number_b (255) end [/QUOTE] I got that function line from this: [url]http://love2d.org/wiki/love.graphics.getBackgroundColor[/url]
[QUOTE=All0utWar;32917819]I just have on tiny question, what the hell do I start on first?[/QUOTE] Anything.
If anyone has specific questions about LÖVE feel free to come to the IRC channel #love on freenode. A lot of the regulars live in Europe though, so don't expect a lively crowd at this time of night.
Dicking around, progress from WAYWO: [QUOTE=amcfaggot;32919000][media]http://www.youtube.com/watch?v=RO5ZI9Y_XSM[/media] Wrote all the core game logic from scratch, and factory stuff in about an hour. Then I realized my gravity was backwards :v: I'm so used to negative gravity implying downwards force. [editline]22nd October 2011[/editline] [media]http://www.youtube.com/watch?v=-sGNHUkXWtk[/media] Okay, what the fuck Box2D. [editline]22nd October 2011[/editline] [media]http://www.youtube.com/watch?v=EsvswIw3Jg0[/media] Nailed it! Sorry for the content spam. :s I hope this is interesting enough to be shown[/QUOTE] Proof of concept stuff for my weapons. Extra credit perhaps?
to set the background colour, you use love.graphics.setBackgroundColor(r,g,b)
I attempted this a few days back, but ended up ditching the project as I couldn't lock the frame rate to 24 fps, or prevent the game's window from popping up and then quickly closing if I wanted to abort the game loading due to a non 9:4 aspect ratio.
I think I'm pretty much done with mine. [img]http://www.peniscorp.com/stuff/Breakout-2011-10-23_12.45.31.png[/img] [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.
[img]http://dl.dropbox.com/u/2692549/lmao.png[/img] Mines going well
I once made pong on a microcontroller. Does that count? It's programmed in C. [media]http://www.youtube.com/watch?v=X7LrsQq80ZI[/media] (sorry, the camera somehow didn't pick up the ball) Here you can see the setup: [media]http://www.youtube.com/watch?v=E9nxC9Ugly8[/media] (It's in a plastic box because I was taking it to school, randomly challenging people to a game. They were all amazed)
If I want to learn Lua where should I go? I know nothing about it.
[QUOTE=Mr.T;32920938]If I want to learn Lua where should I go? I know nothing about it.[/QUOTE] Have a free book: [url]http://www.lua.org/pil/[/url]
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.
[img]http://www.1337upload.net/files/18Capture.PNG[/img] [url]http://www.1337upload.net/files/Breakout.zip[/url] You'll need this to play: [url]http://www.microsoft.com/download/en/details.aspx?id=20914[/url] Done in xna. I only started xna yesterday so I'm pretty happy. [editline]23rd October 2011[/editline] Beat my high score of 33 guys :D
Finaly! After about 9 hours of work I made something that looks like a game. [IMG]http://dl.dropbox.com/u/35800658/ball%20game.png[/IMG] Now I only need to make it look better.
I've got a paddle that moves from side to side but I can't figure out the ball physics.
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)
Sorry, you need to Log In to post a reply to this thread.