## Lua Project for High School Students

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
GreyGoldFish
Prole
Posts: 5
Joined: Tue Aug 21, 2018 6:28 pm

### Lua Project for High School Students

Hello, my name is Lucas and I'm currently working on a project to teach high school students about programming in Brazil. My professor told me that he'd like it all to be in Löve, since it seems like a good framework to make games with Lua (we are from PUC-RJ, the university where Lua was conceived at). Ever since I've taken it upon myself to learn Lua and how to properly program a game, but I'm having issues with simplifying the content for the students.

For example, I have two projects in the making at the moment. One is a Space Invaders clone, and the other one is a "shoot 'em up" style game. On neither of them, I've been able to block the player from moving off-screen, and I'm at a loss on how to make a square appear on a random point of the screen, then disappear after a few seconds.

Any help would be greatly appreciated.

Cheers,

Lucas, the struggling underling

EDIT:
This is the project's GitHub. Sorry, it's in Portuguese, but if you'd like to contribute in any way, get in touch
https://github.com/GreyGoldFish/projeto ... dio-gaming

zorg
Party member
Posts: 2731
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Lua Project for High School Students

Hi and welcome to the forums!

Without giving you any code at first, let me try to just explain a bit how you could tackle these elements you want to implement.

To block something from going outside the screen is the same as making a number be between two others (and then you do this for the other axis as well). Let's say if your screen size is 800x600, then you need to restrict the player's movement code so that the x and y coordinates are never below 0 and above 800 and 600 respectively... although a minor caveat, you do need to account for the rectangle that contains the player itself, otherwise your player image/sprite will be halfway out of the screen, since you're only restricting the object's centerpoint.

For spawning, i'd just keep a table around, that can contain objects, and add one either deliberately when the timer reaches a certain value (be it seconds, or frames, doesn't matter too much by itself), or via random chance, per-frame (you could do this in love.update); then, when the object is created, which should be a table itself, having properities like position and whatnot, it should have a "time to live" properity as well, and an update method, that's called by love.update; decreasing the time it's alive, when that value reaches (or goes past 0), you delete it.

I'm sure others can explain better than me, but maybe this can help as well.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

D0NM
Party member
Posts: 220
Joined: Mon Feb 08, 2016 10:35 am
Contact:

### Re: Lua Project for High School Students

Hi GGF.

Please, look at these tutorials https://love2d.org/wiki/Category:Tutorials
Go to YouTube, there are a lot of Love2d tutorials that cover your requests.

Use love.math.random() https://love2d.org/wiki/love.math.random
to get initial random x y coordinates for your square.
And init some variable as a time counter to remove your rectangle from the screen when the time is right.

Code: Select all

removeRectAfter = 5
-- 5 seconds

...you need something like this

Code: Select all

function love.update(dt)
removeRectAfter = removeRectAfter - dt
if removeRectAfter < 0 then
--remove your rectangle here or give it some other random x y coords. Do not forget to init removeRectAfter again
removeRectAfter = 5
x,y =  random stuff
end
end
Twitter @FaMeSoft / GP32 Free Platformer: SUPER PLUSHA
LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua

GreyGoldFish
Prole
Posts: 5
Joined: Tue Aug 21, 2018 6:28 pm

### Re: Lua Project for High School Students

Thank you for the warm welcome! That is valuable advice, thank you. I had already figured out that tables are really useful for keeping enemies around, but I didn't realize that I could add an object to the table on a timer!

By the way, if anyone's interested, this is my code for my Space Invaders clone (which is also on the GitHub page)
https://codeshare.io/GA7lr8

joshuametcalfe
Prole
Posts: 1
Joined: Wed Dec 04, 2019 8:57 am

### Re: Lua Project for High School Students

Hi! I got curious to check your education project on GitHub but unfortunately the following link: https://github.com/GreyGoldFish/projeto ... dio-gaming returns: Page not found.
Our education blog: do my homework

### Who is online

Users browsing this forum: No registered users and 8 guests