Coding Challenge #72: Frogger Refactoring

preview_player
Показать описание


Other Parts of this Challenge:

References:

Videos:

Related Coding Challenges:

Timestamps:
0:00 Today's objective: refactor the code
3:15 Create a Lane class
4:15 Rename logs and cars as Obstacles
6:56 Make an array of lanes
22:35 Use constructor overloading to add color to the lane
24:30 Add game play back
26:03 Use type to indicate whether an obstacle is a car or log
28:43 Use type to refactor the check function
31:44 Detach the frog when it moves
32:32 Use the lane index to register which lane the frog is in
35:23 Conclusion and ways to contribute

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

#gamemechanics #froggeratari #inheritance #processing
Рекомендации по теме
Комментарии
Автор

I have no idea of much programming but I could understand almost everything. Your teaching is amazing!!!

bamkparto
Автор

This is actually pretty interesting and cool! Can you please make some more refactoring code? ^^

henrikstorch
Автор

Interesting thing about your videos is that when you advance through coding challenges, you will reach a stage where you will catch the error you are making before you catch it by running and that makes me happy :)

sreejithpro
Автор

This is so cool to watch. I love to see a challange of my favorite C64 game * Boulderdash *.

niels
Автор

I think it would be a good idea just to pass in a type, lane number, and number of obstacles.
Odd / Even lane index = positive or negative speed.
Number of obstacles, fewer = bigger obstacles, more obstacles = smaller obstacles
Spacing based on number of obstacles.
In a loop through indexes: Type based on index, index 0 & max_index = safe zone, and max_index / 2 = safe zone. max_index / 2 could also indicate the switch from car lane to log lane.

xetop
Автор

I'm interested in seeing you do this again in JavaScript! :)

tomburris
Автор

PRO grammers are sure to think through these things much faster/efficiently because of their experience but I bet zero of them think your an idiot....Your videos are attractive to me because I know nearly nothing about coding languages and really seems like (in my 45 year old age) I can absorb and learn along with YOU perfectly.

gqoniefh
Автор

I haven't watched the whole video yet, but I strongly feel that when the frog jumps on a log, or out of a log, its x position should be corrected, so it wont be out of the grid.

Great video, love the channel :)

ricardolima
Автор

Hi Dan!

As always thanks for this video series.

I thought it might be useful to have the frog 'snap' back to the grid when hopping off the logs, but I don't have Github so I'll share it here - it's a function to go in the Frog object, called on a move (best place I could find for it) :

void snap() {
float a = grid - (frog.x % grid);
float b = frog.x % grid;
if (a < b) {
frog.x += a;
} else if (a > b) {
frog.x -= b;
} else if (a == b) {
if (random(1) > 0.5) {
frog.x += a;
} else {
frog.x -= b;
}
}
}

It just uses the frog's x position and some modulus operations to find out which 'cell' it should fit into, i.e. if it's between two 'cells', it finds the relative distances and snaps to the correct one by setting the frog's x equal to the cells (by adding or subtracting the /other/ distance).

marksherriff
Автор

I would have first decided the number of lanes (11 in this case) you need. Based on that number and the window size you can calculate "grid". That way if you change the window size or add a lane, the whole thing scales automatically.

grid = height/lanes.length;

Anyway, thanks for the videos, Dan.

joostvanrens
Автор

The coding train is all about making the program then refactoring it in a separate video.

asston
Автор

An alternative, and possibly more flexible, way to check which Lane the Frog is currently occupying would be to check whether they intersect. That way you could have lanes which vary in width and not have to include complicated arithmetic in the Frog code.

PhilBoswell
Автор

it is kind of ironic the computer you use to remake the game is a zillion times faster and bigger memory wise and graphically its a zillion times in reverse of the 8 bit original :) but it really makes you appreciate how much they got done with 8 bits and practically no sound ya?

midnightrizer
Автор

Refactoring to javascript would basically be a search and replace 😅

dave
Автор

ps time is 15 min. ive learned how to code from you thanks!

hdndhdbxhhfbxgdggdbxhdb
Автор

Thanks for the video :) might it be an idea to read the setup values from a file? You could then have different level files which configure the program. (p.s watched until the end!)

FoxSurvival
Автор

I've got a challenge for you, how about a 3d fracturing object? When it falls, it breaks into pieces and depending on the impact, it breaks dynamically (:

jesusrwc
Автор

"and actually, I don't need to have this argument here" sounds like something a married couple that doesn't get along really well would say.

sinom
Автор

I like that sunset animation at the end. Is that perlin noise for the terrain?

camelcase
Автор

how would you add images and make it work with a Arduino joystick?

chasestevens
welcome to shbcf.ru