• Content count

  • Joined

  • Last visited

Community Reputation

121 Neutral

About GameC++Expert93

  • Rank
  1. Need alittle help in allegro please

    [quote name='LennyLen' timestamp='1349239984' post='4986281'] Some notes on your code that aren't related to this issue: 1) You need to check return values of functions such as load_bitmap() and create_bitmap(). If these functions encounter an error, they will not terminate your program, or let you know i any other manner that something has gone wrong, and your program will not crash until later, when you try to access the returned data structure. 2) Unless you are using some obscure OS/hardware, you don't need to call poll_keyboard() as this will be done automatically anyway, and calling it yourself will just slow down the program. 3) Also, don't use acquire_screen()/release_screen() either, unless you know exactly what you are doing. With most OSes, these calls actually either do nothing, or will again slow down your code. 4) Using rest() to slow down your code is going to have different results on different machines. Allegro has timer routines for making sure that code runs at the same speed on all machines. Use those instead. 5) Instead of doing multiple draws to the screen, draw everything to one BITMAP then draw that to the screen. The way you have it right now, if there is a screen refresh between the two calls, you will get jittery results. The more draws to the screen you do, the more this occurs. 6) If you are going to draw a buffer bitmap that covers the entire screen, use blit() rather than draw_sprite(). draw_sprite is slower as it checks every pixel for transparency before drawing it. blit() does not do this extra work. [/quote] thank u im aware of some of the things like poll_keyboard my editor has an allegro project creator so it creates the starting code for you like starting allegro and it throws in that function i never added it imma save ur above tips and go through them later thanks again. Now i have 1 other question how do i get a scrolling background to repeat itself/continue from the bottom of the bitmap smoothly once the background runs out?
  2. Need alittle help in allegro please

    Never mind i got it to work
  3. Need alittle help in allegro please

    Hey this is the first game ive built using sprites/bitmap images im just curious how do you make a bitmap move in allegro? in using c++ btw thanks in advance. This is what i have so far [size=4][b][size=5]game.h[/size][/b][/size] [size=4][b][size=5][CODE] #ifndef GAME_H_INCLUDED #define GAME_H_INCLUDED /** *Include allegro and the std library **/ #include <stdlib.h> #include "allegro.h" /**Sprite bitmap**/ BITMAP* ship; BITMAP* enemy; BITMAP* laser; BITMAP* enemyLaser; /** *DEFINE SOME MAIN GAME CONSTANTS **/ #define WIDTH 640 #define HEIGHT 480 #define LIVES 4 /** *DEFINE SOME COLORS **/ #define TAN makecol(255,242,169) #define BURST makecol(255,189,73) #define BLACK makecol(0,0,0) #define WHITE makecol(255,255,255) #define GRAY makecol(128,128,128) #define GREEN makecol(0,255,0) /** *DEFINE SPRITE FILES WE NEED TO LOAD **/ #define SHIP "ship.bmp" /** *Buffer **/ BITMAP* buffer; /** *Define some variables **/ int score = 0;//Players score /** *DEFINE A SPRITE STRUCTURE **/ typedef struct SPRITE{ int dir; int x,y; int Xspeed,Yspeed; }SPRITE; SPRITE* Ship; #endif // GAME_H_INCLUDED [/CODE][/size][/b][/size] [b][size=5]main.cpp[/size][/b] [size=5][size=3][CODE] #include "game.h" /** *Draw everything to the screen **/ void draw(){ acquire_screen(); draw_sprite(screen,buffer,0,0); draw_sprite(screen,ship,100,300); release_screen(); rest(50); } /** *Handles movement of our players ship **/ void moveShip(){ if(key[KEY_RIGHT]){ --Ship->x; } } /** *SETUP OUR GAME **/ void GameSetup(){ draw(); } void Enemy_Handle(){} int main() { //Initialize Allegro allegro_init(); /**Set color depth to 32**/ set_color_depth(32); //Set the resolution to 640 x 480 with SAFE autodetection. set_gfx_mode(GFX_SAFE, WIDTH, HEIGHT, 0, 0); //Install the keyboard handler install_keyboard(); buffer = create_bitmap(WIDTH,HEIGHT); ship = load_bitmap(SHIP,NULL); GameSetup(); //Loop until escape is pressed while(! key[KEY_ESC]) poll_keyboard(); moveShip(); return 0; } END_OF_MAIN(); [/CODE][/size][/size]
  4. Struggling a little

    [quote name='EngineProgrammer' timestamp='1349031643' post='4985440'] This is how my Ball class should look like: [CODE] #include "GameTypes" // this will create a struct Position and Velocity #include "Paddle.h" class Ball { public: Ball(Position pos, Velocity vel, int radius); // Create a ball with an initial position and velocity. Is not necessarily. radius: how big is the ball. ~Ball(); void Update(); void Draw(); void SetPosition(Position pos); void SetVelocity(Velocity vel); void IncreaseVelocity(Velocity velDelta); void DecreaseVelocity(Velocity velDelta); void Disable(bool draw); // You can use this when you make a countdown after a point has made. The Boolean will tell to to keep the ball drawn of hided from the screen. void Enable(bool left); // This will create a random velocity for your ball. The Boolean will tell you what direction you want the random velocity go to. void CollisionDetection(Paddle& paddle); // This will reserve the X-velocity when you hit a paddle. private: Position m_Position; Velocity m_Velocity; int m_Radius; Hitregion* m_pHitRegion; // create new Hitregion. bool m_bIsEnabled; // init of false };[/CODE] And this is how my Paddle class should look like: [CODE] #include "GameTypes" // this will create a struct Position and Velocity class Paddle { public: Paddle(Position pos, Velocity vel); // Create a ball with an initial position and speed. Is not necessarily. ~Paddle(); void Update(); void Draw(); void SetPosition(Position pos); void SetVelocity(Velocity vel); void IncreaseVelocity(Velocityve velDelta); void DecreaseVelocity(Velocity velDelta); HitRegion* GetHitregion(); // return the hitregion of the paddle. This can also be a RECT if you like to. private: Position m_Position; Velocity m_Velocity; RECT m_Bounds; // how big the brick will be HitRegion* m_pHitRegion; };[/CODE] All methods will be handled in the main message loop. I'm not familiar with Allegro so I don't know how your keyboard will function to move your paddles. I also don't know how those messages are handled. So with using the methods of the class I can't really help you. [img][/img] In the main you need to say something like: ball.CollisionDetection(paddlePlayer1); ball.CollisionDetection(paddlePlayer2); The structs aren't hard to make: [CODE]struct Position { int x, y; }; struct Velocity { int x, y; }; [/CODE] Each gamecycle you say: m_Position += m_Velocity; So maybe you need to put an operator += in your struct ;) ~EngineProgrammer [/quote] Haha u write some pretty advance classes i think u should take the expert out of my title and put it in your name as for allegro moving the paddle is something like this [CODE] if(key[KEY_UP] && paddleY > 0){ --paddleY; }else if(key[KEY_DOWN] && paddleY < 410){ ++paddleY; } [/CODE]
  5. Struggling a little

    Heres what i have so far and i do find it a lot easier writing out your methods etc.. first then adding functionality to them later [source lang="cpp"]#include <allegro.h> /** *Our class that handles paddle 1 and paddle 2 **/ class Paddles{ }; /** *Our class that handles the pong ball **/ class Ball: public Paddles{ public: int x; int y; int direction; int tmpX; int tmpY; void BallMoveRandom(); void DrawBall(); }; void Ball::BallMoveRandom(){ x = 330; y = 240; direction = 1; tmpX = x; tmpY = y; /** *Set up a switch statement to handle 4 different directions **/ switch(direction){ case 1: //Code for direction 1 break; case 2: //Code for direction 2 break; case 3: //Code for direction 3 break; case 4: //Code for direction 4 break; default: direction = rand() % 4 + 1; } } int main() { //Initialize Allegro allegro_init(); //Set the resolution to 640 x 480 with SAFE autodetection. set_gfx_mode(GFX_SAFE, 640, 480, 0, 0); //Install the keyboard handler install_keyboard(); //Loop until escape is pressed while(! key[KEY_ESC]) poll_keyboard(); //Exit program allegro_exit(); return 0; } END_OF_MAIN();[/source]
  6. Struggling a little

    [quote name='EngineProgrammer' timestamp='1349027351' post='4985419'] I'm sorry but I can't give my code away. Our game has been supported with a Game Engine from our docent Programming. I assume allegro has matrices? Check this game: [url=""]http://www.rocksolid...ames/robokill2/[/url] Play a few missions, but not to "play" but to observe. Look how the robot is moved. Look from where the bullets are fired. Look what happens when a bullet has touched a wall. Look how many bullets a breakable box can take. Look at your inventory, map, checkpoints, items you can buy. You can drag and drop items, figure out(on paper) how you should make that work. For all the things I said: use a piece of paper! Writing down is very important when you want to create a game. If you aren't interested in this game find a game yourself and do the same thing. Look how the game mechanics work. Write it down, and figure out how you will code those mechanics. You have trouble with applying it to programming games because you don't have a diagram/sketch. So make one after you got all the game mechanics. You have game-logic, and game-creation-logic. And they are almost exact the same. When you play a game for example COD, Your weapon has 40 bullets, you've shot 28 and you are in a safe area, you know you need to reload that moment. So when you program the class Weapon and class Bullet, you know you need a method: Reload(); When you program a game it's important to find a structure through the game-logic. This is sort of how my Weapon class of a COD game will look like: ( and I'm not even thinking at the game-creation-logic, just thinking how the weapon should work when I play the game. so at game-logic level ) [CODE] class Weapon() // You know there are more than 1 type of weapon so I make this class a virtual class { Weapon(); virtual ~Weapon(); virtual void SetFireRate(int fireRate); // Maybe you can buff your character with faster firepower. virtual void SetBulletDamage(int damage); // When you got a death-streak your character can be buffer with more damage the first kill. static const int DEFAULT_FIRE_RATE = 4; static const int DEFAULT_DAMAGE = 20; virtual void Fire(); virtual void Reload(); virtual bool IsActive(); virtual bool IsPrimary(); virtual bool IsSecondary(); virtual bool IsOutOfAmmo(); virtual int GetMagazine(); // returns the size of how many bullets I have left in my magazine(arsenal) virtual int GetAmmo(); // returns the size of how many bullets I have left in my ammo(so the total amount) } [/CODE] This is how I do it. just writing down the class + the methods. So I don't think at linking classes yet, or data members. [img][/img] After I got the methods ready of how I think my game will work. I create a diagram, sketch, structure, plan of how I will program that game. Thereafter I just start programming class by class, method by method. Sorry for the long post. [img][/img] ~EngineProgrammer [/quote] Aww that helps put it into better perspective , maybe ill start by rewriting the game pong using a more organized way like you did above then send u the code and let you tell me how i did haha call me old fashion but i really get into building some of the older arcade games adding my own twist to them so maybe ill stick with things like pong,breakout, asteroids etc.. for now to get more into game programming then move onto things like RPGS
  7. Struggling a little

    [quote name='EngineProgrammer' timestamp='1349023324' post='4985397'] Hi GameC++Expert93. I would say, first check to be sure it you got all basics done. Here is a pdf, have a look at the introduction and see if you have learned all the 'days'. [url=""]http://www.angelfire...lusin21days.pdf[/url] My first game(school project) was: supersonic warrions 2: Dragonball We had 2 months for it. So you can already make pong, try to make a game like this as well in a deadline of 2 months. If you accept the challenge post your progress on this site. I gladly help you with any problem! [img][/img] ~EngineProgrammer [/quote] Thanks for the link ive looked over it and can say i do have a pretty good understanding of all the days idk if it list vectors in their also but i have an understanding of that has well. Mmm i dont guess u could take the time and message me the code to your dragonball game id love to look at it and hopefully use it as a guide if possible thanks again for the offer of helping me its just weird cause i know c++ but am having trouble applying it to programming games.
  8. Struggling a little

    So yes i know my title has the word expert in it i honestly was just making up a name so don't poke fun please lol. Anyways ive coded c++ for quite awhile now and have c++ pretty much grasped but for the lights of me im really having a hard time in the game programming aspect because i do come from a web development background of programming in PHP for over 5 years but i really wanna dig deeper into game development with c++ and allegro. any ideas as to how to master programming games using the c++ language? i mean i have the basics down and can create small games like pong etc.. but its the bigger games id like some advice on how to plan and code thanks in advance.
  9. How to pack game resources?

    As mentioned just organize them into files then set your references correctly in your code to point to the different folders like sounds,images etc..
  10. How to pack game resources?

    As mentioned just organize them into files then set your references correctly in your code to point to the different folders like sounds,images etc..
  11. [SFML] I Finished Pong! I Can't Believe It!

    [quote name='superman3275' timestamp='1348959016' post='4985176'] Okay, i'm still adding things: CHANGELOG: +Displays your final score on the game over screen +Made Programming Cleaner [url=""]LINK[/url] [/quote] mm we all are happy you have completed your pong game but idk if any programmers especially advance ones would go as far to keep updated with your changes or to try the changes out. After all it is just pong and is fairly easy to build your own pong game within 30 mins maybe not even that if your a fast typer
  12. tictactoe

    [quote name='Servant of the Lord' timestamp='1348978138' post='4985255'] This piece of code: "[b]rand() % 9 + 1[/b]"generates a number between 1 and 10. In C++, arrays begin at 0, so you may not want the +1 there. (An array with 10 elements, goes from 0 to 9) [b]srand(time(NULL));[/b] is only supposed to be called once at the beginning of your program - not every function call, or the results won't be properly random. Call [b]srand()[/b] once, and [b]rand()[/b] as many times as you like. If 'board[]' is a boolean array, you can't assign it a 'O'. If it's a char array, then it's okay. If this statement: "if(array_X[player_O]==false)" is valid, then you probably want "array_O[player_O]=true;" within the if() statement also. [code]if(array_X[player_O]==false) { board[player_O]='O'; array_O[player_O]=true; } [/code] But let's seperate out the two different things you are doing. A) You are having a board be clicked, and checking if the place is valid, and if valid, marking the board at that spot. B) You are also doing AI, by making it be the computer doing the move. The two should be seperated into different functions. [code]void Computer::do_turn() { //The computer's logic goes here. //Then you place the marker. place_marker(spot); } void Computer::place_marker(int spot) { board[spot]='O'; array_O[spot]=true; }[/code] The question is, what do you do for the computer's logic? There are two options that come to my mind: 1) Randomly choose a location, and if it's taken, randomly choose a new location, and if that's taken, randomly choose a new location, and so on. The problem: You can (possibly) have very bad random numbers and (potentially) loop forever accidentally choosing the same bad spots over and over. In code, this would look like this: [code]void Computer::do_turn() { int spot = 0; bool good = false; do { spot = rand() % SIZE_OF_BOARD; //Check that we didn't previously go here. if(array_O[spot]==false) { //Check that the other player didn't previously go here. if(array_X[spot]==false) { //If the place is actually empty, then this spot is good. good = true; } } } while(!good) //Place the marker where the computer decided. place_marker(spot); } [/code] But, as mentioned, this is not good, because we could accidentally randomly loop forever if we keep on picking spots that aren't good. 2) The second option is to make sure that the only places that are available to randomly pick, are ones that we know are already empty. Now there are two ways to do [i]that[/i]. One is to keep track of what places haven't been used by either player. Another is to, each time the computer is ready to pick, check which places are available. We're going to try the second option. [code]void Computer::do_turn() { //Count how many empty spaces are left. int numberOfEmptySpaces = 0; for(int i = 0; i < SIZE_OF_BOARD; i++) { if(board[i] != 'O' && board[i] != 'X') { numberOfEmptySpaces++; } } //Randomly generate a random number within the number of empty spaces. int spot = rand() % numberOfEmptySpaces; //Keep looping until we find a spot that isn't filled. while(board[spot] == 'O' || board[spot] == 'X') { //Each time we find our spot taken, we move to the next spot. spot++; //Unless we reach the end of our array, in which case we loop back around to zero. if(spot >= SIZE_OF_BOARD) { spot = 0; } } //Place the marker where the computer decided. place_marker(spot); }[/code] [/quote] I think he may be mixed up thinking about a random number generator where u may not want the number to start with 0 and may not exactly have the workings of an array in mind
  13. tictactoe

    [quote name='phil67rpg' timestamp='1348975909' post='4985245'] I am working on a tic tac toe game using c++.My question is how do I get the O's to not overwrite the X's on the board.I am using a boolean array to do a simple comparison using two boolean arrays.I just need a little hint.Here is the code I am working on. [code] void Computer::move_player_O() { srand(time(NULL)); player_O = rand()%9+1; if(array_X[player_O]==false) { board[player_O]='O'; } array_O[player_O]=true; } [/code] [/quote] my guess would be to only allow the computer to fill in a blank spot on your tic tac toe board by checking if the spot already contains an 0
  14. Coding

    As always id suggest allegro along side c++ if your a beginner its 100% free not pro/free version
  15. Want to make RTS strategy game, good starting point...?

    Personally i think you should start with the allegro gaming library/c++ its not all that hard once you get the basics down such as arrays,variables,datatypes,functions and objects. But do yourself a fav and learn the language you will program a game in first then start planing on making an RTS game after all we all had to start somewhere.