Allegro.cc - Online Community

Allegro.cc Forums » The Depot » Absorber - There can be only one

This thread is locked; no one can reply to it. rss feed Print
Absorber - There can be only one
Joe larson
Member #10,200
September 2008
avatar

EDIT: Changing the name to Rover Wars.

{"name":"roverwars.gif","src":"http:\/\/static.allegro.cc\/image\/cache\/3\/6\/3689497099ba45c4f3b0c9427bd1d160.gif","w":300,"h":225,"tn":"http:\/\/static.allegro.cc\/image\/cache\/3\/6\/3689497099ba45c4f3b0c9427bd1d160"}roverwars.gif
I made my first allegro game. Turned out good if I do say so myself. I called it absorber Rover Wars. It's kind of a multi-player competitive Osmos.

I'm gonna feature this game on my site, Cymon's Games, in February, but it turned out so well I've just got to show it off. I could expand it, add a score table to declare a winner after a number of rounds, add sound, but I'm gonna keep this one simple. It proves the concept. If it turns out that folks like this I may make those additions.

Download it compiled for windows and it's source here.

Note to self, allegro.cc forums uses html tags, not BBCode.

Trent Gamblin
Member #261
April 2000
avatar

Great little game!

If eating hotdogs is wrong, I don't wanna be right.

MiquelFire
Member #3,110
January 2003
avatar

Fun game. A little confusing as to which ball is whose (whom? Err, Matt!) when you start however.

---
People = Idiots; Person = Smart *compared to people*; Persons = undefined;
MiquelFire.com | +Me | Cumulate
I used to be an arrow, but then I took an adventurer to the head. ~23yrold3yrold

Joe larson
Member #10,200
September 2008
avatar

I've updated the zip with some minor (cheap) changes to the main menu to hopefully make the colorization a little clearer.

protip - press F10 while the game is running.

kazzmir
Member #1,786
December 2001
avatar

Pretty neat game dynamics, but its not that hard. I was able to win 3 times in a row. I think its a great base for something more interesting. Maybe make the screen larger (like a large virtual area that you can move through) and have things like negative balls that always take away some of your life?

OnlineCop
Member #7,919
October 2006
avatar

Very neat.

One small problem is that when you're playing against 2 computers, and one of those spawns by the edge of the screen, it just "bounces" next to the screen edge instead of seeking out the balls around it (or even avoiding the bigger balls/enemies as they move closer).

Other than that, this is a perfect candidate for an iPhone or Facebook app. It's a little high on the CPU usage, but that can always be tweaked later.

Thumbs up!

EDIT: Also, what to do in this situation (against a computer OR other players):

{"name":"600015","src":"http:\/\/static.allegro.cc\/image\/cache\/9\/0\/90b85af2cfee2c5d203f72717cbb637c.png","w":806,"h":626,"tn":"http:\/\/static.allegro.cc\/image\/cache\/9\/0\/90b85af2cfee2c5d203f72717cbb637c"}600015

EDIT 2: Here's what happens when it's 3 computers all against each other:

{"name":"600016","src":"http:\/\/static.allegro.cc\/image\/cache\/3\/f\/3fdbfa5cbda586fcf515e67d0cd25590.png","w":806,"h":628,"tn":"http:\/\/static.allegro.cc\/image\/cache\/3\/f\/3fdbfa5cbda586fcf515e67d0cd25590"}600016

Seems the big one is too concerned about the li'l one to go after the medium one, and the medium one is just scared off its own little corner.

The physics and logic in this were very well implemented.

EDIT 3: Yay, Playser 1 wins! Can you find him? Player 2, who was quite massive, got sucked into a NPC as Player 1 was running for his life from its own NPC black hole predators:

{"name":"600017","src":"http:\/\/static.allegro.cc\/image\/cache\/7\/8\/7842c0693e87d8fc1223bbbd809be0bc.png","w":803,"h":626,"tn":"http:\/\/static.allegro.cc\/image\/cache\/7\/8\/7842c0693e87d8fc1223bbbd809be0bc"}600017

--
You: Yeah! I'm gonna get stuff done today!
Internet: Nope! *POW*

Joe larson
Member #10,200
September 2008
avatar

Naturally the game is better against a human. The AI is pretty dumb. It just find the closest bubble and if it's smaller moves towards it and if it's bigger moves away from it.

Oh, and in the case of a jerk hiding in the corner, your bad for getting so big. You can take care of it by pressing F1 and starting over.

OnlineCop
Member #7,919
October 2006
avatar

So the point of this game is "it sucks to be you"? ;)

--
You: Yeah! I'm gonna get stuff done today!
Internet: Nope! *POW*

Dario ff
Member #10,065
August 2008
avatar

Great game! ;) I haven't tried playing against a human, but I'm sure it's really fun. But what framerate is it supposed to run at? It runs really jerky for me, but I see little CPU usage. And I don't think it needs more than 2.7 GHZ :P

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

OnlineCop
Member #7,919
October 2006
avatar

Joe, looks good, but you have an early "return" in your Blob::check_collision() code:

#SelectExpand
48int Blob::check_collide (Blob* obj) { 49 if( (obj->x - obj->radius) > (this->x + this->radius) ) return 0; 50 if( (obj->x + obj->radius) < (this->x - this->radius) ) return 0; 51 if( (obj->y - obj->radius) > (this->y + this->radius) ) return 0; 52 if( (obj->y + obj->radius) < (this->y - this->radius) ) return 0;
53 return 1;
54 int xx = abs(this->x - obj->x); 55 int yy = abs(this->y - obj->y); 56 double d = xx * xx + yy * yy; // Pythagorean theorem minus the sqrt to save processor cycles 57 if (d <= ((this->radius + obj->radius) * (this->radius + obj->radius))) { // we have overlap 58 return 1; 59 } 60 return 0; 61}

I got rid of this, and the balls correctly collided when they were at diagonals with each other (and overlapping visually). Otherwise, they SHOULD have absorbed each other but didn't.

--
You: Yeah! I'm gonna get stuff done today!
Internet: Nope! *POW*

Joe larson
Member #10,200
September 2008
avatar

Thanks for that. Duh. If you have any hints for the frame rate people are complaining about. Maybe that's just the frame rate the game's moving at.

let's see... 10 frames per second. Yeah that is a bit slow. But if I drop that it'll speed up the game, and I don't know that I want that. I'll play with it.

Dario ff
Member #10,065
August 2008
avatar

You know, normally in programming, Delta Timing is a popular technique for making the game run at the same speed in any frame rate :P. Come on, it's 2009, 10 fps is something really poor.

But, what the hell, I have the source code, I'll add it myself ;D

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

OnlineCop
Member #7,919
October 2006
avatar

This won't speed things up considerably, but you have several places where you do this kind of construct:

if (blobs[c].x - blobs[c].radius < 0)
  ...
if (blobs[c].y - blobs[c].radius < 0)
  ...
if (blobs[c].x + blobs[c].radius) > SCREENW)
  ...
if (blobs[c].y + blobs[c].radius) > SCREENH)
  ...

I would think that if blob[c].x is close to the left edge of the screen, it can automatically exclude the need for the check that it's against the right edge of the screen as well. You could rewrite this to:

if (blobs[c].x - blobs[c].radius < 0)
  ...
else if (blobs[c].x + blobs[c].radius) > SCREENW)
  ...

if (blobs[c].y - blobs[c].radius < 0)
  ...
else if (blobs[c].y + blobs[c].radius) > SCREENH)
  ...

Then, if you're by the left edge of the screen, you're not going to check that you're exceeding the right bounds of the screen also.

You may consider sorting all of your blobs. Since your screen is wider than it is tall, it's better to sort them along the x-axis. Then, when you are testing for collisions, you can eliminate all blobs that are too far away. This will at help with the framerate, since you're currently testing ALL blobs, even those on the opposite end of the screen.

And why do you (re)initialize the player_colors every time your gameloop() is called? Since the color values are fixed (not dependent on their sizes, or anything), call them within your init() loop a single time, and pass them into your other functions (if you don't want to just make them globals).

EDIT
<nitpick>

#SelectExpand
1class Blob 2{ 3public: 4 ... 5 6 Blob(int new_x = 0, int new_y = 0, double new_radius = 1.0) 7 { 8 this->x = new_x; 9 this->y = new_y; 10 this->dx = 0; 11 this->dy = 0; 12 this->radius = new_radius; 13 this->calc_area (); 14 this->playerid = 0; 15 }

You can initialize everything using the single-colon, which even gives you the ability to set const-defined variables (or, well, consts ;)):

#SelectExpand
1 Blob(int new_x = 0, int new_y = 0, double new_radius = 1.0) : 2 x(new_x), 3 y(new_y), 4 dx(0), 5 dy(0), 6 radius(new_radius), 7 playerid(0) 8 { 9 this->calc_area (); 10 }

</nitpick>

--
You: Yeah! I'm gonna get stuff done today!
Internet: Nope! *POW*

BAF
Member #2,981
December 2002
avatar

Interesting game. Is there a way to show FPS built in? Because it seems to run fine for me.

Also, you should set the color depth to the desktop color depth so aero doesn't kick off in Windowed mode. :P set_color_depth(desktop_color_depth()); I believe is the line for that.

SiegeLord
Member #7,827
October 2006
avatar

dario ff said:

You know, normally in programming, Delta Timing is a popular technique for making the game run at the same speed in any frame rate :P.

No.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]

Dario ff
Member #10,065
August 2008
avatar

I still mantain my point of view :P But I use a combination of the two in my games to assure stability.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Joe larson
Member #10,200
September 2008
avatar

I'm using the allegro timer routines to control my framerate. It was my understanding this would fix my timing at a constant rate. Is that not the case? At the moment my framerate is a 66ms pause, which should translate into about 15FPS.

@OnlineCop - Investigating further turns out that early return statement caused false positives on the collision at diagonals which was giving me negative overlap which was causing me trouble until I figured it was negative overlaps and corrected the code for that in the collides_with function, essentially fixing the symptom while not getting at the root cause. Now that I've fixed that I'm guessing my check for negative distances is mostly redundant, but good to have.

Also, concerning your else statements when you hit the side wall. Yeah, that might be a minor, very minor, optimization. But concerning sorting the list I do not see an effective way to make that save any time due to the 2D nature of the board. Unless I do some sort of perpixel check on the edges of the bubble. That's why "check_collide()" (IIRC that's what I called it) does a quick AABB check before pulling out the more mathematically intensive Pythagorean's.

And double oops to initializing player_colors every time. Fixed now.

re: nitpick - Wow! I didn't know it worked like that. Obviously I'm still learning.

Dario ff
Member #10,065
August 2008
avatar

The way you're doing your timing is right. I'm just complaining because you putted a so LOW fps limit. I mentioned Delta Timing because you said that you wanted it to run at the same speed, and that's what it does. But Siege Lord now mantains a point for fixed framerate... IDK, leave it in 10 FPS if you want to. I can always modify the source code.

EDIT: Changing the name to Rover Wars.

Ohhh... :( Absorber sounded like a truly classic game. I liked it more than Rover wars. Just my opinion.

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

CursedTyrant
Member #7,080
April 2006
avatar

Setting the FPS limit below 30 for a game that isn't Tic-Tac-Toe is absurd.

---------
Signature.
----
[My Website] | [My YouTube Channel]

Joe larson
Member #10,200
September 2008
avatar

@dario ff: "Ohhh... :( Absorber sounded like a truly classic game. I liked it more than Rover wars. Just my opinion."
You, my friend, have clearly never watched the Prisoner.

Go to: