We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am considering make a simple 2D game based on this video https://m.youtube.com/watch?v=-3ODe9mqoDE
However I can.t think of how to implement the situation when some bike crosses the border. I mean is there a getPixelColour function? Or am I supposed to use a huuuuuge array against which I will be checking the coordinates of the bike?
Answers
https://processing.org/reference/get_.html
There are two ways to get destroyed
1) Hit the border of the game area
2) Hit any path created by a light bike
If the game area is the same size as the screen you can simply test the bike position against the display (x < 0 or x >= width or y < 0 or y >= height then the bike has left the game area).
If smaller than the display you can use use get() to get the pixel colour and based on that decide what action to do.
You could use a huge array but I wouldn't recommend it.
Hmmm. But to make the border stay i will have to stop using background. However, if I do this then thre bikes will trail shapes as well...
If you want to use background you would have to take into account the trail of each bike. I would do this by having three (same number as the bikes) arrays to store each point at which the movement direction changes. By doing that, after you use background you could plot the trails of the bikes using a simple for loop.
Not true you simply draw the entire display every frame e.g.
OK just had a ah-ha moment, are you talking about storing the bike paths in an array?
Yes, it seems my wording confused you. Sorry. I was thinking of using an array to store the bike paths.
It is not very clear how you intend to change the direction of each bike. But given that you have stored the position where each bike has changed its direction, here is a code to redesign the background and trails.
I would use an ArrayList of PVectors for the bike path. A new point will be added for every turn.
Have you used classes before?
Yes, i thought of putting all these arrayLists into bike classes.
I would recommend that. The Bike class should be autonomous which will make it easier to have multiple bikes at the same time.
isn't that just snake game without the food? ;-)
code not by me
People you have to stop this:) I want to write the code by myself)) Now i will be too tempted to look at the provided ones.
Only joking))
As to the question, well it IS a snake, but the snake that I have on my Tetris has a limited number of positions - pixels, it means the maximum length is limited by the resolution of the screen.
PC screens are very detailed, so the array might grow very quickly. In the code above, the coder works around this problem by drawing the tail as a number of squares. "Pixelizing" so to say.
Also, I was thinking of not limiting the player to the screen. It means the array will grow even quicker, and I was afraid it would eat much memory.
I might be wrong though.
It is not the same as the snake game because the snake length is fixed even though it increases with eating. The light cycle trail never decreses until the bike is destroyed and then the whole cycle trail dissappears. The data structures for the two scenarios would be very different.
If you want the cycle arena bigger than the screen and have the ability to scroll and zoom then you should avoid using the pixel colour to represent type of data e.g. bike, trail, boundary walls etc. I would avoid using a 2D array to specify the arena as it is unwieldy.