Jump to content

  • Log In with Google      Sign In   
  • Create Account


KotoR`eZ

Member Since 24 Apr 2013
Online Last Active Yesterday, 11:51 PM
-----

Topics I've Started

SDL Keyboard input

06 July 2014 - 05:34 PM

Basically the problem in my program is when I move my character for example North/East and I hold W and D at the same time my character goes it a correct direction but when I let go W and continue holding D my character moves in D direction but it only plays the first frame of W animation for 1-2 seconds before switching to the W animation. Also when I was trying to "debug" the program I wrote some couts for which animation gets called (ACTIVE/IDLE) and I noticed that when I press move my active animation sometimes gets called 5 times but when ever I release the button the Idle animation gets called about 20-30 times. Can somebody please explain to me this behavior and also is there "industry standard" on setting up keyboard input? I was following lazyfoo's tutorials but those dont explain much in details.


void Game::GameLoop()

{


    while (!quit && sdl_setup->GetMainEvent()->type != SDL_QUIT)

    {

        sdl_setup->Begin();

        walkingGround->Draw();


        player->Draw();


        //float angle = atan2(Follow_Point_Y - player->GetY(), Follow_PointX - player->GetX());

        //angle = angle * (180/3.14);


        if(sdl_setup->GetMainEvent()->type == SDL_KEYDOWN)

        {

            switch(sdl_setup->GetMainEvent()->key.keysym.sym)

            {

            case SDLK_w:

                moveUp = true;

                break;

            case SDLK_s:

                moveDown = true;

                break;

            case SDLK_a:

                moveLeft = true;

                break;

            case SDLK_d:

                moveRight = true;

                break;

            default:

                break;

            }

        }

        if(sdl_setup->GetMainEvent()->type == SDL_KEYUP)

        {

            switch(sdl_setup->GetMainEvent()->key.keysym.sym )

            {

            case SDLK_w:

                std::cout GetX() + 1);

               // moveRight = false;

            }

	}

        sdl_setup->End();

    }

}


Small inventory system Java (Novice)

07 March 2014 - 12:20 PM

Hello I am learning JAVA and I am currently practicing arrays. Basically what I am trying to write is a small inventory management system with just arrays for my small RPG(no saves). I am stuck on the part where I have to put items from main table of items that exist in the entire game, into the limited space of the backpack. I cant seem to figure out how to insert items from "Item array" into "Backpack array" just by using reference ID which is also happens to be array index.


Here is my code: http://pastebin.com/wKSu5UD1


    //IMS Main class//

    class IMS {
        public static void main(String[] arguments) {
            Item product = new Item();
            Inventory backpack = new Inventory();
            product.createItem("Boots", 325, 1);  
            product.createItem("Sword", 410, 3);  
            product.createItem("Ring", 110, 2);  
            product.createItem("Dagger", 240, 2);  
            product.createItem("Bow", 810, 1);

            product.displayItemList();

            backpack.setMaxInventory(5);

        }
    }


    // Item class //

    class Item {
        //Maximum Items allowed
        private int maxItems = 5;
        Item[] itemDB = new Item[maxItems];

        //Item related
        private int id;
        String name;
        int price;
        int quantity;

        Item(){
            id = 0;
        }

        private Item(String name, int price, int quantity){
            this.name = name;
            this.price = price;
            this.quantity = quantity;
        }

        private void idAutoIncrement(){    
            id = id + 1;
        }

        private void setItemID(){
            itemDB[id].id = id;
        }

        void createItem(String name, int price, int quantity){
           if (id < maxItems){        
                itemDB[id] = new Item(name, price, quantity);
                setItemID();
                idAutoIncrement();
           } else {
               System.out.println("You have riched the maximum item limit.");
           }
        }

        void queryItem(int id){
            System.out.println(itemDB[id].id + " " + itemDB[id].name + " " +
                    itemDB[id].price + " " + itemDB[id].quantity);
        }

        void displayItemList(){
            System.out.println("ID " + "Name " + "Price " + "Quantity ");
            for (int i = 0; i < id; i++){
                System.out.println(itemDB[i].id + " " + itemDB[i].name + " " +
                        itemDB[i].price + " " + itemDB[i].quantity);
            }
        }
    }

    // Inventory class //

    class Inventory {
        private int invSize;
        Inventory [] backpack;
        Item item;

        //item related
        private int id;
        String name;
        int itemsInStack;


        Inventory(){
            invSize = 2;
        }

        void addItem(int id, String name, int itemsInStack){
            // ---- part where i am stuck //
        }

        void setMaxInventory(int invSize){
            this.invSize = invSize;
            backpack = new Inventory[invSize];
        }

        void putInside(int id){
            // ---- part where i am stuck //
           // backpack[id] = new addItem(            );  
        }

    }



Can you guys please glance at it and tell me if I am even on the right track? Also, suppose I created a sword class that adds +str +stamina etc properties and I want to put it into an item array. How would I put it into a main item array (is it even possible or I am over thinking it)?

Thanks

Snake game help

08 May 2013 - 06:16 AM

Hello, I am trying to do a snake game and I am stuck on the step where I have to make a game loop. I want my snake to move automatically until it hits the wall or user steers it into a different direction. I tried to make a function "playerAutomove" that records the user's last move so the game loop knows where the snake turned (up,down,left,right) but it seems like no matter what I do the program will stop and wait for user's key press, similar to "cin". I just need a suggestion, you dont have to give me the exact code. :) This is what I have so far. The code should compile under c++11 if you just copy/paste. I used only default libraries that c++ comes with. http://pastebin.com/g05vYALt Thanks

Pointer question

29 April 2013 - 10:56 AM

Hello,

I am writing my first dungeon crawl game and I stumbled upon strange program behavior.

http://pastebin.com/ZVvmVdbf

    Board_level board;
    PlayerOn_Board player(0,0);
    board.setValues(20,20);
    //player.setPosition(10, 15);
    cout << player.returnX() << " " << player.returnY() << endl;

When I do "board.setValues(20,20)", player.returnX() and player.returnY() return 20s. I am expecting them both to be equal to zero since I declare them as zero and dont do any assigning. For some reason board object overwrites my player object. Can somebody please explain to my why it happens. I spent couple of hours trying to understand this.

Thanks

PARTNERS