Obstacles in game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
konrmat171
Prole
Posts: 4
Joined: Sun Dec 20, 2020 4:28 pm

Obstacles in game

Post by konrmat171 »

Hi everyone
I'm new here and I'm supposed to write a flappy birds game or temple run game. I'm supposed to be responsible for the piece of code that generates obstacles and moves them towards the hero and the background. Is there anyone here who can help me with this task because I don't even know how to start?
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Obstacles in game

Post by pgimeno »

Hi, welcome to the forums. Do you have any background in Lua or in any other programming language?
konrmat171
Prole
Posts: 4
Joined: Sun Dec 20, 2020 4:28 pm

Re: Obstacles in game

Post by konrmat171 »

Yes i made simple paralax system with two img (one for background and another to ground). Now I try to create two types of obstacles (for example, jump barrels and crouch posts).
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Obstacles in game

Post by pgimeno »

OK, then I suggest you use axis-aligned rectangles as the collision shape, because these are the simplest to check against. For a Dinosaur Game type of game, you only need collision detection, not collision response, which simplifies things for you.

Every time you need to create a new obstacle, you need to add the corresponding collision rectangle.

There are several ways to check for collision; the simplest one is to use the Separating Axis Theorem, which when applied to convex polygons (like rectangles), says that two polygons overlap only if none of their edges leaves one polygon on one side of the edge and the other polygon on the other side. For axis-aligned rectangles, that condition translates to this code: https://love2d.org/wiki/BoundingBox.lua

Every time you remove an obstacle (because it goes off the screen), you also remove the collision rectangle.

See if that helps. If not, feel free to ask for clarification you need.
konrmat171
Prole
Posts: 4
Joined: Sun Dec 20, 2020 4:28 pm

Re: Obstacles in game

Post by konrmat171 »

Thank you very much, it will be of great help in the future, but I am currently having trouble drawing random obstacle. I don't know how to write an algorithm that creates a obstacle that goes in my direction and crate new obstacle every few seconds.
RNavega
Party member
Posts: 246
Joined: Sun Aug 16, 2020 1:28 pm

Re: Obstacles in game

Post by RNavega »

konrmat171 wrote: Thu Dec 24, 2020 2:41 pm I am currently having trouble drawing random obstacle. I don't know how to write an algorithm that creates a obstacle that goes in my direction and crate new obstacle every few seconds.
Hi. What have you tried already, can you show some code?

The things you're asking are very simple, so maybe it's better to follow a "flappybird clone" tutorial instead until you get more experience. Here's a good one, using LÖVE: https://simplegametutorials.github.io/love/bird/

EDIT: When following tutorials for LÖVE, note that they might be using an older version, so a function name or usage might be different. If you find these differences then you need to go to the library documentation and find the updated function and how to use it.

EDIT 2: you can find more LÖVE tutorials in here: https://love2d.org/wiki/Category:Tutorials
Last edited by RNavega on Fri Dec 25, 2020 1:02 pm, edited 1 time in total.
RNavega
Party member
Posts: 246
Joined: Sun Aug 16, 2020 1:28 pm

Re: Obstacles in game

Post by RNavega »

Also, if you imagine yourself making more complex games in the future, it'd be interesting to invest some time in making simpler games first that will give you an easier challenge in learning different techniques, design patterns and such.

There are two cool articles talking about this, not specifically about LÖVE, just in general no matter what language/libraries you're using:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 89 guests