Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Re: C++ Progress ish
 Post Posted: May 31st, 2017, 6:54 pm 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
Added some sound fx. It took me longer than I expected because I didn't know what to look for. I hope these sounds kind of sort of match ish. There was also the bad wave format thing which can easily be solved with audicity, as Chili said.
I think I'm going to start intermediate now. See you soon. Thanks for help.


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 1st, 2017, 5:39 pm 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
Is it not possible to work with an array without passing in the length? When I do this sizeof(ptr) returns sizeof(ptr[0]) not the size of the whole array. So i will go from 0 to 4/4-1 and sum(v) will return v[0]. Am I missing something?

Code:
#include <iostream>
int sum(int ptr[]);
int main()
{
   int v[3] = { 5, 2, 10 };
   std::cout << sum(v);
   std::cout << std::endl;
   system("pause");
    return 0;
}

int sum(int ptr[])
{
   int s = 0;
   for (int i = 0; i < sizeof(ptr) / sizeof(ptr[0]); i++)
   {
      s += ptr[i];
   }
   return s;
}


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 2nd, 2017, 1:13 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3402
Location: Japan
Your code is not correct. You can't pass an array in like that and have its status as a C-array preserved.

These functions are all exactly the same:

Code:
#include <iostream>
#include <conio.h>

void thing( int x[10] )
{
 x++;
 std::cout << sizeof( x ) << std::endl;
}

void thing2( int x[] )
{
 x++;
 std::cout << sizeof( x ) << std::endl;
}

void thing3( int* x )
{
 x++;
 std::cout << sizeof( x ) << std::endl;
}

int main()
{
 int arr[10];
 int arr2[7];

 thing( arr );
 thing2( arr );
 thing3( arr );

 thing( arr2 );
 thing2( arr2 );
 thing3( arr2 );

 while( !_kbhit() );
 return 0;
}


In C jargon, we say that the array "decays" into a pointer.

For this reason I use the pointer syntax because it is indicative of what is actually going on. And it is what the std library functions use (for the most part at least).

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 2nd, 2017, 3:34 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2711
Location: Oklahoma, United States
Yeah, getting sizeof(ptr) would just return the size of a pointer, 4 bytes on x86 and 8 bytes on x64 because of what chili said about the decay to pointer. Once the array is passed to function, the compiler no longer knows the size of the array being passed in inside the function.

I know chili is covering C style arrays right now, but the standard library has an array container that works almost like a standard vector.
Code:
#include <array>
#include <iostream>
#include <conio.h>

int Sum( const std::array< int, 10 > &Arr )
{
    int val = 0;
    for(const int num : Arr)
    {
        val += num;
    }
    return val;
}

int main()
{
    const std::array<int, 10> arr = {{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, (9}, {10}};
    const int sum = Sum(arr);
    std::cout << "The sum of the array equals: " << sum << std::enl;
    while(!_kbhit());
    return 0;
}



You might have notices the fact you are hard coding the size of the accepted array into the function signature with this though, the only way around this is using templates or a lambda. Chili may cover lambdas later, but not sure about templates.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 3rd, 2017, 4:47 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3402
Location: Japan
Just checked out the version with sound effects. Sounds good, keep up the good work!

For you next project, also check out the framework repo. The current version of the framework has MP3 support, so you can add music and shit too :)

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 4th, 2017, 12:52 pm 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
I'm kind of up to date with chili's videos. (I've only watched the new beginner and intermediate series). Wasn't really looking forward to this moment. I mean it's not that bad, but from now on I'll have to do the research myself, which I'm not very good at. And there is also the old series. But hopefully I will get used to learning and searching shit myself.
Now I'm probably going to watch some of the old episodes, but before that I want to add some stuff to the 2d shooter.
-give it goddamn name
-probably change the icon (is it ok if I change the icon? it's not like I'm changing the credits or something, right?)
-change the way the bullet/ball counter is displayed to something like this. Wanted to do something like a bullet icon and then display how many balls you have left. But the ones that are easy to do look like dildos.
-make a circle area that gets smaller as time passes. and if you are out of it you take some amount of damage per second (like in PUBG or h1z1)
-probably adjust the balls to be smaller and faster
-a menu between rounds where you can mess with the values


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 5th, 2017, 11:54 am 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
ceofil wrote:
-make a circle area that gets smaller as time passes. and if you are out of it you take some amount of damage per second (like in PUBG or h1z1)

I used the recursion thing used in memesweeper (to check for empty tiles but now it just puts a pixel at on of the 9 positions) to draw an "ElectricThing". And then every frame it generates a random position and draws an electric thing at that position. But that was too ugly and fast.
Instead of that I saved the last position and continued from there and so on. So it look like the wave of electricity is moving or something. Looks kinda cool. Also the length sets the speed. I need to find a better way to spawn these things tho. Because it should look like it's uniformly distributed.

Feel free to mess with the values.

https://github.com/ceofil/tanks
Image


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 6th, 2017, 9:42 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3402
Location: Japan
This is a really great effect ceofil! Really good stuff there, I'm impressed. Gonna have to put this in the next update video for sure. If you like this kind of stuff, you're gonna love pixel shaders.

Also did you change the sounds? They sound better now.

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 6th, 2017, 5:17 pm 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
Yup. Changed the sound for shooting and the sound when being hit. I wanted it to sound more like a shooter. I also wanted to make it so bullets don't get reflected by the walls. Because that's how bullets behave and because if the speed is too high the collision test is fucked. But I just left that in there, set the speed a little lower. It's a kind of nice mechanic in the game. Being able to angle shoot.

Thanks for the nice words tho!


Top 
 Profile  
Reply with quote  
 Post subject: Re: C++ Progress ish
 Post Posted: June 17th, 2017, 2:56 pm 
 

Joined: April 13th, 2017, 8:35 pm
Posts: 38
Hi there! Didn't post anything here in a while.
Didn't do much last week.
-added a little animation for reloading.
-installed sfml and played a little bit with it (most of the things that are included in their tutorial). It's cool to be able to draw sprites easily and rotate and all that jazz. But it feel more comfortable in chili's framework. It's like I have more freedom or something. Or maybe it's a matter of time until I get used to it.
-decided to make this game. It's combination of superhot and hotline miami. Didn't play hotline miami but I really liked superhot. I already have the physics, the slow motion things it's not gonna be a problem. All I have to do is the enemies and their AI.
-made the first commit for the game. The enemies will not start chasing you until they see you so there is that. The line between enemy.pos player.pos must not overlap with any wall. Well that's simple all I have to do is check every side of the wall and see if it overlaps with that line (segment). Now that was a pain in the ass. Tried to do it on my own and failed miserably. Then I found this and this. So nice and short and easy to understand. What's the best way to aproch this kind of stuff? Try to do it on your own ( and probably spend a lot of time on it) or search and use a method that is already tested and it's more efficient and all?


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: