Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 28 Sep 2012
Offline Last Active Oct 07 2012 01:29 PM

Posts I've Made

In Topic: Need alittle help in allegro please

03 October 2012 - 08:54 AM

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.

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?

In Topic: Need alittle help in allegro please

02 October 2012 - 03:12 PM

Never mind i got it to work :)

In Topic: Struggling a little

30 September 2012 - 01:42 PM

This is how my Ball class should look like:

#include "GameTypes" // this will create a struct Position and Velocity
#include "Paddle.h"

class Ball
	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.

		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.

	Position m_Position;
	Velocity m_Velocity;
	int m_Radius;
	Hitregion* m_pHitRegion; // create new Hitregion.
	bool m_bIsEnabled; // init of false

And this is how my Paddle class should look like:
#include "GameTypes" // this will create a struct Position and Velocity

class Paddle
	Paddle(Position pos, Velocity vel); // Create a ball with an initial position and speed. Is not necessarily.

	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.

	Position m_Position;
	Velocity m_Velocity;
	RECT m_Bounds; // how big the brick will be
	HitRegion* m_pHitRegion;

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. Posted Image

In the main you need to say something like:

The structs aren't hard to make:
struct Position
	int x, y;

struct Velocity
	int x, y;
Each gamecycle you say: m_Position += m_Velocity;
So maybe you need to put an operator += in your struct ;)


Haha u write some pretty advance classes :P i think u should take the expert out of my title and put it in your name :o as for allegro moving the paddle is something like this

if(key[KEY_UP] && paddleY > 0){

}else if(key[KEY_DOWN] && paddleY < 410){

In Topic: Struggling a little

30 September 2012 - 12:29 PM

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 1break;case 2://Code for direction 2break;case 3://Code for direction 3break;case 4://Code for direction 4break;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]

In Topic: Struggling a little

30 September 2012 - 12:05 PM

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: http://www.rocksolid...ames/robokill2/

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 )

class Weapon() // You know there are more than 1 type of weapon so I make this class a virtual class
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)

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. Posted Image
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. Posted Image


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