Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Pong Multi Mode Version! Made by, Skaida or Nightblade
- Based on DesktopMan's original Pong game for gamecube.
- Special Thanks to:
- DesktopMan for his great Pong game :P
- WntrMute for his great support on setting up the compiller and other stuff(thx man!)
- And all of #gcdev for there great support (Thank You!)
- */
- // Change these to where you keep your libs
- #include "mygcn.h"
- #include ".\gfx\font.h"
- #include "main.h"
- #define COLOR_TRANSPARENT COLOR_WHITE // White is transparent (see sprite.bmp and sprite.raw.c)
- // Framebuffer
- u32* fb = (u32*)0xC0500000;
- PAD pad[3];
- // Paddle structs
- struct sprite{
- int x;
- int y;
- int width;
- int height;
- int points;
- }player[3];
- // Ball struct
- struct bsprite{
- int x;
- int y;
- int xspeed;
- int yspeed;
- }ball;
- //Variable Declarations
- int LastTouch;
- int PointCheck;
- int CheckA;
- // Function declarations
- void GetInput();
- void ClearScreen(int color);
- void BlitScreen();
- void MoveBall();
- int HitDet();
- void PrintNumber(int x,int y,int number);
- void RestartReady();
- int main()
- {
- // Init video in PAL mode, change this to your video-mode.
- VIDEO_Init(VIDEO_640X480_PAL60_YUV16);
- VIDEO_SetFrameBuffer(VIDEO_FRAMEBUFFER_BOTH,(u32)fb);
- // Init ball and players' pos.
- player[0].x=30;
- player[0].y=200;
- player[0].points=0;
- player[1].x=290;
- player[1].y=200;
- player[1].points=0;
- player[2].x=160;
- player[2].y=200;
- player[2].points=0;
- player[2].width=MONKEY_WIDTH;
- player[2].height=MONKEY_HEIGHT;
- ball.x=100;
- ball.y=100;
- ball.xspeed=4;
- ball.yspeed=6;
- LastTouch=0;
- PointCheck=1;
- CheckA=0;
- while(1) // Main game loop
- {
- VIDEO_WaitVSync(); // Wait for vblank
- PAD_ReadState(&pad[0], PAD_CHANNEL_0); // Read pads
- PAD_ReadState(&pad[1], PAD_CHANNEL_1);
- PAD_ReadState(&pad[2], PAD_CHANNEL_2);
- ClearScreen(COLOR_BLACK); // Paint the screen in black
- BlitScreen(); // Draw paddles and ball
- MoveBall(); // duh
- GetInput(); // duh
- }
- return 0;
- }
- void GetInput(){ // Controller input
- if(pad[0].Analog.Y>20&&player[0].y<400)
- player[0].y+=5;
- if(pad[1].Analog.Y>20&&player[1].y<400)
- player[1].y+=5;
- if(pad[2].Analog.Y>20&&player[2].y<400)
- player[2].y+=5;
- if(pad[2].Analog.X>20&&player[2].x<280)
- player[2].x+=5;
- if(pad[0].Analog.Y<-20&&player[0].y>20)
- player[0].y-=5;
- if(pad[1].Analog.Y<-20&&player[1].y>20)
- player[1].y-=5;
- if(pad[2].Analog.Y<-20&&player[2].y>20)
- player[2].y-=5;
- if(pad[2].Analog.X<-20&&player[2].x>40)
- player[2].x-=5;
- }
- void ClearScreen(int color){ // Clear the screen in a certain color
- int x,y;
- for(y=0;y<480;y++){
- for(x=0;x<320;x++){
- fb[x+320*y]=color;
- }
- }
- }
- void BlitScreen(){ // Draw everything
- int x,y;
- for(y=player[0].y;y<player[0].y+64;y++){
- for(x=player[0].x;x<player[0].x+8;x++)
- fb[x+320*y]=COLOR_RED;
- }
- for(y=player[1].y;y<player[1].y+64;y++){
- for(x=player[1].x;x<player[1].x+8;x++)
- fb[x+320*y]=COLOR_RED;
- }
- int bitmappos;
- for(y=player[2].y;y<player[2].y+player[2].height;y++){
- for(x=player[2].x;x<player[2].x+(player[2].width/2);x++){
- bitmappos=x-player[2].x+((y-player[2].y)*player[2].width)/2;
- fb[x+320*y]=monkey_Bitmap[bitmappos];
- }
- }
- for(y=ball.y;y<ball.y+8;y++){
- for(x=ball.x;x<ball.x+4;x++)
- fb[x+320*y]=COLOR_BLUE;
- }
- PrintNumber(20,30,player[0].points);
- PrintNumber(290,30,player[1].points);
- PrintNumber(135,30,player[2].points);
- }
- void MoveBall(){
- if(ball.y<=20)
- ball.yspeed=6;
- if(ball.y>=440)
- ball.yspeed=-6;
- if(ball.x<=20){
- ball.xspeed=4;
- player[1].points++;
- }
- if(ball.x>=312){
- ball.xspeed=-2;
- player[0].points++;
- }
- if(HitDet(player[0].x,player[0].y,16,64,ball.x,ball.y,8,8)){
- ball.xspeed=4;
- LastTouch=1;
- }
- if(HitDet(player[1].x,player[1].y,16,64,ball.x,ball.y,8,8)){
- ball.xspeed=-2;
- LastTouch=2;
- }
- if(HitDet(player[2].x,player[2].y,16,30,ball.x,ball.y,8,8)){
- ball.xspeed=0;
- ball.yspeed=0;
- }
- if(ball.xspeed==0&&ball.yspeed==0){
- DEBUG_InitText(fb, COLOR_WHITE);
- if(LastTouch==0){
- DEBUG_Print(15,150,"Player3, has been touched");
- DEBUG_Print(15,170,"player 1 and 2 Victorious!");
- DEBUG_Print(15,190," ");
- DEBUG_Print(15,210,"All players push A To Restart a new game");
- if(PointCheck==1){
- player[2].points=player[2].points+1;
- PointCheck=0;
- }
- }
- if(LastTouch==1){
- DEBUG_Print(15,150,"Player3, has been touched!");
- DEBUG_Print(15,170,"player 1 and 2 Victorious!");
- DEBUG_Print(15,190," ");
- DEBUG_Print(15,210,"All players push A To Restart a new game");
- if(PointCheck==1){
- player[2].points=player[2].points+1;
- PointCheck=0;
- }
- }
- if(LastTouch==2){
- DEBUG_Print(15,150,"Player3, has been touched!");
- DEBUG_Print(15,170,"player 1 and 2 Victorius!");
- DEBUG_Print(15,190," ");
- DEBUG_Print(15,210,"All players push A To Restart a new game");
- if(PointCheck==1){
- player[2].points=player[2].points+1;
- PointCheck=0;
- }
- }
- int temp1, temp2, temp3;
- temp1=0;
- temp2=0;
- temp3=0;
- if(pad[0].Digital.A){
- temp1=1;
- }
- if(pad[1].Digital.A){
- temp2=1;
- }
- if(pad[2].Digital.A){
- temp3=1;
- }
- int i;
- if(temp3==1){
- for (i = 0; i < 60*10; i++){
- VIDEO_WaitVSync();
- RENDER_ClearFrameBuffer(fb,0x00800080);
- DEBUG_Print(200,200,"Please wait restarting");
- player[0].x=30;
- player[0].y=200;
- player[1].x=290;
- player[1].y=200;
- player[2].x=160;
- player[2].y=200;
- ball.x=100;
- ball.y=100;
- ball.xspeed=2;
- ball.yspeed=4;
- LastTouch=0;
- PointCheck=1;
- }
- }
- }
- ball.x+=ball.xspeed;
- ball.y+=ball.yspeed;
- }
- int HitDet(int x1, int y1, int w1, int h1,int x2, int y2, int w2, int h2){ // Hit detection between two objects
- if(x1+w1>x2&&x1<x2+w2&&y1+h1>y2&&y1<y2+h2)
- return 1;
- return 0;
- }
- void PrintNumber(int x,int y,int number){ // No, scores over 100 is not supported, you sick pong addict :P
- int X,Y;
- u32 *font=(u32*)image;
- if(number<10){
- for(Y=y;Y<y+24;Y++){
- for(X=x;X<x+12;X++){
- fb[X+320*Y]=font[X-x+(Y-y)*12+number*24*12];
- }
- }
- }
- else{
- int num1,num2;
- num1=number/10;
- num2=number-num1*10;
- for(Y=y;Y<y+24;Y++){
- for(X=x;X<x+12;X++){
- fb[X+320*Y]=font[X-x+(Y-y)*12+num1*24*12];
- }
- }
- for(Y=y;Y<y+24;Y++){
- for(X=x;X<x+12;X++){
- fb[X+13+320*Y]=font[X-x+(Y-y)*12+num2*24*12];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement