The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C++ Code
Posted by: tommy2002 | July 6, 2009 @ 12:10am
C++ Code
[
Download
]
#include <iostream> #include "objects.h" #include "SDL/SDL.h" #include "SDL/SDL_draw.h" SDL_Surface* window = NULL; SDL_Event event; bool quit = false; ball one; paddle player; int update(int background_color, int paddle_color, SDL_Rect background) { if (SDL_FillRect(window,&background,background_color) == -1) { return 1; } Draw_FillCircle(window,one.x,one.y,10,paddle_color); player.pad.y += player.velocity; if (player.pad.y < 0) { player.pad.y = 0; } if (player.pad.y > 400) { player.pad.y = 400; } if (SDL_FillRect(window,&player.pad,paddle_color) == -1) { return 1; } if (SDL_Flip(window) == -1) { return 1; } return 0; } int main() { if (SDL_Init(SDL_INIT_EVERYTHING) == -1) { return 1; } window = SDL_SetVideoMode(620, 470, 32, SDL_SWSURFACE); if (window == NULL) { return 1; } int background_color = SDL_MapRGB(window->format,23,54,200); SDL_Rect background; background.x = 0; background.y = 0; background.w = 620; background.h = 470; int paddle_color = SDL_MapRGB(window->format, 235,4,55); SDL_WM_SetCaption("Ping",NULL); int begin = 0; while (quit == false) { begin = SDL_GetTicks(); while(SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_UP: player.velocity -= 5; break; case SDLK_DOWN: player.velocity += 5; break; default: break; } } if (event.type == SDL_KEYUP) { switch (event.key.keysym.sym) { case SDLK_UP: player.velocity += 5; break; case SDLK_DOWN: player.velocity -= 5; break; default: break; } } if (event.type == SDL_QUIT) { quit = true; } } if(update(background_color, paddle_color, background) == 1) { return 0; } if ((SDL_GetTicks() - begin) < 20) { SDL_Delay(20 - SDL_GetTicks() + begin); } } SDL_Quit(); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
Draw_FillCircle is causing the segfault
Rating
4.23 / 8
77 Votes
http://codebin.yi.org/323
page generated in 0.01 seconds