C++ Simple Fighter Game Help menu

User Tag List

Results 1 to 3 of 3
  1. #1
    Fireking300's Avatar Active Member
    Reputation
    27
    Join Date
    Jun 2007
    Posts
    92
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C++ Simple Fighter Game Help

    Code:
    #include <iostream>
    #include <time.h>
    #include <cstdlib>
    using namespace std;
    
    void collision();
    void endmatch();
    void playerwin();
    int damage(int health, int taken);
    
    int health = 100;
    
    void main()
    {
    		
    }
    
    void collision()
    {
    	
    }
    
    void endmatch()
    {
    	
    }
    
    int damage(int health, int taken)
    {
    	health = health - taken;
    	return health;
    }
    I don't know how to do Classes yet. So Could anyone help me? I want to define opponent and player. Like opponent.health and player.health.
    This is just going to be the backend of the game it will be a 2d game eventually.
    So any additional help would be appreciated with +Rep x2

    C++ Simple Fighter Game Help
  2. #2
    Molleren's Avatar Member
    Reputation
    2
    Join Date
    Nov 2007
    Posts
    58
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a part from my own little game in C++ using SDL.
    Code:
    class Player
    {
        private:
        //animations
        int frame;
        int dir;
    
        //X and Y offset of player
        int x, y;
    
        //Velocity
        int xVel, yVel;
    
        //Animation status
        int status;
    
        public:
        //Initiliaze
        Player();
    
        //STATS
        int statSpeed;
        int statHP;
    
        //Key presses
        void handle_input();
    
        //Move player
        void move(Tile *tiles[]);
    
        //Jump
        void jump();
    
        //Show player
        void show();
    
        //scrolling map
        void set_camera();
    };
    And all the initializing for every void etc.

    Code:
    //PLAYER VARIABLES//
    Player::Player()
    {
        //Initilaze offsets
        x = SCREEN_WIDTH / 2; //CENTER
        y = GROUNDY; //ON GROUND
    
        //Initialize velocity
        xVel = 0;
        yVel = 0;
    
        //Animation status
        frame = 0;
        status = PLR_LEFT;
    
        //STATS
        statSpeed = 32;
        statHP = 100;
    }
    
    void Player::handle_input()
    {
        //If key was pressed
        if (event.type == SDL_KEYDOWN)
        {
            //adjust velocity
            switch (event.key.keysym.sym)
            {
                case SDLK_UP: yVel -= statSpeed; break; //PLR_HEIGHT / 2; break;
                case SDLK_DOWN: yVel += statSpeed; break; //PLR_HEIGHT / 2; break;
                case SDLK_LEFT: 
                    xVel -= statSpeed; break;
                    //dir = PLR_LEFT; break; //PLR_WIDTH / 2; break;
                case SDLK_RIGHT: 
                    xVel += statSpeed; break;
                    //dir = PLR_RIGHT; break;//PLR_WIDTH / 2; break;
            }
        }
        //If key released
        else if (event.type == SDL_KEYUP)
        {
            //adjust velocity
            switch (event.key.keysym.sym)
            {
                case SDLK_UP: yVel += statSpeed; break;//PLR_HEIGHT / 2; break;
                case SDLK_DOWN: yVel -= statSpeed; break;//PLR_HEIGHT / 2; break;
                case SDLK_LEFT: xVel += statSpeed; break;
                        //dir = PLR_LEFT; break;//PLR_WIDTH / 2; break;
                case SDLK_RIGHT: xVel -= statSpeed; break;
                        //dir = PLR_RIGHT; break;//PLR_WIDTH / 2; break;
            }
        }
    }
    
    void Player::move()
    {
        //move left or right
        x += xVel;
    
        //If dot is too far to the left or right
        if ( (x < 0) || (x + PLR_WIDTH > SCREEN_WIDTH) )
        {
            //move back
            x -= xVel;
        }
    
        //Move up or down
        y += yVel;
    
        //if player is too far up or down
        if ( (y < 0) || (y + PLR_HEIGHT > SCREEN_HEIGHT) )
        {
            //move back
            y -= yVel;
        }
        
        /*if (y < GROUNDY)
        {
            yVel += 1;
            jumping = true;
        }
        else
        {
            yVel = 0;
            y = GROUNDY;
            jumping = false;
            jumpCount = 2;
        }
        y += yVel;*/
    
            //if player is too far up or down
        if ( (y < 0) || (y + PLR_HEIGHT >= SCREEN_HEIGHT) )
        {
            //move back
            y -= yVel;
        }
    }
    
    void Player::show()
    {
    
        //Moving left
        if (xVel < 0)
        {
            status = PLR_LEFT;
            frame++;
        }
        else if (xVel > 0) //Moving right
        {
            status = PLR_RIGHT;
            frame++;
        }
        else if (yVel < 0) //moving up
        {
            status = PLR_UP;
            frame++;
        }
        else if (yVel > 0) //moving down
        {
            status = PLR_DOWN;
            frame++;
        }
        
        //ANIMATION
        if (frame >= 3)
        {
            frame = 0;
        }
    
        if (status == PLR_RIGHT)
        {
            apply_surface(x,  y, playerSprite, screen, &clipsRight[frame]);
        }
        else if (status == PLR_LEFT)
        {
            apply_surface(x, y, playerSprite, screen, &clipsLeft[frame]);
        }
        else if (status == PLR_UP)
        {
            apply_surface(x, y, playerSprite, screen, &clipsUp[frame]);
        }
        else if (status == PLR_DOWN)
        {
            apply_surface(x, y, playerSprite, screen, &clipsDown[frame]);
        }
    }

  3. #3
    Pragma's Avatar Contributor
    Reputation
    261
    Join Date
    Feb 2007
    Posts
    630
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really would suggest learning the basics of C++ before trying this. cprogramming.com is not bad, they have lots of beginner tutorials including one for classes. They even go into the more advanced like 3D rendering.


Similar Threads

  1. Simple LUA Script Help
    By Wolfly in forum WoW EMU Questions & Requests
    Replies: 7
    Last Post: 09-02-2008, 04:22 PM
  2. simple problem need help please..
    By glitch in forum World of Warcraft Emulator Servers
    Replies: 7
    Last Post: 02-24-2008, 09:51 AM
All times are GMT -5. The time now is 02:17 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search