Halosos

62887 pts ยท October 24, 2012


#include <allegro.h> #include <cstdlib> #include <time.h> int ball_x = 320; int ball_y = 240; int ball_tempX = 320; int ball_tempY = 240; int p1_x = 20; int p1_y = 210; int p1_tempX = 20; int p1_tempY = 210; int p2_x = 620; int p2_y = 210; int p2_tempX = 620; int p2_tempY = 210; time_t secs; int dir; BITMAP *buffer; void moveBall(){ ball_tempX = ball_x; ball_tempY = ball_y; if (dir == 1 && ball_x > 5 && ball_y > 5){ if( ball_x == p1_x + 15 && ball_y >= p1_y && ball_y <= p1_y + 60){ dir = rand()% 2 + 3; }else{ --ball_x; --ball_y; } } else if (dir == 2 && ball_x > 5 && ball_y < 475){ if( ball_x == p1_x + 15 && ball_y >= p1_y && ball_y <= p1_y + 60){ dir = rand()% 2 + 3; }else{ --ball_x; ++ball_y; } } else if (dir == 3 && ball_x < 635 && ball_y > 5){ if( ball_x + 5 == p2_x && ball_y >= p2_y && ball_y <= p2_y + 60){ dir = rand()% 2 + 1; }else{ ++ball_x; --ball_y; } } else if (dir == 4 && ball_x < 635 && ball_y < 475){ if( ball_x + 5 == p2_x && ball_y >= p2_y && ball_y <= p2_y + 60){ dir = rand()% 2 + 1; }else{ ++ball_x; ++ball_y; } } else { if (dir == 1 || dir == 3) ++dir; else if (dir == 2 || dir == 4) --dir; } acquire_screen(); circlefill ( buffer, ball_tempX, ball_tempY, 5, makecol( 0, 0, 0)); circlefill ( buffer, ball_x, ball_y, 5, makecol( 128, 255, 0)); draw_sprite( screen, buffer, 0, 0); release_screen(); rest(5); } void p1Move(){ p1_tempY = p1_y; if( key[KEY_W] && p1_y > 0){ --p1_y; } else if( key[KEY_S] && p1_y < 420){ ++p1_y; } acquire_screen(); rectfill( buffer, p1_tempX, p1_tempY, p1_tempX + 10, p1_tempY + 60, makecol ( 0, 0, 0)); rectfill( buffer, p1_x, p1_y, p1_x + 10, p1_y + 60, makecol ( 0, 0, 255)); release_screen(); } void p2Move(){ p2_tempY = p2_y; if( key[KEY_UP] && p2_y > 0){ --p2_y; } else if( key[KEY_DOWN] && p2_y < 420){ ++p2_y; } acquire_screen(); rectfill( buffer, p2_tempX, p2_tempY, p2_tempX + 10, p2_tempY + 60, makecol ( 0, 0, 0)); rectfill( buffer, p2_x, p2_y, p2_x + 10, p2_y + 60, makecol ( 0, 0, 255)); release_screen(); } void startNew(){ clear_keybuf(); readkey(); clear_to_color( buffer, makecol( 0, 0, 0)); ball_x = 320; ball_y = 240; p1_x = 20; p1_y = 210; p2_x = 620; p2_y = 210; } void checkWin(){ if ( ball_x < p1_x){ textout_ex( screen, font, "Player 2 Wins!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0)); startNew(); } else if ( ball_x > p2_x){ textout_ex( screen, font, "Player 1 Wins!", 320, 240, makecol( 255, 0, 0), makecol( 0, 0, 0)); startNew(); } } void setupGame(){ acquire_screen(); rectfill( buffer, p1_x, p1_y, p1_x + 10, p1_y + 60, makecol ( 0, 0, 255)); rectfill( buffer, p2_x, p2_y, p2_x + 10, p2_y + 60, makecol ( 0, 0, 255)); circlefill ( buffer, ball_x, ball_y, 5, makecol( 128, 255, 0)); draw_sprite( screen, buffer, 0, 0); release_screen(); time(&secs); srand( (unsigned int)secs); dir = rand() % 4 + 1; } int main(){ allegro_init(); install_keyboard(); set_color_depth(16); set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0); buffer = create_bitmap( 640, 480); setupGame(); while( !key[KEY_ESC]){ p1Move(); p2Move(); moveBall(); checkWin(); } return 0; } END_OF_MAIN();

MRW I see that the zombies are winning

Points 10
Comments 2
Views 75

Lizard status: Sitting upon his ramp enjoying warmth

Points 13
Comments 1
Views 1

Lizard status: Getting nice and warm under his heat lamp

Points 10
Comments 3
Views 13

Soak logs in wood.

Points 1883
Comments 56
Views 99788

lizard status: Still sulking under his shelf

Points 4
Comments 6
Views 440

Lizard status: Happy, his shed is peeling

Points 5
Comments 2
Views 6

Lizard status: Some of his shed has fallen off, he is much happier

Points 6
Comments 12
Views 4

Lizard status: About to enjoy a bowl of tasty salad

Points 8
Comments 2
Views 2

Lizard status: Dingo is feeling less grumpy, but is still shedding

Points -3
Comments 0
Views 61

Lizard status: Being all high and mighty

Points 13
Comments 1
Views 4

Lizard status: A lot happier today, wants to be let out

Points 4
Comments 1
Views 12

Lizard status: Happy and a little inquisitive

Points 6
Comments 5
Views 2

Lizard status: Sitting on my keyboard being a cute pain in the ass

Points 15
Comments 5
Views 491

Lizard status: Hiding behind his log

Points 5
Comments 3
Views 3

Why.

Points 24
Comments 7
Views 1

Help, there is a danger noodle on my desk!

Points 7
Comments 2
Views 73

MRW a gypsy curses me

Points 10
Comments 10
Views 205

When I get bored of Imgur on the PC, I look at Imgur on my phone. MRW

Points 49
Comments 16
Views 146

Lizard staues: Shedding and sulking under his shelf

Points -1
Comments 2
Views 307

When you get the emojis just right

Points -5
Comments 0
Views 35

M'lizard

Points 9
Comments 3
Views 260

Found this amazing story on Reddit the other day. Its really worth the read.

Points -4
Comments 7
Views 57

.

Points 15
Comments 16
Views 305

My cat likes being combed

Points 1430
Comments 83
Views 33789

Why are you mugging me?!

Points 12
Comments 3
Views 140

Was playing FO4... God dammit Bethesda

Points 4
Comments 7
Views 59

What the hell am I doing with my life?

Points -7
Comments 2
Views 168

Trying to close meatspin

Points 10
Comments 2
Views 479

When someone asks why your reluctant to lend them your phone

Points 3
Comments 8
Views 172

living the student life

Points 5
Comments 17
Views 111

Lets play a game.

Points -2
Comments 25
Views 35

Snaked potato.

Points 63
Comments 12
Views 828

I don't know what I found, but I am sure it should not exist.

Points 16
Comments 11
Views 74

Still the 29th in the UK!

Points 11
Comments 0
Views 1

Maybe want to find a little bit of money? follow the instruction below

Points 10
Comments 1
Views 60

Baby danger floofs are kind of cute, in their own demon-spawn-of-hellish way

Points 19
Comments 7
Views 168

Imgur's reaction when I upload it wrong

Points -5
Comments 1
Views 13

100 pictures of pizzas

Points 21
Comments 4
Views 618

MFW I see the Front Page

Points 8
Comments 0
Views 0

Repeating the same joke, cause no one laughed the first time

Points 20
Comments 1
Views 11837

Are we still doing work stories? Here are some of my most memorable moments from my time as a rock.

Points 29
Comments 16
Views 1879

Merry Christmas, you filthy animal!

Points 9
Comments 1
Views 1759

The front page in a nutshell

Points 3
Comments 10
Views 160

I regret everything

Points -5
Comments 2
Views 108

Who needs drugs when you have fractals.

Points 63
Comments 13
Views 23623

What time is it?

Points 33
Comments 2
Views 191

My cat yawning.

Points 26
Comments 9
Views 119

I took a selfie with a big ol' black hole. Which is different I suppose.

Points 1
Comments 1
Views 82

My favorite gif of all time

Points 23
Comments 10
Views 1314

My bearded dragon dances when he wants to be let out of his tank.

Points 12
Comments 11
Views 312

To avoid accidental spoilers, get this plugin for chrome

Points 1
Comments 1
Views 70
Next page