Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. /*
  2. Pong Multi Mode Version! Made by, Skaida or Nightblade
  3. Based on DesktopMan's original Pong game for gamecube.
  4. Special Thanks to:
  5. DesktopMan for his great Pong game :P
  6. WntrMute for his great support on setting up the compiller and other stuff(thx man!)
  7. And all of #gcdev for there great support (Thank You!)
  8. */
  9.  
  10. // Change these to where you keep your libs
  11.  
  12. #include "mygcn.h"
  13. #include ".\gfx\font.h"
  14. #include "main.h"
  15.  
  16.  
  17. #define COLOR_TRANSPARENT COLOR_WHITE // White is transparent (see sprite.bmp and sprite.raw.c)
  18.  
  19. // Framebuffer
  20. u32* fb = (u32*)0xC0500000;
  21.  
  22. PAD pad[3];
  23.  
  24. // Paddle structs
  25. struct sprite{
  26. int x;
  27. int y;
  28. int width;
  29. int height;
  30. int points;
  31. }player[3];
  32.  
  33. // Ball struct
  34. struct bsprite{
  35. int x;
  36. int y;
  37. int xspeed;
  38. int yspeed;
  39. }ball;
  40.  
  41. //Variable Declarations
  42. int LastTouch;
  43. int PointCheck;
  44. int CheckA;
  45.  
  46.  
  47. // Function declarations
  48. void GetInput();
  49. void ClearScreen(int color);
  50. void BlitScreen();
  51. void MoveBall();
  52. int HitDet();
  53. void PrintNumber(int x,int y,int number);
  54. void RestartReady();
  55.  
  56. int main()
  57. {
  58. // Init video in PAL mode, change this to your video-mode.
  59. VIDEO_Init(VIDEO_640X480_PAL60_YUV16);
  60. VIDEO_SetFrameBuffer(VIDEO_FRAMEBUFFER_BOTH,(u32)fb);
  61.  
  62. // Init ball and players' pos.
  63. player[0].x=30;
  64. player[0].y=200;
  65. player[0].points=0;
  66.  
  67. player[1].x=290;
  68. player[1].y=200;
  69. player[1].points=0;
  70.  
  71. player[2].x=160;
  72. player[2].y=200;
  73. player[2].points=0;
  74. player[2].width=MONKEY_WIDTH;
  75. player[2].height=MONKEY_HEIGHT;
  76.  
  77. ball.x=100;
  78. ball.y=100;
  79. ball.xspeed=4;
  80. ball.yspeed=6;
  81.  
  82. LastTouch=0;
  83. PointCheck=1;
  84. CheckA=0;
  85.  
  86.  
  87.  
  88. while(1) // Main game loop
  89. {
  90. VIDEO_WaitVSync(); // Wait for vblank
  91. PAD_ReadState(&pad[0], PAD_CHANNEL_0); // Read pads
  92. PAD_ReadState(&pad[1], PAD_CHANNEL_1);
  93. PAD_ReadState(&pad[2], PAD_CHANNEL_2);
  94.  
  95. ClearScreen(COLOR_BLACK); // Paint the screen in black
  96.  
  97. BlitScreen(); // Draw paddles and ball
  98. MoveBall(); // duh
  99. GetInput(); // duh
  100.  
  101. }
  102. return 0;
  103. }
  104.  
  105. void GetInput(){ // Controller input
  106. if(pad[0].Analog.Y>20&&player[0].y<400)
  107. player[0].y+=5;
  108.  
  109. if(pad[1].Analog.Y>20&&player[1].y<400)
  110. player[1].y+=5;
  111.  
  112. if(pad[2].Analog.Y>20&&player[2].y<400)
  113. player[2].y+=5;
  114.  
  115. if(pad[2].Analog.X>20&&player[2].x<280)
  116. player[2].x+=5;
  117.  
  118.  
  119. if(pad[0].Analog.Y<-20&&player[0].y>20)
  120. player[0].y-=5;
  121.  
  122. if(pad[1].Analog.Y<-20&&player[1].y>20)
  123. player[1].y-=5;
  124.  
  125. if(pad[2].Analog.Y<-20&&player[2].y>20)
  126. player[2].y-=5;
  127.  
  128. if(pad[2].Analog.X<-20&&player[2].x>40)
  129. player[2].x-=5;
  130.  
  131. }
  132.  
  133. void ClearScreen(int color){ // Clear the screen in a certain color
  134. int x,y;
  135.  
  136. for(y=0;y<480;y++){
  137. for(x=0;x<320;x++){
  138. fb[x+320*y]=color;
  139. }
  140. }
  141. }
  142.  
  143. void BlitScreen(){ // Draw everything
  144. int x,y;
  145. for(y=player[0].y;y<player[0].y+64;y++){
  146. for(x=player[0].x;x<player[0].x+8;x++)
  147. fb[x+320*y]=COLOR_RED;
  148. }
  149.  
  150. for(y=player[1].y;y<player[1].y+64;y++){
  151. for(x=player[1].x;x<player[1].x+8;x++)
  152. fb[x+320*y]=COLOR_RED;
  153. }
  154. int bitmappos;
  155. for(y=player[2].y;y<player[2].y+player[2].height;y++){
  156. for(x=player[2].x;x<player[2].x+(player[2].width/2);x++){
  157. bitmappos=x-player[2].x+((y-player[2].y)*player[2].width)/2;
  158. fb[x+320*y]=monkey_Bitmap[bitmappos];
  159. }
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. for(y=ball.y;y<ball.y+8;y++){
  167. for(x=ball.x;x<ball.x+4;x++)
  168. fb[x+320*y]=COLOR_BLUE;
  169. }
  170. PrintNumber(20,30,player[0].points);
  171. PrintNumber(290,30,player[1].points);
  172. PrintNumber(135,30,player[2].points);
  173. }
  174.  
  175. void MoveBall(){
  176. if(ball.y<=20)
  177. ball.yspeed=6;
  178. if(ball.y>=440)
  179. ball.yspeed=-6;
  180. if(ball.x<=20){
  181. ball.xspeed=4;
  182. player[1].points++;
  183. }
  184. if(ball.x>=312){
  185. ball.xspeed=-2;
  186. player[0].points++;
  187.  
  188.  
  189.  
  190. }
  191.  
  192. if(HitDet(player[0].x,player[0].y,16,64,ball.x,ball.y,8,8)){
  193. ball.xspeed=4;
  194. LastTouch=1;
  195. }
  196.  
  197. if(HitDet(player[1].x,player[1].y,16,64,ball.x,ball.y,8,8)){
  198. ball.xspeed=-2;
  199. LastTouch=2;
  200. }
  201.  
  202. if(HitDet(player[2].x,player[2].y,16,30,ball.x,ball.y,8,8)){
  203. ball.xspeed=0;
  204. ball.yspeed=0;
  205. }
  206. if(ball.xspeed==0&&ball.yspeed==0){
  207. DEBUG_InitText(fb, COLOR_WHITE);
  208. if(LastTouch==0){
  209. DEBUG_Print(15,150,"Player3, has been touched");
  210. DEBUG_Print(15,170,"player 1 and 2 Victorious!");
  211. DEBUG_Print(15,190," ");
  212. DEBUG_Print(15,210,"All players push A To Restart a new game");
  213. if(PointCheck==1){
  214. player[2].points=player[2].points+1;
  215. PointCheck=0;
  216. }
  217. }
  218. if(LastTouch==1){
  219. DEBUG_Print(15,150,"Player3, has been touched!");
  220. DEBUG_Print(15,170,"player 1 and 2 Victorious!");
  221. DEBUG_Print(15,190," ");
  222. DEBUG_Print(15,210,"All players push A To Restart a new game");
  223. if(PointCheck==1){
  224. player[2].points=player[2].points+1;
  225. PointCheck=0;
  226. }
  227. }
  228. if(LastTouch==2){
  229. DEBUG_Print(15,150,"Player3, has been touched!");
  230. DEBUG_Print(15,170,"player 1 and 2 Victorius!");
  231. DEBUG_Print(15,190," ");
  232. DEBUG_Print(15,210,"All players push A To Restart a new game");
  233. if(PointCheck==1){
  234. player[2].points=player[2].points+1;
  235. PointCheck=0;
  236. }
  237. }
  238. int temp1, temp2, temp3;
  239. temp1=0;
  240. temp2=0;
  241. temp3=0;
  242. if(pad[0].Digital.A){
  243. temp1=1;
  244. }
  245. if(pad[1].Digital.A){
  246. temp2=1;
  247. }
  248. if(pad[2].Digital.A){
  249. temp3=1;
  250. }
  251. int i;
  252. if(temp3==1){
  253. for (i = 0; i < 60*10; i++){
  254. VIDEO_WaitVSync();
  255. RENDER_ClearFrameBuffer(fb,0x00800080);
  256. DEBUG_Print(200,200,"Please wait restarting");
  257. player[0].x=30;
  258. player[0].y=200;
  259.  
  260. player[1].x=290;
  261. player[1].y=200;
  262.  
  263. player[2].x=160;
  264. player[2].y=200;
  265.  
  266. ball.x=100;
  267. ball.y=100;
  268. ball.xspeed=2;
  269. ball.yspeed=4;
  270.  
  271. LastTouch=0;
  272. PointCheck=1;
  273. }
  274. }
  275. }
  276.  
  277. ball.x+=ball.xspeed;
  278. ball.y+=ball.yspeed;
  279. }
  280.  
  281. int HitDet(int x1, int y1, int w1, int h1,int x2, int y2, int w2, int h2){ // Hit detection between two objects
  282. if(x1+w1>x2&&x1<x2+w2&&y1+h1>y2&&y1<y2+h2)
  283. return 1;
  284. return 0;
  285. }
  286.  
  287. void PrintNumber(int x,int y,int number){ // No, scores over 100 is not supported, you sick pong addict :P
  288. int X,Y;
  289. u32 *font=(u32*)image;
  290. if(number<10){
  291. for(Y=y;Y<y+24;Y++){
  292. for(X=x;X<x+12;X++){
  293. fb[X+320*Y]=font[X-x+(Y-y)*12+number*24*12];
  294. }
  295. }
  296. }
  297. else{
  298. int num1,num2;
  299. num1=number/10;
  300. num2=number-num1*10;
  301.  
  302. for(Y=y;Y<y+24;Y++){
  303. for(X=x;X<x+12;X++){
  304. fb[X+320*Y]=font[X-x+(Y-y)*12+num1*24*12];
  305. }
  306. }
  307.  
  308. for(Y=y;Y<y+24;Y++){
  309. for(X=x;X<x+12;X++){
  310. fb[X+13+320*Y]=font[X-x+(Y-y)*12+num2*24*12];
  311. }
  312. }
  313. }
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement