Hello and Good Day!
I am brand new to Love, as in, tonight I am building my first simple game, ever. It is attached. I am trying just to jump in and build something. I have a background in PHP and Javascript. I found a pong game online and I want to adapt it to be a breakout game.
I have 3 little questions and 1 big one.
1. How can I get the console to print out a variable and a string. Like in Javascript I want:
> console.log( 'game.timerLimitCycles = ' + game.timerLimitCycles );
When I do the equivalent in Love I get errors, so I am stuck with just
print (game.timerLimitCycles)
2. Right now my game is just a paddle and ball, with the ball progressively speeding up as it bounces around the screen. But sometimes it seems to jump/hiccup a little. Is this just my machine? Or possibly in my head? If it is a real issue, is there something I can do about it?
3. I know there are three main functions (load, draw and update). Is it normal to stick my own functions "in between" these ones? It feels funny to me doing so? Maybe my "startGame()" and "spawnBall()" should be part of "love.load()"? Or somewhere else?
4. Finally, here is my big question: How should I do the bricks? I am just going to plow ahead after I write this, but I would love some advice from more experienced people. I figure I can just have a loop that writes out 30 or so rectangles, and keep a note of their position (upper left x and y), and then just do some pseudo "collision detection" (like I did the paddle and ball) for all 30 of them, and as they get hit, one by one decrease brick.totalNum by one until I get to 0. But this is going to call upon some loops and classes that I am unfamilair with as of yet? Also, it seems a bit inefficient to test the locations of 30 objects over and over? But maybe that is the only way?
Thanks for any insights anyone can give me!
Help with my Breakout Game
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 4
- Joined: Mon Oct 12, 2015 5:22 pm
Help with my Breakout Game
- Attachments
-
breakout.love
- (1.88 KiB) Downloaded 302 times
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Help with my Breakout Game
In lua we have a specific concat operator which is "..". You can concat a string by doing
For the bricks you can store them an array.(a lua table with indexes starting from one) you can then use table.remove when you detect a collision.
Hiccups and such, may be due to frame rate. It advised to use dt in any math to help make it run smooth indifferent to frame rate.
And you can use other files for your functions. And just load them by using require.
This tutorial explains how to do something similar to what your doing. It would probably be helpful to read.
http://www.headchant.com/2010/11/27/lov ... -must-die/
Code: Select all
stringVar.." A string literal"
Hiccups and such, may be due to frame rate. It advised to use dt in any math to help make it run smooth indifferent to frame rate.
And you can use other files for your functions. And just load them by using require.
This tutorial explains how to do something similar to what your doing. It would probably be helpful to read.
http://www.headchant.com/2010/11/27/lov ... -must-die/
-
- Prole
- Posts: 4
- Joined: Mon Oct 12, 2015 5:22 pm
Re: Help with my Breakout Game
Thanks for the reply! The link you sent was helpful!
One other thing: How can I draw something only one time? For instance, the bricks are stationary, so I never need to update them once they are on screen (except to remove them). But love.draw() draws things over and over.
I tried to set a flag to do it only once, but it does not work:
Thanks! I really appreciate any help I can get. ![Smile :)](./images/smilies/ms-smile.png)
One other thing: How can I draw something only one time? For instance, the bricks are stationary, so I never need to update them once they are on screen (except to remove them). But love.draw() draws things over and over.
I tried to set a flag to do it only once, but it does not work:
Code: Select all
function love.draw()
if bricks.haveBeenDrawnFlag == false then
for i,v in ipairs(bricks) do
print (i)
love.graphics.rectangle("fill", v.x, v.y, v.width, v.height)
bricks.haveBeenDrawnFlag = true
end
end
end
![Smile :)](./images/smilies/ms-smile.png)
Re: Help with my Breakout Game
You need to draw them over and over. An alternative would be using a [wiki]SpriteBatch[/wiki] or a [wiki]Canvas[/wiki], if you need to speed things up.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
-
- Prole
- Posts: 4
- Joined: Mon Oct 12, 2015 5:22 pm
Re: Help with my Breakout Game
I am attaching the latest version of my breakout game. Thanks to the people here that have helped me figure things out. ![Smile :)](./images/smilies/ms-smile.png)
I have added a background image, and have 2 questions about it:
1. Why does it look crappy and "washed out"? (If you open the same image in a browser, or Photoshop, it is nice and clear and colorful. I tried bith Jpg and Png with same results...)
2. Should I be concerned about it being redrawn over and over? (Similar to what I asked about re-drawing the bricks in an earlier question)
It seems strange to me to re-draw things, especially complex things, when they only need to be done once? But maybe I am missing something? Perhaps the same way Lua/Love2d automatically does garbage collection, it also can figure out when an image can just stay put so it doesn't use resources redrawing things unnecessarily?
![Smile :)](./images/smilies/ms-smile.png)
I have added a background image, and have 2 questions about it:
1. Why does it look crappy and "washed out"? (If you open the same image in a browser, or Photoshop, it is nice and clear and colorful. I tried bith Jpg and Png with same results...)
2. Should I be concerned about it being redrawn over and over? (Similar to what I asked about re-drawing the bricks in an earlier question)
It seems strange to me to re-draw things, especially complex things, when they only need to be done once? But maybe I am missing something? Perhaps the same way Lua/Love2d automatically does garbage collection, it also can figure out when an image can just stay put so it doesn't use resources redrawing things unnecessarily?
- Attachments
-
breakout_5d.love
- (422.55 KiB) Downloaded 96 times
Re: Help with my Breakout Game
I like to include this at the end of the update loop for more resource needy games:
Code: Select all
collectgarbage("collect")
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest