Sunday 26 May 2013

Mario & Luigi

 I referred to a picture at http://alexno.com/super-mario/pixel-mario/ for Mario.

For Luigi, it's the same pattern, except change colours from red to green (from 12 to 10....find and replace).
There may be better ways to do this, but i don't know, maybe i'll learn later.



<─ This is what it displays.







Here is the code (I still dont understand how the colours thing works):

/*Program to display ASCII Mario & Luigi */

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <windows.h>

#define TRUE 1
#define FALSE !TRUE


void SetColorAndBackground(int ForgC, int BackC);
void green(int c);
void grey(int d);
void flesh(int e);
void black(int f);
void red(int h);
void nl(int g);
void luigi(void);
void mario(void);

int x,y=176,z,state;

main()
{
    state=TRUE;
    while(state)
    {
        char k;
        system("cls");
        printf("A: Mario\nB: Luigi\nC: Both\nD: Exit\n");
        printf("Choice: ");
        k=toupper(getch());

        if (k=='A' || k=='B' || k=='C' || k=='D')
        {
            if(k=='A')
            {
                system("cls");
                mario();
                SetColorAndBackground(7,0);
                getch();
            }
            else if(k=='B')
            {
                system("cls");
                luigi();
                SetColorAndBackground(7,0);
                getch();
            }
            else if(k=='C')
            {
                system("cls");
                mario();
                nl(1);
                luigi();
                SetColorAndBackground(7,0);
                getch();
            }
            else if(k=='D')
            {
                system("cls");
                SetColorAndBackground(7,0);
                state=FALSE;
            }
        }
    }
}

void mario(void)      /*This took a while to figure and write. Run, compare between
                                 Output and picture at http://alexno.com/super-mario/pixel-mario/ 
                                 and put in a few more or remove a few*/
{
    black(6);
    red(8);
    black(6);
    nl(1);

    black(4);
    red(14);
    nl(1);

    black(4);
    grey(6);
    flesh(3);
    grey(1);
    flesh(1);
    nl(1);

    black(2);
    grey(2);
    flesh(2);
    grey(2);
    flesh(5);
    grey(1);
    flesh(3);
    nl(1);

    black(2);
    grey(2);
    flesh(2);
    grey(4);
    flesh(4);
    grey(1);
    flesh(4);
    nl(1);

    black(2);
    grey(4);
    flesh(7);
    grey(4);
    nl(1);

    black(6);
    flesh(10);
    nl(1);

    black(4);
    grey(3);
    red(1);
    grey(6);
    nl(1);

    black(2);
    grey(5);
    red(1);
    grey(5);
    red(1);
    grey(4);
    nl(1);

    grey(7);
    red(7);
    grey(6);
    nl(1);

    flesh(4);
    grey(2);
    red(1);
    flesh(2);
    red(3);
    flesh(2);
    red(1);
    grey(1);
    flesh(4);
    nl(1);

    flesh(6);
    red(1);
    flesh(2);
    red(3);
    flesh(2);
    red(1);
    flesh(5);
    nl(1);

    flesh(4);
    red(10);
    red(2);
    flesh(4);
    nl(1);

    black(4);
    red(5);
    black(2);
    red(5);
    nl(1);

    black(2);
    grey(6);
    black(4);
    grey(6);
    nl(1);

    grey(8);
    black(4);
    grey(8);
    nl(1);
}
void luigi(void)
{
    black(6);
    green(8);
    black(6);
    nl(1);

    black(4);
    green(14);
    nl(1);

    black(4);
    grey(6);
    flesh(3);
    grey(1);
    flesh(1);
    nl(1);

    black(2);
    grey(2);
    flesh(2);
    grey(2);
    flesh(5);
    grey(1);
    flesh(3);
    nl(1);

    black(2);
    grey(2);
    flesh(2);
    grey(4);
    flesh(4);
    grey(1);
    flesh(4);
    nl(1);

    black(2);
    grey(4);
    flesh(7);
    grey(4);
    nl(1);

    black(6);
    flesh(10);
    nl(1);

    black(4);
    grey(3);
    green(1);
    grey(6);
    nl(1);

    black(2);
    grey(5);
    green(1);
    grey(5);
    green(1);
    grey(4);
    nl(1);

    grey(7);
    green(7);
    grey(6);
    nl(1);

    flesh(4);
    grey(2);
    green(1);
    flesh(2);
    green(3);
    flesh(2);
    green(1);
    grey(1);
    flesh(4);
    nl(1);

    flesh(6);
    green(1);
    flesh(2);
    green(3);
    flesh(2);
    green(1);
    flesh(5);
    nl(1);

    flesh(4);
    green(10);
    green(2);
    flesh(4);
    nl(1);

    black(4);
    green(5);
    black(2);
    green(5);
    nl(1);

    black(2);
    grey(6);
    black(4);
    grey(6);
    nl(1);

    grey(8);
    black(4);
    grey(8);
    nl(1);
}

void SetColorAndBackground(int ForgC, int BackC)
{
     WORD wColor=((BackC&0x0F)<<4)+(ForgC & 0x0F);;
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wColor);
     return;
}

void green(int c)
{
    SetColorAndBackground(10,0);
    for(z=0;z<c;z++)
    {
        printf("%c",y);
    }
}

void grey(int d)
{
    SetColorAndBackground(6,0);
    for(z=0;z<d;z++)
    {
        printf("%c",y);
    }
}

void flesh(int e)
{
    SetColorAndBackground(14,0);
    for(z=0;z<e;z++)
    {
        printf("%c",y);
    }
}

void black(int f)
{
    SetColorAndBackground(0,0);
    for(z=0;z<f;z++)
    {
        printf("%c",y);
    }
}

void red(int h)
{
    SetColorAndBackground(12,0);
    for(z=0;z<h;z++)
    {
        printf("%c",y);
    }
}

void nl(int g)
{
    for(z=0;z<g;z++)
    {
        printf("\n");
    }
}
_______________________________________
That's the code there. Try it out.

No comments:

Post a Comment