Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


KotoR`eZ

Member Since 24 Apr 2013
Offline Last Active Jun 30 2015 06:29 PM

Topics I've Started

Need suggestion

06 January 2015 - 09:42 AM

I need a suggestion on how to load multiple images in SDL. All of the games I did before for practice had 1-5 surfaces where I could load an image and move it around. Now lets assume I am making a typing tutor where every letter has its own pretty image. Does it mean I would have to load A B C D..... Z surfaces into the game such as:

 

SDL_Surface* A = NULL;
SDL_Surface* B= NULL;
SDL_Surface* C = NULL;

 

A = LoadImage("graphics/A.bmp");

B = LoadImage("graphics/B.bmp");

C = LoadImage("graphics/C.bmp");

....

Z = LoadImage("graphics/Z.bmp");
 

I know that for the example with alphabet I can just load one image and then cut it up like a sprite but what if I have 100 images that are completely idepandant. Creating 100 surfaces seems wrong. Is there a proper way of doing it?

I was thinking of making a map and loading a proper image path only when I request a specific image key but wouldnt it slow down my program?


Logic question

25 December 2014 - 09:52 PM

I am coding the game and I am a bit stuck on how to handle collisions. Here is how it works:

 

You have three buttons for example A, B, C.  A = 1, B = 2, C = 3. If I press ABC, the sum would be 1 + 2 + 3 = 6. After the total calculation I will use total value as a key and fetch the data from the map. Here is were I am a bit stuck. When I do BBB = 6 and ABC = 6 I get a conflict or AAC = 5 and BBA = 5. How do I avoid these collisions. I dont mind rewriting the entire thing but I am pretty sure there are some kind of techniques on handling these kind of problems.

 

Thanks.


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

PARTNERS