Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualselve

Posted 21 November 2012 - 12:18 PM

Oh, sorry. Random numbers are defined here:
[source lang="cpp"]#define randx rand()*100%1175#define randy rand()*100%585[/source]

The whole code:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 && abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &&            ( mouseX >= ballposition.x &&                mouseX <= ballposition.x + ballposition.w ) &&                ( mouseY >= ballposition.y &&                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &&ballposition);        SDL_Flip(screen);    }}[/source]

The point of the game is just to click on the moving ball which causes increase of its speed.

#6selve

Posted 21 November 2012 - 12:00 PM

Oh, sorry. Random numbers are defined here:
[source lang="cpp"]#define randx rand()*100%1175#define randy rand()*100%585[/source]

The whole code:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 &amp;amp;amp;amp;&amp;amp;amp;amp; abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(&amp;amp;amp;amp;event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &amp;amp;amp;amp;&amp;amp;amp;amp;            ( mouseX >= ballposition.x &amp;amp;amp;amp;&amp;amp;amp;amp;                mouseX <= ballposition.x + ballposition.w ) &amp;amp;amp;amp;&amp;amp;amp;amp;                ( mouseY >= ballposition.y &amp;amp;amp;amp;&amp;amp;amp;amp;                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &amp;amp;amp;amp;ballposition);        SDL_Flip(screen);    }}[/source]

The point of the game is just to click on the moving ball which causes increase of its speed.

#5selve

Posted 21 November 2012 - 11:58 AM

Oh, sorry. Random numbers are defined here:
[source lang="cpp"]#define randx rand()*100%1175#define randy rand()*100%585[/source]

The whole code:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 &amp;amp;amp;&amp;amp;amp; abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(&amp;amp;amp;event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &amp;amp;amp;&amp;amp;amp;            ( mouseX >= ballposition.x &amp;amp;amp;&amp;amp;amp;                mouseX <= ballposition.x + ballposition.w ) &amp;amp;amp;&amp;amp;amp;                ( mouseY >= ballposition.y &amp;amp;amp;&amp;amp;amp;                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &amp;amp;amp;ballposition);        SDL_Flip(screen);    }}[/source]

#4selve

Posted 21 November 2012 - 11:57 AM

Oh, sorry. Random numbers are defined at these:
[source lang="cpp"]#define randx rand()*100%1175#define randy rand()*100%585[/source]

And here is the whole code:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 &amp;amp;&amp;amp; abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(&amp;amp;event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &amp;amp;&amp;amp;            ( mouseX >= ballposition.x &amp;amp;&amp;amp;                mouseX <= ballposition.x + ballposition.w ) &amp;amp;&amp;amp;                ( mouseY >= ballposition.y &amp;amp;&amp;amp;                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &amp;amp;ballposition);        SDL_Flip(screen);    }}[/source]

#3selve

Posted 21 November 2012 - 11:57 AM

Oh, sorry. Random numbers are defined at these:
[source lang="cpp"]#define randx rand()*100%1175#define randy rand()*100%585[/source]

And here is the whole code:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 &amp;amp;&amp;amp; abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(&amp;amp;event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &amp;amp;&amp;amp;            ( mouseX >= ballposition.x &amp;amp;&amp;amp;                mouseX <= ballposition.x + ballposition.w ) &amp;amp;&amp;amp;                ( mouseY >= ballposition.y &amp;amp;&amp;amp;                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &amp;amp;ballposition);        SDL_Flip(screen);    }}[/source]

#2selve

Posted 21 November 2012 - 11:55 AM

Oh, sorry. Random numbers are defined at the top:

[source lang="cpp"]#include "SDL/SDL.h"#include "SDL/SDL_ttf.h"#include "SDL/SDL_mixer.h"#include "SDL/SDL_image.h"#include <windows.h>#include <stdbool.h>#include <time.h>#define randx rand()*100%1175#define randy rand()*100%585using namespace std;SDL_Surface * screen;SDL_Surface * background;SDL_Surface * ball;SDL_Rect ballposition;SDL_Event event;int mouseX, mouseY;int ballX = randx, ballY = randy;int oldx, oldy;int ballspeed = 1;bool gameover = false;void moveBall(){    if(ballposition.x > ballX)    {        ballposition.x -= ballspeed;    }    if(ballposition.x < ballX)    {        ballposition.x += ballspeed;    }    if(ballposition.y > ballY)    {        ballposition.y -= ballspeed;    }    if(ballposition.y < ballY)    {        ballposition.y += ballspeed;    }}int main(int argc, char * args[]){    SDL_Init(SDL_INIT_EVERYTHING);    Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);    Mix_Chunk * click = Mix_LoadWAV("sounds/click.wav");    screen = SDL_SetVideoMode(1280, 720, 32, SDL_DOUBLEBUF | SDL_SWSURFACE);    background = IMG_Load("images/texture.jpg");    ball = IMG_Load("images/ball.png");    ballposition.x = 500;    ballposition.y = 400;    ballposition.h = 80;    ballposition.w = 80;    while(!gameover)    {        srand(time(NULL));        do        {            ballX = randx;            ballY = randy;        }while(abs(oldx-ballX) > 300 &amp;&amp; abs(oldy-ballY) > 300);        oldx = ballX;        oldy = ballY;        while(SDL_PollEvent(&amp;event))        {            if(event.type == SDL_QUIT)            {                SDL_Quit();                return 0;            }            if(event.type == SDL_MOUSEMOTION)            {                mouseX = event.motion.x;                mouseY = event.motion.y;            }            if(event.button.button == SDL_BUTTON_LEFT            &amp;&amp;            ( mouseX >= ballposition.x &amp;&amp;                mouseX <= ballposition.x + ballposition.w ) &amp;&amp;                ( mouseY >= ballposition.y &amp;&amp;                    mouseY <= ballposition.y + ballposition.h ) )            {                ballspeed++;                Mix_PlayChannel(0, click, 0);            }        }        moveBall();        SDL_BlitSurface(background, NULL, screen, NULL);        SDL_BlitSurface(ball, NULL, screen, &amp;ballposition);        SDL_Flip(screen);    }}[/source]

PARTNERS