Id go for "Beginning C++ Through Game Programming" by Michael Dawson. Its a good book for complete beginners and is not a daunting 1000 page tome like other books.
- Viewing Profile: Reputation: ISDCaptain01
Community Stats
- Group Members
- Active Posts 177
- Profile Views 4,137
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
User Tools
Contacts
ISDCaptain01 hasn't added any contacts yet.
Latest Visitors
#5069901 C++ programing book and game developing
Posted by ISDCaptain01
on 14 June 2013 - 11:12 PM
#5069023 Having collision detection problems in my pong clone (allegro 4)
Posted by ISDCaptain01
on 11 June 2013 - 10:24 PM
Okay so im making a pong game. Im able to successfully get both of paddles on the screen moving. I get my ball on screen as well and it moves too! But the thing is when it hits the end of the screen, it just stays there stuck. How do I make it bounce off the screen? Heres my code:
This is just my header file filled with constants and function declarations. Nothing special
#pragma once
#include <allegro.h>
#include <iostream>
using namespace std;
const int WIDTH = 640;
const int HEIGHT = 480;
const int MAXSPEED = 8;
int gameover = 0;
class Ball
{
public:
int x;
int y;
int radius;
int color;
int speed;
};
//Declare a ball object
Ball ball;
class Paddle
{
public:
int x;
int y;
int color;
int speed;
int dir;
int score;
};
//Declare two paddles
Paddle paddle[2];
//Draws the paddles on screen
void drawpaddle(int num);
void setuppaddle();
void erasepaddle(int num);
void movepaddle(int num);
void getinput();
void moveright(int num);
void moveleft(int num);
void score(int player);
void setupball(int num);
void setupscreen();
void drawball(int num);
void eraseball(int num);
void moveball(int num);
Now heres my main. The collision detection code is inside the moveball function near the end of the file, right above main. Please do let me know what my problem is. For those who wish to compile, all you need the a4 libs. Im only using geometric primitives and no sprites or separate files.
#include "functions.h"
//Sets up the paddles, ready to be drawn
void setuppaddle()
{
//Set up the top paddle first
paddle[0].x = 320;
paddle[0].y = 50;
paddle[0].color = 15;
paddle[0].score = 0;
paddle[0].speed = 0;
paddle[0].dir = 1;
//Set up the bottom paddle
paddle[1].x = 320;
paddle[1].y = SCREEN_H - 50;
paddle[1].color = 15;
paddle[1].score = 0;
paddle[1].speed = 0;
paddle[1].dir = 3;
}
//Draws the paddles on screen
void drawpaddle(int num)
{
int x = paddle[num].x;
int y = paddle[num].y;
int paddleColor = paddle[num].color;
//Draw the paddles
rectfill(screen, x+40, y+10, x-40, y-10, paddleColor);
}
//Erase the paddle from screen
void erasepaddle(int num)
{
//Capture the paddle in a rectangle
int left = paddle[num].x- 41;
int right = paddle[num].x+ 41;
int top = paddle[num].y- 11;
int bottom = paddle[num].y+11;
//Erase the paddle
rectfill(screen, left, top, right, bottom, 0);
}
void movepaddle(int num)
{
int dir = paddle[num].dir;
int speed = paddle[num].speed;
//Update the paddle positions based on direction
switch(dir)
{
case 1:
paddle[num].x += speed;
break;
case 3:
paddle[num].x += speed;
}
//Keep the paddles within the screen
if(paddle[num].x > SCREEN_W-22)
{
paddle[num].x = SCREEN_W-22;
paddle[num].speed = 0;
}
if(paddle[num].x < 22)
{
paddle[num].x = 22;
paddle[num].speed = 0;
}
}
void getinput()
{
if(key[KEY_ESC])
gameover = 1;
//Controls for top paddle
//Move right
if(key[KEY_D])
moveright(0);
//Move left
if(key[KEY_A])
moveleft(0);
//Controls for the bottom paddle
//move right
if(key[KEY_RIGHT])
moveright(1);
//move left
if(key[KEY_LEFT])
moveleft(1);
rest(10);
}
void moveright(int num)
{
paddle[num].speed++;
if(paddle[num].speed > MAXSPEED)
paddle[num].speed = MAXSPEED;
}
void moveleft(int num)
{
paddle[num].speed--;
if(paddle[num].speed < -MAXSPEED)
paddle[num].speed = -MAXSPEED;
}
void score(int player)
{
//update points
int points = ++paddle[player].score;
//Display the score
textprintf_ex(screen, font, SCREEN_W-70*(player+1), 1, 15, 0,
"P%d: %d", player+1, points);
}
void setupscreen()
{
int ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
if(ret != 0)
{
allegro_message(allegro_error);
return;
}
//Print the game title on the screen
textprintf_ex(screen, font, 1, 1, 15, 0,
"Pong - %dx%d", SCREEN_W, SCREEN_H);
}
void setupball(Ball &ball)
{
//Set up all the ball properties
ball.x = 320;
ball.y = 240;
ball.radius = 10;
ball.color = 15;
ball.speed = 0;
}
void drawball(Ball &ball)
{
//Fit in the ball properties in variables
int x = ball.x;
int y = ball.y;
int radius = ball.radius;
int color = ball.color;
//Use those variables to draw a filled circle on the screen
circlefill(screen, x, y, radius, color);
}
void eraseball(Ball &ball)
{
//Get dimensions of ball
int left = ball.x - ball.radius;
int right = ball.x + ball.radius;
int top = ball.y - ball.radius;
int bottom = ball.y + ball.radius;
//Make a black rectangle big enough to "erase" it
rectfill(screen, left, top, right, bottom, 0);
}
void moveball(Ball &ball)
{
//This is where the ball moves and collides with the
//screen boundries and paddles
int xdir = 10;
int ydir = 10;
//Update the x position
ball.x += xdir;
if(ball.x > SCREEN_W - ball.radius)
{
xdir = -10;
ball.x = SCREEN_W - ball.radius;
}
if(ball.x < ball.radius)
{
xdir = 10;
ball.x = ball.radius;
}
//Update the y position
ball.y += ydir;
if(ball.y > SCREEN_H - ball.radius)
{
ydir = -10;
ball.y = SCREEN_H - ball.radius;
}
if(ball.y < ball.radius + 20)
{
ydir = 10;
ball.y = ball.radius + 20;
}
//Draw the circle in the updated position
//drawball(ball);
//rest(20);
//eraseball(ball);
}
int main()
{
//Set up allegro
allegro_init();
install_keyboard();
install_timer();
srand(time(NULL));
//Call the setupscreen function
setupscreen();
//Set up the paddles at the right position on screen
setuppaddle();
//Set up the ball
setupball(ball);
while(gameover == 0)
{
/*Erase the paddles
erasepaddle(0);
erasepaddle(1);
//Move the paddle
movepaddle(0);
movepaddle(1);
//Draw the paddles
drawpaddle(0);
drawpaddle(1);
//Check for keypressed
if(keypressed())
getinput();
//Slow the game down */
moveball(ball);
drawball(ball);
rest(30);
eraseball(ball);
}
allegro_exit();
return 0;
}
#5066203 OMS CS degree - viable option?
Posted by ISDCaptain01
on 30 May 2013 - 12:25 PM
Looks like a coursework-only degree. No research requirement, and no thesis.
The coursework-only aspect will make a difference to some people, and will make no difference to others.
Ultimately it is still just a bit of education and certification. It won't guarantee a job, and it won't guarantee any changes to your career. You may be able to leverage the knowledge and other facets of what you gained, but it guarantees you nothing.
If you want to invest the time and the money, and if it fits your life goals, it might be worth it.
Thanks for the input. Honestly, my desire is to get my feet wet in industry before I go on to a MS CS program. So I am working on my own projects to build up a portfolio. Unfortunately I keep getting mixed answers to this question of getting a Master's degree (or even a Bachelor's in CS) first, which becomes frustrating and a bit of a distraction when I am working towards my primary goal. That said, grad school is more of a backup plan if finding work is seeming like a shot in the dark.
Just remember a degree in just about anything (even STEM degrees) don't guarantee anything. They are just a CV/resume booster. But I can say with confidence that your portfolio and personal projects will say a lot more than that piece of paper
#5062750 Need advice
Posted by ISDCaptain01
on 18 May 2013 - 02:55 AM
Thanks everyone. I'll do more research on ME to see if its for me. But if I major in one and minor in another would there be too little free time for game dev? This is what I'm afraid of.
Engineering majors barely get free time. I don't know about you, but I def. would not feel like coding after studying some vector dynamics or mechanics of materials.
Brain draining major + brain draining hobby = burn out
#5049846 Advanced C++
Posted by ISDCaptain01
on 04 April 2013 - 01:32 AM
I highly recommend you read the book "data structures for game programmers"
#5048807 Re-starting?
Posted by ISDCaptain01
on 01 April 2013 - 12:48 AM
I wouldn't restart, cause you really cant "restart" because you obviously know the basics. Just fix what is broken and move forward. You cant always go back cause you wont ever move forward. Grab a good modern book on C++ and see what is wrong. Then fix your wrong code into the right code. That way you'll get practice and learn more things.
#5048132 Education-related questions from a beginner.
Posted by ISDCaptain01
on 29 March 2013 - 03:35 PM
Well I cant give you any advice on how to break in the industry, it is very possible to learn on your own, especially nowadays.
There are a ton of books and online tutorials and videos out there. Also GameDev.net has been on spree with articles, they are a great source of info.
Then you can actually take computer science classes online for free from sites like coursera, Udacity, and EdX. Its never been easier.
Edit: I also want to add, that taking those courses can get you a certificate as well, if your into that.
#5045766 Java or learn c++
Posted by ISDCaptain01
on 22 March 2013 - 04:37 PM
I like C++ since it has tons of game and graphics libraries for it, not to mention the sheer amount of tutorials and books on game programming that use C++.
Its not as hard as some people make it out to be, it aint close to the nightmare that calculus based physics was... lol
#5038959 Comparing strings using a priority queue(heap)
Posted by ISDCaptain01
on 04 March 2013 - 01:42 AM
Well Everyone. I got it to work!!!!
What I did was remove the function pointer and made the comparison function built inside the class. The comparison function
just returns bool values so it can work with any datatype now:
Heres the brand new and improved class:
#pragma once
#include <iostream>
#include "Array.h"
using namespace std;
template <class DataType>
class Heap2: public Array<DataType>
{
public:
//CLASS VARIABLES================================
//Keeps track of how many items are in the heap
int m_count;
//CLASS FUNCTIONS================================
//Constructor
Heap2(int p_size)
: Array<DataType> (p_size + 1)
{
m_count = 0;
}
//Enqueue
void Enqueue(DataType p_data)
{
//Updates the counter, to keep track of how many
//items are in the heap
m_count++;
//If the number of entries is larger then the array size
if(m_count >= m_size)
{
Resize(m_size*2);
}
//Inserts the the data in the proper index
m_array[m_count] = p_data;
//Perform the WalkUp algorithm to see if the newly inserted
//item is larger then its parent
WalkUp(m_count);
}
//Dequeue
void Dequeue()
{
//If the heap is not empty
if(m_count >= 1)
{
//Moves the item at the bottom of the heap
//to the root
m_array[1] = m_array[m_count];
//Calls the WalkDown function to align the nodes properly
// to keep it as a heap
WalkDown(1);
//Decrements the number of items in the array
m_count--;
}
}
//WalkUp
void WalkUp(int p_index)
{
//The current parent index
int parent = p_index / 2;
//The current child index
int child = p_index;
//A temporary variable that holds the data of the child
DataType temp = m_array[child];
//While the parent index is not zero
while(parent > 0)
{
//Determines if the node is walking up is in
//the correct place or not by checking the parent value
//If the parent node is greater then the node that is being
//walked up, the function uses the break keyword to quit the loop
//If the parent node is less then the node, then the parent
//node is moved down into the child node, and both the parent
//and child pointers are divided by 2, moving them up one level.
if(m_compare(temp, m_array[parent]) == true)
{
m_array[child] = m_array[parent];
child = parent;
parent /= 2;
}
else
break;
}
//The data that was supposed to be moved up is moved into the cell
//that the child points to.
m_array[child] = temp;
}
//WalkDown: Moves the root down the tree until it becomes a heap
void WalkDown(int p_index)
{
//Keeps track of the current parent index
int parent = p_index;
//Keeps track of the current child index
int child = p_index * 2;
//Stores the data that is being walked down into a temporary variable
DataType temp = m_array[parent];
//Starts a loop, loops through the tree until the child index is
//greater then the tree size
while(child < m_count)
{
//Checks to see if the right child exists
if(child < m_count - 1)
{
//Compares the left and right child to see which one is larger
// LEFT CHILD RIGHT CHILD
if(m_compare(m_array[child], m_array[child + 1]) == false)
{
//If the right child is larger, then increment the child index
//because the the index of the right child is always is one larger
//then the left child
child++;
}
}
//Now the function knows which child it wants to move upward. It
//Determines if the child node needs to move upward by comparing
//it to the value in the temp variable
//If a swap needs to be made
if(m_compare(temp, m_array[child]) == false)
{
//Moves the child upward into the parent index
m_array[parent] = m_array[child];
//Moves the the parent and child index down one level
parent = child;
child *= 2;
}
//If no swap is needed
else
break;
}
//The value in temp is placed into the correct index
m_array[parent] = temp;
}
bool m_compare( DataType left, DataType right)
{
if(left > right)
return true;
if(right > left)
return false;
else
{
cout << "Critical Failure" << endl;
}
}
};
and heres the source file:
#include <iostream>
#include "Heap2.h"
using namespace std;
int main()
{
//Create a heap and inserts some values into it
cout << "Inserting ints into the heap..." << endl;
Heap2<int> myHeap(5);
myHeap.Enqueue(1);
myHeap.Enqueue(2);
myHeap.Enqueue(3);
myHeap.Enqueue(10);
myHeap.Enqueue(20);
//Show the heap on screen
cout << "Showing the heap: " << endl << endl;
for(int index = 1; index <= myHeap.m_count; index++)
{
cout << myHeap[index] << ", ";
}
cout << endl << endl;
//Create a double heap
cout << "Inserting doubles into the heap..." << endl;
Heap2<double> dHeap(5);
dHeap.Enqueue(22.22);
dHeap.Enqueue(33.33);
dHeap.Enqueue(44.44);
dHeap.Enqueue(11.11);
dHeap.Enqueue(55.55);
//Show the double heap on screen
cout << "Showing the double heap: " << endl << endl;
for(int index = 1; index <= dHeap.m_count; index++)
{
cout << dHeap[index] << ", ";
}
cout << endl << endl;
//Create a string heap
cout << "Inserting strings into the heap..." << endl;
Heap2<char*> sHeap(5);
sHeap.Enqueue("Hello");
sHeap.Enqueue("Bye");
sHeap.Enqueue("Red");
sHeap.Enqueue("Blue");
sHeap.Enqueue("Green");
//Show the string heap on screen
cout << "Showing the string heap: " << endl << endl;
for(int index = 1; index <= sHeap.m_count; index++)
{
cout << sHeap[index] << ", ";
}
cout << endl << endl;
cin.get();
return 0;
}
Thanks to everyone for the input and ideas. Felt like I conquered something lol
#5036618 Today marks one year since I started programming
Posted by ISDCaptain01
on 26 February 2013 - 12:37 AM
So on this day, last year I picked up my c++ book and got started programming, I can definately say its been challeging. I barely knew anything about the stuff. I worked myself through the basics and some of the more advance stuff like operator overloading and pointer manipulation went over my head the first 4 months or so. By the end of August, I got a basic grasp of the language. Then in september I decided to get familar with visual c++ 2010. I learned how to make header, implementation and source files, and got a basic control on the IDE. I also made a pong clone following a tutorial. By mid-October I was like "okay I want to learn about data structures, cause I feel im missing out since the CS majors were taking it". I get a copy of Data Structures for Game Programmers and work my way through it. I learned about basic algorithm analysis, templates and all the various data structures. Since the book was using SDL, I decided to pause and get a basic idea of SDL. That took me 2 weeks. Then I continued through the book, learning the data structures (and cool stuff like the branch prediction unit). Now Im 60% done with the book. I plan to start Allegro within the next copule of months and max out all my skills in it. I want to make tons of shareware quality games for atleast a year. Then I might hit 3D programming
All I can say its amazing how much Ive learned. Its been amazingly fun and interesting endeavor. The most imporatant thing that helped was self-discipline. I was able to sit down everyday for atleast an hour and learn. And thats what im going to continue doing.
#5035717 GameMaker Tutorials
Posted by ISDCaptain01
on 23 February 2013 - 04:01 AM
you could go to amazon and get the official gamemaker apprentice book straight from yoyo games
and heres the gamemaker companion
http://www.amazon.com/Game-Makers-Companion-Jacob-Habgood/dp/1430228261/ref=pd_bxgy_b_img_y
#5030552 TheNewBoston any good?
Posted by ISDCaptain01
on 09 February 2013 - 07:10 PM
he's Very good, he helped jumpstart my foray into programming. I find him engaging and not slow like my boring textbook. Don't worry just watch them, they are really the best u can find
#5029643 Experience without a degree
Posted by ISDCaptain01
on 06 February 2013 - 11:58 PM
Dude you have 10 years of experience. No new college grad is going to be able to beat that.
Get a degree if: 1) To get passed the HR filter (which you already have)
2) To fail at impressing your coworkers(like your coworkers tried impressing you, but failed)
3) To get knowledge in a field you have no clue about
Honestly I think its your friends who are the insecure ones. They have to justify their degrees to you because you
are more successful than them without one
If you already know about CS and wanna try EE then go ahead. But Warning: its crazy hard, get ready to buckle down and study full time
good luck
#5027738 Anyone here a self-taught graphics programmer?
Posted by ISDCaptain01
on 31 January 2013 - 10:30 PM
wow that blew me away lol. Id be happy if i could program N64ish graphics haha
#5027722 Anyone here a self-taught graphics programmer?
Posted by ISDCaptain01
on 31 January 2013 - 09:29 PM
Im talking about people with no cs degree or formal education in it. How were you able to pick up the material and what challeneges did you face? Do you do it as a living or just a hobby?
- Home
- » Viewing Profile: Reputation: ISDCaptain01

Find content