Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Pong counter (complete noob)

Author
Message
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 16th Jan 2012 21:33
Hi, I created my pong game and I'd like some help with something.. I have a thought of how to create the counter for the game but I get stuck on this problem that I don't know how to cout an integer! in c++ u could just do "cout<<"here's the int "<<int<<endl;" but in DarkGDK the only command I've found out about to output text is dbText();.
While I'm still making a thread I might just as well ask how I'd go about making a menu for the game and a simple AI.
Regards
(I'm sorry for the load of noob question).
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 22:35 Edited at: 16th Jan 2012 22:45
well i dont know the int name so i will call it counter.

Just use:


If you haven't a count system is easy:

When you check for collision with one of the paddles, just increment the value:


If this is not what you are looking for, please explain better

@EDIT
Oh sorry i didnt read the whole thing :S

So for the menu, it's called game states.

Hassan teached me this thing, its quite simple.. but not sure if will say it right, im kinda sleepy.. Please guys if i mistake something please correct.


@EDIT 2:
Ok i edited this 5 times, i dont want to mess up your head
I think its easily explained... Good luck

So basicly make a ENUM with the Gamestates

enum ENUM_NAME { Paused, MainMenu, Game };

Then in the loop just use the



Real sorry dude i dont know to explain it :S, I dont know if you can understand.. probably not because im not a good teacher..


For the AI... i dont know what you are mentioning with AI for pong.. are you looking for the CPU paddle movement?

If yes i think you can make it so it follows the Y of the Ball..
Bascily it will get invencible but you can play with the speed of movement , and playing with the speed you are making the difficulties of the game Easy han?

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 16th Jan 2012 22:56
Okay, don't worry, your explanations were perfect and I think I got it all, and yeah sorry, maybe it's not called AI but what I was looking for was what you refered to CPU Paddle movement. Thanks for the reply it was really useful.
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 16th Jan 2012 23:10
Hmm there also seems to be a problem that I can't see any text that I output. Is this because it gets "behind" the sprites? I tried in a fresh empy document to just output some text and it worked perfectly.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Jan 2012 03:09
When using sprites I always use this method:
load all the sprites
hide all the sprites

(in your game loop)
dbPasteSprite(..) for each sprite you have
dbText(..)

In that order...... This will show the sprites and then show the text even if the text appears on top of the sprite.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 17th Jan 2012 14:35
@the_raz
You can call it AI of course.. but is not that the paddle is "so" intelligent xD

But i think what i told you about playing with the speed will work nice, and you are making 2 things at once, you are making the CPU Movement and also the dificulty of the game so the player can play in different difficulties.. But there's a problem.. Too high speed will probably get the CPU invencible xD

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 17th Jan 2012 15:16
@Hawkblood how do I go about moving it then? Currently I use:
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 17th Jan 2012 16:35
Not a bad system, but i think its cool if you check if the other key is being pressed...

like:



C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 17th Jan 2012 17:10
Okay cool, thanks. I've solved all the problems I've had with sprites etc and I've got a working counter now but one thing that I wonder now, while it might not be specifically about darkGDK but about c++ is, how would I go about using a int that i declared in the player1.cpp and using it e.g. player2.cpp? Is that possible?
Regards.

(P.S it's annoying to have to wait for your posts to be accepted because by the time they've gotten accepted the issue or question I typed is most likely not relevant to the time( meaning i've fixed it or figured it out)).8
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Jan 2012 17:57
Quote: "how do I go about moving it then"

You change the position of the dbPasteSprite(..)
Currently you are using the move function of the sprites. It's not needed, but you CAN do it like this:
hide your sprites as stated before

I know this seems redundant, but it will work just fine and you can still use the collision detection.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 17th Jan 2012 21:24 Edited at: 17th Jan 2012 21:46
Hey hawkblood, can you just say me how can i call (in the switch) one of the gamestates? i forgot how..

@edit
Already know it thanks

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 21st Jan 2012 13:46
bump! How do I use an integer or similar between different .cpp or header files?
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 21st Jan 2012 14:12
the compiler doesn't seem to find my cpuai.h class, any idea why this is?
Here's the code for it and the cpuai.cpp:
CPUai.h:

CPUai.cpp:



this is the error message i get:

1>c:\users\the_raz\documents\visual studio 2008\projects\pong - kopia\pong\main.cpp(74) : error C2143: syntax error : missing ';' before '.'
1>c:\users\the_raz\documents\visual studio 2008\projects\pong - kopia\pong\main.cpp(75) : error C2143: syntax error : missing ';' before '.

which are these lines in the while-loop of the main.cpp:

Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Jan 2012 16:32
cpuai is a CLASS not an OBJECT, you can't cpuai.whatever, instead, something like:


the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 21st Jan 2012 19:19 Edited at: 21st Jan 2012 19:39
Okay, thanks for the answer Hassan. The thing is just that I did the same procedure with my player1 and it worked. I'll include my player1 to show you what I mean.
Player1.h:

Player1.cpp:


And with those I can use e.g. player1.movement();
player1.hittingtheball(); etc, so what's the difference between these and the cpuai one I did?
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 21st Jan 2012 20:07
Did you #include "CPUai.h" in your Main.cpp?

The fastest code is the code never written.
Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Jan 2012 20:08
you can't player1.movement() in that case

the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 21st Jan 2012 20:27
@Hawkblood, yes I did include that. I just find it peculiar that it doesn't work out when I've done basically the same thing that I did with the player1 and player 2 except I've changed it to automatically follow the ball.

@Hassan, How do you mean? It does indeed work using player1.movement(); with that code, it's just weird why the cpuai.movement(); doesn't work when the player1 does, when they're all made up the same way.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 00:35
What Hassan means is that you are not declaring cpuai as a variable of class cpuai.

It's a better practice to make all your classes and structs with some sort of identification that you don't use for normal variables. I use all caps:
struct MYSTRUCT{
....stuff....
};
or you can use:
struct _mystruct{
....stuff....
};
or any other method that will tell you and other people looking at code what is a variable and what is a struct/class.

I think the problem is that you are not doing something like this in your code:
cpuai cpuai;//this will make a variable cpuai of your structure cpuai.... This is confusing; and that's why you should do something like what I discussed earlier.

The fastest code is the code never written.
the_raz
12
Years of Service
User Offline
Joined: 14th Jan 2012
Location:
Posted: 22nd Jan 2012 13:51
@Hawkblood. Okay, but I don't completely understand this yet, should I do that in the header file of the cpuai or the .cpp? Also, can you do an example how it should look (more specifically to my case), I think that would make me understand more. (I'm sorry that I don't understand, I've just begun readin c++ and I haven't come to learn about structures, objects, classes etc. yet.)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 20:04 Edited at: 22nd Jan 2012 20:05

This is your class. Note: I used all caps for the class declaration. You can use anything you like to distiguish it from a variable object.
In your code, you need to declare something as a CPUAI type:

Notice that the class "CPUAI" is similar to other data structures like "int", "float", etc.... Your data structure just happens to have a tree of data structures inside it making it complex.

The fastest code is the code never written.
Kerl
User Banned
Posted: 26th Feb 2012 01:25
I understand what the_raz is saying about the cpuai movement because I too created a method just like that but it doesn't function properly in the game. The paddle doesn't follow the balls Y movements. It will follow the first movement (either up or down) then continue until it is off the screen. Even tho the sync rate is 60. Doesn't that mean this if loop should be re-checking at 60 loops per second?

Also, I understand what he was asking beore about passing variables to other classes. If an int is defined in say class ball. If you want to pass that variable to class player1. What is the syntax for this?

Ex.


Define hitCounter in ball.cpp



I know my syntax for that ball.hitCounter++; is wrong
I've also tried ball::hitCounter();
But do you get what I am trying to do and why it isn't working?

Login to post a reply

Server time is: 2024-04-27 02:34:18
Your offset time is: 2024-04-27 02:34:18