Page 2 of 2 FirstFirst 12
Results 41 to 52 of 52

Thread: Tile engine

  1. #41
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Say in your scrolling function you have 2 variables, one stores the scrolling offset (intScrollX ?) and one stores the tile offset (intTmpX ?) and a tile size of 20 pixels (must match)...

    VB Code:
    1. intScrollX = intScrollX + 1
    2. If intScrollX > 20 then
    3.    'Reset scrolling offset
    4.    intScrollX = 0
    5.    'Adjust tile offset
    6.    intTmpX = intTmpX + 1
    7. Endif

    Remember where you draw the map you have to add both offsets to draw it at the correct position:

    VB Code:
    1. For A = 0 to MapWidth
    2. For B = 0 to MapHeight
    3.    DrawTile Map(intTmpX,intTmpY), A*TileWidth - intScrollX, B*TileHeight - intScrollY
    4. Next
    5. Next

    That's all ..

  2. #42

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    intSclX is the scroll offset, intScrollX is the tile offset
    intTmpX is the tile the player is on...
    Fox, I studied the example you gave me - it's exactly what I got allready...
    Last edited by McCain; May 9th, 2002 at 09:53 PM.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  3. #43
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    If you had the same it worked

    VB Code:
    1. intPX = intPX + 20 'What the hell do you need intPX for?
    2.          If intTmpX >= 20 + intScrollX Then 'Why do you check the player position :confused:
    3.             intScrX = intScrX + 20 'intSrcX? You don't need thisat all!
    4.             If intSclX < 20 Then 'Next tile reached right?
    5.                 intSclX = intSclX + 20 'Why 20? Scrolling is 1 pixel / frame I assume...
    6.             ElseIf intSclX >= 20 Then 'Well .. again checked that we reached the next tile or what?
    7.                 intScrollX = intScrollX + 1 'Increase tile index
    8.                 intSclX = 0 'Reset scrolling
    9.             End If
    10.         End If

  4. #44
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    hrrr I took the time to correct your code:

    VB Code:
    1. If GetAsyncKeyState(vbKeyRight) <> 0 Then
    2.     If intMap(intTmpY, intTmpX + 1) = 0 And intMap(intTmpY2, intTmpX + 1) = 0 Then
    3.         intPX = intPX + 20 'Still dunno what's this..
    4.  
    5.         intSclX  = intSclX +1
    6.         if intSclX >20 then
    7.            intSclX =0
    8.            intScrollX =intScrollX +1
    9.         endif
    10.     End If
    11. End If

    intMap(intTmpY, intTmpX + 1)

    not sure how this'll work though.. it means your tiles are 1x1 pixel in size! If you had 20x20 tiles you'd need to do collision it like this:

    VB Code:
    1. intMap(int(intTmpY/20), int(intTmpX/20) + 1)
    etc.

  5. #45

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    intPX is an integer variable holding the X position of the character... That's what I use to move the character when the map isn't scrolling...
    Maybe if I had posted this piece of code it would've been easier to understand...
    VB Code:
    1. intTmpX = intPX \ 20
    2. intTmpY = intPY \ 20
    3. intTmpY2 = (intPY \ 20) - 1

    And I think I just figured out what's wrong with the collision thing, thanks Fox!
    When the map is scrolling and the character isn't moving the intPX and intPY doesn't get updated so the intTmpX and intTmpY stays the same...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  6. #46
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    So how's everything going?
    I don't know if I mentioned of course the actor needs to be drawn different too now or it won't scroll with the map
    you draw it like:

    draw x-intScrollX*20+xscrl,....
    Sanity is a full time job

    Puh das war harter Stoff!

  7. #47

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    I'm going away for the weekend so I can't do any coding...
    I uploaded what I got if anyone wanna have a look...
    When I get the scrolling to work I want to add gravity
    Attached Files Attached Files
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  8. #48
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    well adding gravity is really simple... here you go:
    first you need to check if you actor is standing on something if so yspeed=0 if not just add 9.8 to yspeed
    and every loop you go like
    y=y+yspeed
    x=x+xspeed

    that way you can also implement jumps and stuff
    jump just set y speed to some negativ value big enough and you will get a nice parabolic jump...
    that way you can also do it for going left and right so you actually need to hold down the key a while till you reach full speed and also you can make it so the actor is not able to stop at once but slides a little...
    in one of my games I made the xspeed increasement dependend on the ground I was standing on to get ice and stuff like that...
    Sanity is a full time job

    Puh das war harter Stoff!

  9. #49
    Zaei
    Guest
    9.8 pixels looks wrong. Add 9.8*heightOfActor, instead =).

    Z.

  10. #50
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    hm got another idea what you could do...
    what about a paralax background? I think it's pretty cool having one, I never made one though.
    It should not be to hard though. smaller things in the back move slower and bigger things in front of the game move real fast so they seem all close...
    Sanity is a full time job

    Puh das war harter Stoff!

  11. #51
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    you are right 9.8 pixels does not work... you need some scale down thingy... I often used constants from nature and took some general "scale down" variable to finetune the game easily...
    Sanity is a full time job

    Puh das war harter Stoff!

  12. #52

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Ok, I'm back.
    Gravity doesn't look too hard, but before I implement that I want to get the scrolling to work...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width