Video není dostupné.
Omlouváme se.
Learning C++ and making a GAME WITHOUT A GAME ENGINE
Vložit
- čas přidán 31. 07. 2021
- I decided to finally take the plunge and learn C++. In this video, I use the Raylib game framework to make a simple space shooter.
//Links:
Source code: github.com/Cee...
Propulsion: bit.ly/Propulsi...
Barji's tutorial: • Video
Discord: bit.ly/Chadder...
Space Shooter Environment Asset: ansimuz.itch.i...
//Videos you might enjoy:
Inspiration for this video (aside from the countless requests too): • Making a C++ Game with...
Making a game without a game engine in Python: • Making a GAME WITHOUT ...
I Put The BIGGEST Game Devs in a Boxing Match (feat. Dani): • i made a multiplayer b...
Going all in on my Rust Voxel Engine: • Going all in on my Rus...
#chadderbox
I also learnt a bit of Python and made a game without a game engine in that, check out the video here: czcams.com/video/toqxn7l5rHU/video.html
Good video tho just thought maybe u could add that to ur next project. Very cool stuff man
Python with pygame is a blast, I was wondering if it was worth it to try and learn some Lua to make some short projects with pico-8.
C++: Have you ever heard of Memory leaks?
Beginner C++ programmer: No.
C++: *Would you like to?*
And then there's seg faults...
And there's invalid and dangling pointers and references...
I think CZcams Shorts has a memory leak. Each short makes my phone run slower, till CZcams crashes, then it's better.
@@rmt3589 CZcams shorts definitely entice an "attention span leak"...
I'm learning C++ to make games as I can't run things like unity and unreal
Me too...
But i find no Tutorials on 3D game setups without Game Engine :(
@@spekulatiu openGL or vulkan C++ tutorials is the way to go if you have s old CPU openGL is the way to go and at first it may seem like vulkan is supported but later on you might find out some extensions you need are not
Me too very sad
my pc can run unity it's just it takes to much storage
@Jossiefxd same lol, I have tons of storage on my D drive but it still installs most of it to C and I'm running out.
Reject Game Engine, return to C/C++
Yes.
Great video! I am learning/using C++ now so hearing this was quite a good way of me going back over some of the basics (and I surprisingly remembered most of it!)
Your superhot project does look awesome, I wanna see how far you can go with it.
@@Chadderbox Thanks I appreciate that! (I'm wondering too X) ) - What's next for you though? Try out a new language? Using C++ more?
I'm honestly not sure. I've been eying up Haxe, but I've also been challenged regarding my dislike of Lua, but I've got no internet and it is kinda hard to do both of those options right now.
@@Chadderbox Oh yeah I saw about your internet issues, not heard of Haxe, so I'll have to Google that.
But you using Lua would be rather funny, maybe a video "proving" why your dislike of Lua is justified
I like this idea haha
Managing memory in C++ is not hard at all (unlike C), but it requires that you use the right abstractions/tools and do not use the wrong ones, e. g. do not do raw memory management at all if you can avoid it (in 99.5% of the cases you can). So it is hard for a beginner until you learn what to do and what not to do.
Collision is quite simple, and using AABB, it’s as easy as one ‘if’ statement.
// If the first rectangle is in between the second rectangle horizontally
// Meaning, that the left side of the first rectangle is to the left of the right side of the second rectangle
// and the right side of the first rectangle, is to the right of the second rectangles left side
if(x0+w0 > x1 && x0 < x1+w1 &&
// And the first rectangle is in between the second rectangle vertically
// Vice versa for the Y, same algorithm, but replace ‘x’ with ‘y’, and ‘w’ with ‘h’
y0+h0 > y0 && y0 < y1+h1) {
// Collision has occurred
return true;
}
I know you probably know how to do this, but I just wanted to show an example of AABB with comments.
Yep, AABB is awesome and it is what Raylib uses, but my problem tends to be using it on a larger scale and making something that doesn't destroy performance and is also expandable. I have never actually implemented AABB and it is pretty interesting, thanks!
@@Chadderbox Oh ok, you’re welcome :). Yeah, using it on a large scale can be very expensive. One way that I’ve seen is to check the distance between the object (in your case, just x) then if it’s close enough calculate if it’s colliding. Player width + some large enough value like 64-96 could be what you might check against for example.
It saves a bit on performance, but there are probably better ways.
Thats the basics of collission detection, but collission detection is a whole field in itself.
Quadtrees, octtrees, mid-frame collissions, detecting which sides or edges collided, between-frame collissions of rotating or morphing objects, pixel perfect collission, etc and different combination of these concepts
"I don't like the way headers work". There is now new feature in latest C++ where you can use "modules". So no more #include nighmares :). I was just looking it myself, I like the idea.
Seems interesting
Game looks cool! It’s amazing that you even made that without a game engine
Just an FYI on your code, switching out std::vector for std::list did not fix your issues, just covered them up.
What is happening is two things:
1) When you delete an Enemy, you don't remove it from the list so the update function calls update on a "Dead" enemy.
2) When you do remove objects from gameObjects, it invalidates all the iteration references causing the loop to overrun the bounds of allocated storage. The main way you could fix this is by adding a "garbage" array that stores the pointers that need to be removed, then remove them after iterating, rather than removing them on the spot.
Additionaly, if you are going to new a bunch of things, you can wrap them in std::unique_pointer or std::shared_pointer so that delete will be called automatically when it goes out of scope.
I hope you do more C++ projects in the future as this was very entertaining to watch. Good Job!
The way i fix this is by iterating *backwards* over the list. The crash probably happens when you wanna delete and remove the last spaceship in the list, but then your size became smaller and your current index is invalid. But iterate backwards and you can delete and remove at the same time and just continue on. I know it sounds weird at first but if you just spell out the code and look at it, you'll see how. I think this is a much better solution cuz no extra list to create and maintain, but you do have to remember the right order of the backwards list for important stuff.
@@DrZygote214 at first i thought it wouldnt work but 5 minutes later i realized the devils in the details. i forgot when u iterate in c++, your not just taking array[i--] ur actually iterating to the current previous object, so if index 4 removed index 3, then next it wouldnt do dostuff(array[3]) it would end up being dostuff(array[2])
if that makes any sense. ive been using c too much
The videos are short, entertaining and informative
Noice
Love it!
Thanks a lot :)
Awesome dude. Welcome to cpp gang
Thanks a lot, I think I might stay with it for a bit :)
I tried making something like this using SDL libraries some time ago. It's really difficult and requires some linear algebra. There was a tutorial online too. Don't remember the name though
fascinating content Chadderbox. I broke the thumbs up on your video. Maintain up the superior work.
Thanks a lot :)
This was really interesting. I agree about the library and headers with C++
"didnt have a problem with pointers"
"idk why vector crashes but list doesnt"
dont think you did understand them after all buddy xD
Bro your really great starting from scratch that is so nerve cracking keep it up!!! you have a bright future up ahead
I just completed my Associate of Science in Software & Database Development and had a semester of C++, I remember it being fairly easy... but that's literally all I can remember about it.😅 I can't remember a single project that I did. It was my thickest textbook too. 🤷♂️ I've spent the majority of my time with Python(for PC and Raspberry Pi) and Java in Android.
c++ is super difficult, when you start to dive in to more complex code (bad error messages is huge oversight), a quote from the creator is: "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off"
you can make something like a garbage collection in C++ : create a mem_area class and add free/delete in the destructor
Try Making a game with an arduino kit with an LCD display. It was fun. I dont even want to pull it down. It has 3 buttons(requiring 3 wires each) and the LCD display hooked up to a Breadboard and Arduino Uno😅
What I don't like about C++ is header files and build system. With Dlang I get things done faster and it's easier to maintain.
Fair enough
raylib is a game engine
Well done Chadder! :D
Thanks mate :)
what would you call the greatest video game ever (excluding that one about them things, you know, the one where you have to do something to complete the missions then when all the missions are over the game ends, you know, the game that was on steam and had music in it, you know, the one that was made by them people in that country with the government, you know, the game with the mechanics, like, you know the one where if you press buttons on your keyboard/mouse things happen, you know, excluding that one, and portal 2)
reply
Im going to make my dream games with this
How'd you learn Raylib and C++? Did you read documentation or use tutorials? I'm having troubles with it.
Read the documentation (the raylib cheatsheet is amazing), along with talking to people in the community and generally having an idea of how object oriented languages worked beforehand.
@@Chadderbox Thanks.
Hey, I would like to know if you made your own code from scratch for this project. I'm asking because I'm doing coursework for my Computer Science class in which my project is making a game in C++ - the marks for the project being your own code. If it is, could you give some tips? My own coursework is due in 2 months and i've had to switch project ideas entirely. Thank you.
As a consumer of your product(video) I think you should add more visual stuff instead of just having text that's just my thought tho
While the headline is not wrong, it can be a bit misleading - raylib is a framework but it could be considered as game/multimedia language as well.
Im learning c++ to use openGL better than java so i wouldn’t need to worry so much about performance in the future. i thought this would give some tips.. maybe on ur next one
Non-virtial destructors in non-final classes is a horrible idea
Can you make 3d game without game engine but in c++. I know you all redy uploded a video but in c.
using smart pointer is kind of a memory management for C++. shared and weak ones normally do the trick.
Interesting, I'll have to learn about them :)
@@Chadderbox def, they are bread and butter in C++,... shared pointer is the best to managed lifetime of object, while weak pointer is like an observer, that might want to interact with an object, but doesn't want to keep it alive.
you aren't a setup master without a set of cans around your neck.. I'm wearing a set now even though I don't know what I'm doing! LOL!
Fr you are very underrated.
Thanks a lot :)
nicee ;D
Can you not allocate some of that memory onto an external hard drive to make room in your ram? Genuinely asking because idk what it means to run out of memory
Well, you only have a certain amount of bytes in your RAM, so when you use them all there is no memory left, and the program can't make new things so it crashes. Windows actually does have something where it will try to move some bits of memory onto your hard drive so you can use more, but it is ridiculously slow and not a good idea.
barjis video went private
Yeah I noticed a few days ago when I tried to send it to a friend
@@Chadderbox any good replacement for my students?
I've asked Barji to see if he can unprivate it, but for now it might be worth looking at mingw-w64.org
Edit: I should add that I don't really intend for my content to be used for education since I am more of a "professional idiot" than teacher and often I don't really know what is going on.
@@Chadderbox so am I but I'm getting paid
The video should be unlisted now
No boost libraries!? What about the stl!? Well its good practice to program things from scratch if you have the time.
No boost libraries, only pain.
best of luck!
Nice video bro, could you tell me the color scheme of the code in the blue background? I found quite beautiful. +1 subscriber
Likely monokai vibrant amped, you might recognise the creator. It's only available for VSCode though.
Hi Chadderbox, I've been programming on my own for about 1.5 years and coding for me is a hobby as well as an end goal which is it get a job. From time to time, I will stop what I am doing which is learning by creating projects which is now Kotlin and Android and sometimes Python with Django. But lately I've been itching to try out C++. I tried out both C and C++ and it seems C++ is more flexible, and C is harder to create an array, I just suck maybe you can create an array with C? I don't know?
Anyways, I plan on playing around with C++ for only a couple of days maybe 2 weeks before returning to Android development with Kotlin. I need some ideas for making something. Are there any tiny projects you could recommend even if it is a console project? Google isn't being kind to me and won't give me any cool recommendations, thanks.
I love finding cool frameworks and making small games, because they often require you to understand a lot about the programming language, so you learn a lot.
Raylib has collision sysytem inbuilt
It's not great
the cake was a lie
U should have had gameplay of ur game at the end
Probably yeah
good
Can we make a game in C++ without using classes
No
@@Chadderbox Why not?
Because otherwise it would just be C
@@Chadderbox Yes 😁, however I would like to know does any of that inheritance, polymorphism, abstraction stuff ever come into use for game programming. Classes are useful but that can be done using structs and pointers.
@@arifkasim3241 Yeah, for example you could create a Monster class that's inherited by Goblin. The monster class has a virtual void attack() = 0; that allows you to take that method and change it however you want. This is a veeeeeery simple example, but you probably get the gist of it.
I did something similar and it was soooo annoying
👍
Where's the game?
Description
700th like :D
muck.
Where is course lol, another useless video