Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Scrolling Game

  1. #1

    Post Scrolling Game

    Hi Delta,

    I was thinking of finally doing a game and was wanting to do the scrolling like in Dizzy Legends and Rock Dash Dizzy.

    I found a thread from Dizzy Legends

    http://www.yolkfolk.com/bb/showthrea...=9688#post9688

    is this the code used in Rock Dash Dizzy too?

    I would like to move blocks around the screen too, would this be possible?

    Quote Originally Posted by delta View Post
    Meph, i'm guessing you have Vista.

    People with vista seem to have more trouble with it flickering, even when their computer is high spec like yours.

    ah well, 'tis all solved now with Alex integrating scrolling as an option in v2.3 of DizzyAGE!

    so as he's done that, i'll explain how i did the scrolling in my scroll demo (if anyone is interested!!).

    basically i realised when coding BTD that i could change a lot of brushes en-mass, by doing a For loop from 0 up to BrushCount(). this allowed me in BTD to change the colour of every brush in the game. (BrushCount() counts the number of brushes in the map)

    now it occurred to me a while back that there was a similar code for objects, ObjCount().and that if i could change the colour of all the brushes in BTD, there should be no reason at all why i couldn't change the X or Y values of all the objects in a map.

    Two problems then arise. firstly you can't move static brushes (the block material). this means that in TLoD you'd be able to walk through walls, and in classic Dizzy games, that you'd fall through the map. The second problem is getting Dizzy to stay still while the entire map is moved.

    the second problem was the easiest to solve. i simply wrote a new function:

    Code:
    func Scroll_Screen(dirx,diry)
    {
        //set all objects to new location
            for(i=0;i < ObjCount();i++)
            {
                    if(dirx==-1) { ObjSet(i,O_X,ObjGet(i,O_X)+CM_SMLMOVE); }
                    if(dirx==1) { ObjSet(i,O_X,ObjGet(i,O_X)-CM_SMLMOVE); }
                    if(diry==-1) { ObjSet(i,O_Y,ObjGet(i,O_Y)+CM_SMLMOVE); }
                    if(diry==1) { ObjSet(i,O_Y,ObjGet(i,O_Y)-CM_SMLMOVE); }
            }
        ObjPresentGather();
    }
    then called this function, instead of the code that moves dizzy. As you may be able to see, this function loops through *every single object in the map* and moves it up, down, left or right, depending on what the input is. This is what causes the slow-down and flickering on slow (and vista) computers.

    The function is called by replacing this (TLoD-specific up-movement coding):

    Code:
        PlayerSet(P_Y, PlayerGet(P_Y)-CM_SMLMOVE);
    with this:

    Code:
        Scroll_Screen(0,-1);
    That's the easy bit. The problem then is that there are no static brushes at all in the map. this means that walls can be walked through. To counter this, i defined Object Property 45 thus:

    Code:
    #def O_BLOCK        45        // 2 = block but can drop items 1 = block and can't drop items, 0 = not block
    then in the movement checks, where the game checks the space ahead to see if there is any block material, i changed this:

    Code:
    func CM_CheckWalkY()
    {
        x1=0;y1=0;x2=0;y2=0;
        PlayerMakeBB(&x1,&y1,&x2,&y2);
    
        //find player position
        px = PlayerGet(P_X);
        py = PlayerGet(P_Y);
    
        //set box corner coords
        boxx = px-8;
        boxy = py-20;
        boxw = px+8;
        boxh = py-8;
    
        roomw = GameGet(G_ROOMW);
        roomh = GameGet(G_ROOMH);
    
        //check if player is inside 'box'
        return MaterialCheckFree(boxx%roomw,boxy%roomh,boxw%roomw,boxh%roomh);
    }
    to this:

    Code:
    func CM_CheckWalkY()
    {
        //find player position
        px = PlayerGet(P_X);
        py = PlayerGet(P_Y);
    
        //set box corner coords
        boxx = px-12;
        boxy = py-38;
        boxw = px+12;
        boxh = py-14;
    
        //check if player is inside 'box'
        return Check_Blocker(boxx,boxy,boxw,boxh);
    }
    The above code defines a 'box' 24x24 big, ahead of the player (depending on which way he is facing - the above code is for facing up). then i added a couple more functions to deal with the checking of the area ahead.

    Code:
    func Check_Blocker(x,y,w,h)
    {
        pcount = ObjPresentCount();
    
        for(idxlayer=7;idxlayer > =0;idxlayer--)
        {
            for(pidx=0;pidx < =pcount-1;pidx++) // iterate present objects
            {
                idx = ObjPresentIdx(pidx); // object index
                if( ObjGet(idx,O_DISABLE) ) continue;
    
                if( ObjGet(idx,O_LAYER==idxlayer) )
                {
                    if( Find_Obj_Touch(idx,x,y,w,h)==1 ) // touched objects only
                    {
                        blocktype = ObjGet(idx,O_BLOCK);
                        if (blocktype==1)
                        {
                            return 1;
                        }
                        if (blocktype==2)
                        {
                            return 2;
                        }
                    }
                }
            }
        }
        return 0;
    }
    the above code cycles through all the objects in the room (sorting through them by layer), uses function Find_Obj_Touch (shown below) to determine which ones are within the 24x24 box that was defined earlier, then checks O_BLOCK (object property 45) to see if any of those ones are 1 or 2 (blocking). if they are, it stops the function and doesn't allow him to move into that space.

    Code:
    func Find_Obj_Touch( idx,x,y,w,h )
    {
        //player positions
        px1 = x;
        py1 = y;
        px2 = w;
        py2 = h;
    
        //object positions
        ox1 = ObjGet(idx,O_X);
        oy1 = ObjGet(idx,O_Y);
        ox2 = ox1+ObjGet(idx,O_W);
        oy2 = oy1+ObjGet(idx,O_H);
    
        if( px1 > =ox2 || px2 < =ox1 ) return 0;
        if( py1 > =oy2 || py2 < =oy1 ) return 0;
    
        return 1;
    }
    (the above code was bastardised from the 'examine' code in TLoD, hence some slightly unneccessary code)

    Also, the code in action.gs that checks for dropping items is changed too, to reference Check_Blocker(x,y,w,h) as well. if the property is anything other than 1, then it alows dropping of items. This is useful for dealing with tables etc that you can't walk over, but may want to drop something onto. They are simply set to have an O_BLOCK property of 2.


    personally i think it's a rather elegant little solution myself, if a touch CPU-heavy. in fact the method of determining whether there's a block in the space ahead is so much better and more elegant than the method TLoD uses, that i'll probably use it in CoTM.

    I hope that was of some interest to someone! Any questions regarding it, just ask.
    Regards
    Alex

  2. #2
    Hard Boiled Egg delta's Avatar
    Join Date
    Feb 2007
    Location
    North West
    Posts
    4,005

    Default

    Quote Originally Posted by Lex_Hedley View Post
    I was thinking of finally doing a game and was wanting to do the scrolling like in Dizzy Legends and Rock Dash Dizzy.

    is this the code used in Rock Dash Dizzy too?
    no. That was the tech-demo code I used to get the game to scroll when DizzyAGE didn't have a scrolling option. It was never used in any game, not even CoTM.

    Fortunately for you, DizzyAGE now supports scrolling. So all you need to do is add the following code to the bottom of function BeginNewGame() in game.gs:

    Code:
    	GameSet(G_VIEWPORTMODE,1);
    Quote Originally Posted by Lex_Hedley View Post
    I would like to move blocks around the screen too, would this be possible?
    uh oh, I smell complex functions....!

    What do you mean by 'move blocks around the screen'? do you mean they move when you push up against them?

    and what kind of screen view are you wanting? a 'classic' dizzy view, or a view like that in Rock Dash? *prays for the classic view*





    "Quotes from the internet may not be genuine" - Abraham Lincoln

  3. #3

    Default

    I'd like to do a game like rock dash as in up down left right, instead of the usual left to right

    Yes I'd like to push blocks around the screen, is it worth the pain??
    Will this cause problems because of the colliding?

  4. #4
    Hard Boiled Egg delta's Avatar
    Join Date
    Feb 2007
    Location
    North West
    Posts
    4,005

    Default

    right, firstly I'm going to try to explain how I coded Rock Dash Dizzy, so that you can see why it probably wouldn't be suitable for what you have in mind.

    RDD is completely unique. The game had to be able to 'create' tiles (diamonds, amoeba) in blank space. Not only that, but there wasn't even a real limit to how many it would have to create. The problem with this of course, is that DizzyAGE can't 'create' tiles in the middle of a game - they have to already be in the map.

    Obviously you can't have 800+ diamond tiles, 800+ rock tiles, 800+ amoeba tiles etc etc. That would be stupidly excessive. The only real solution to this issue? have a tile for every 'square' in the game - even blank squares (which are actually disabled tiles). This way, even if you needed to 'create' loads of tiles, you can simply enable the blank squares and use them.

    The problem with this solution? What happens when a rock is moved, or falls? tiles would overlap, and there would be empty spaces, which is exactly what I wanted to avoid in the first place. Fortunately, there was a further solution.

    It was this. Don't move any tiles. It may be hard to believe, but all the tiles in the game always stay in exactly the same place. Technically, nothing in the game moves at all (apart from Dizzy).

    What DOES happen is that the properties of one tile are copied to another. For example if a diamond needs to fall into a blank space below it, all the properties of the 'diamond' tile are copied to the blank tile below, which is enabled. The old 'diamond' tile above is then disabled. This creates the illusion that the diamond is moving.

    To do this, every tile (all 880 of them!) needs to know the id of each of the 8 tiles surrounding it. This is done at the start of the level, when the game cycles through each tile, compares positions, and eventually sets 8 object variables in each tile to the 8 relevant ids. This unfortunately takes the game quite a while, which is why it takes a while to load each level. It's also why the delay is unavoidable.

    The whole game is coded around the concept of switching tile properties. But I hope it also explains why a simpler game - in which you just needed to move some blocks (and not create any tiles from thin air) - would be better coded in a different way.


    In theory, the movement code for Dizzy could be used for your game with a few slight modifications (the code currently checks what class of tile Dizzy is stood next to, in order to determine whether he can move there or not). Pushing blocks around would be quite easy to code, as you'd just adapt the movement check to move the block if he was trying to go in that direction.

    If that is all you wanted to do, then hooray! But I suspect that you'd be wanting to do a bit more besides, and I suspect that this 'bit more' would be the difficult bits to code

    So in summary, most of RDD's code is useless for what you probably want to do, however the movement code would probably be useful.
    Last edited by delta; 08-03-11 at 08:37 PM.





    "Quotes from the internet may not be genuine" - Abraham Lincoln

  5. #5
    Hard Boiled Egg Lord Dizzy of Yolkfolk's Avatar
    Join Date
    Apr 2007
    Location
    Yorkshire
    Posts
    1,200

    Default

    Wow clever stuff indeed..

    Regarding scrolling, I was wanting to incorporate that for my next game but I found you had to build the map in a different way because dizzy always keeps in the same position within each room. I found I didn't actually like it in the end due to a few reasons so ive reverted back to normal gameplay now.

    I was toying with the idea of giving the player a choice of normal play & scrolling but it's not ideal to do using the same map.

  6. #6

    Default

    Thanks for the detailed response, very useful.
    I appreciate the time you take to help me.

    I'm wanting to create a puzzle game where there is a room with a box in it and you need to push that box to a designated position within said room.
    This expands to multiple boxes, to increase difficulty.
    (There could also be items to collect)

    If the movement code can be adapted then this sounds promising.
    Am I correct in thinking I wouldn't need to check all the status' of each square as I would just need the Walls to stop dizzy leaving the level and colliders against the boxes to move them if the direction allows, the rest could be left blank.
    Use a status to check that the box is coving the given position and hey presto
    Repeat for multiple boxes.

    --
    E.g Boxed In (www.boxedingame.com/)
    I could make it like this with different coloured boxes being solid until they are activated but I'm happy with the basic concept first!

  7. #7
    Hard Boiled Egg frogandhat's Avatar
    Join Date
    Aug 2007
    Location
    Gravesend, Kent
    Posts
    784

    Default

    Maybe you should see Daisys Search when it comes out!!
    I think the final puzzle sounds similar to what you want to do, but it is played out on a far smaller scale than you want!
    Insert signature here

  8. #8

    Default

    Cool
    Looking forward to giving it a go

  9. #9
    Hard Boiled Egg Meph's Avatar
    Join Date
    Apr 2007
    Location
    England, Suffolk
    Posts
    2,684

    Default

    Quote Originally Posted by Lord Dizzy of Yolkfolk View Post
    Wow clever stuff indeed..

    Regarding scrolling, I was wanting to incorporate that for my next game but I found you had to build the map in a different way because dizzy always keeps in the same position within each room. I found I didn't actually like it in the end due to a few reasons so Ive reverted back to normal gameplay now.

    I was toying with the idea of giving the player a choice of normal play & scrolling but it's not ideal to do using the same map.
    Scrolling works a treat if dizzy's in wide open spaces or underwater, but for normal tree house/castle stuff its not as effective.... but remember you can switch it on and off as needed.
    Its always the cracked ones that let the light in

  10. #10
    Hard Boiled Egg delta's Avatar
    Join Date
    Feb 2007
    Location
    North West
    Posts
    4,005

    Default

    Quote Originally Posted by Lex_Hedley View Post
    Am I correct in thinking I wouldn't need to check all the status' of each square as I would just need the Walls to stop dizzy leaving the level and colliders against the boxes to move them if the direction allows, the rest could be left blank.
    Use a status to check that the box is coving the given position and hey presto
    Repeat for multiple boxes.
    something like that yes. Don't get me wrong, it'd not be easy to code with you not having done a game before, but yes it'd be possible.





    "Quotes from the internet may not be genuine" - Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •