forums

TNT Basic Forums > Programming Q&A
Mapping HELP (more!)
< Last Thread     Next Thread >
Author
Thread        Post A Reply

05-09-2008 01:35

Posted by:
tntfan3

Find more posts by tntfan3

I have a few mapping questions as I am currently teaching myself BASIC mapping (the mapping totorial was of marginal help to me). I currently have a simplistic scrolling map. My problem is that when I reach a specific x,y coordinate (on my 2D map) my map continuously displays the same thing over and over (the same screen continuously re-scrolls). The said x,y coordinates (where the malfunction occurs) appears to change based on my number of tiles. Any tips and/or help would be greatly apprichiated!

05-09-2008 21:46

Posted by:
tntfan3

Find more posts by tntfan3

Below is a code excert:

Note: All variable not shown are declared globally
Note:

load map 128 '*load map 129*

open map viewport 5,0,0,0 to 640,480

load images 131

load sounds 130

load music 128

int mario_right_movement= 4,mario_left_movement= 4

int animation 'denotes whether animation should occur

int ObjNmb= map object count

int pX[ObjNmb],pY[ObjNmb]

int n

int object_type

int tile_count_xdraw= 30,tile_count_ydraw= 20,calculate_text_map_tiling=false

int enter_tube= false

str map_one_tile_print

sprite_Super_Mario_Bros_charx= 320
sprite_Super_Mario_Bros_chary= 240

viewoffset_xx= 0
viewoffset_yy= 1423

Super_Mario_Bros_test_mode_raw= keyboard raw key

Super_Mario_Bros_test_mode= Raw Key Scancode (Super_Mario_Bros_test_mode_raw)

clear keyboard
set pen colour blue

paint canvas

play sound 1,50,225,100

delay 700

play music

set music volume 50

for n= 0 to ObjNmb-1
pX[n]= map object X (n)*60
pY[n]= map object Y (n)*60
next n

while not mouse button
mario_image= 0

if right then viewoffset_xx= viewoffset_xx+mario_right_movement
if right then mario_image= 1


if left then viewoffset_xx= viewoffset_xx-mario_left_movement
if left then mario_image= 4

if down then enter_tube= true

if space then jumping= true
if jumping= true then mario_jump()

'test mode additional commands

if Super_Mario_Bros_test_mode= 105
draw text tile_count_xdraw,tile_count_ydraw,map_one_tile_print
calculate_text_map_tiling= true
if up then viewoffset_yy= viewoffset_yy-10
if down then viewoffset_yy= viewoffset_yy+10
end if

viewoffset_x=viewoffset_xx
viewoffset_y=viewoffset_yy

if viewoffset_x< 0 then viewoffset_x= 0
if viewoffset_y< 0 then viewoffset_y= 0

if viewoffset_x> map width()*60-640 then viewoffset_x= map width()*60-640
if viewoffset_y> map height()*60-480 then viewoffset_y= map height()*60-480

for n= 0 to ObjNmb-1
object_type= map object type (n)

if object_type= 0
sprite n+2,(pX[n]-viewoffset_x),(pY[n]-viewoffset_y),17
sprite n+3,(pX[n]-viewoffset_x),(pY[n]-viewoffset_y),17
end if

if object_type= 1
sprite n+2,(pX[n]-viewoffset_x),(pY[n]-viewoffset_y),18
sprite n+3,(pX[n]-viewoffset_x),(pY[n]-viewoffset_y),18
end if

map_one_tile_obj= map tile (pX[n]/60,pY[n]/60,0)

'insert object tile reactions here
next n

map_one_tile_char= map tile ((sprite_Super_Mario_Bros_charx+viewoffset_xx)/60,(sprite_Super_Mario_Bros_chary+viewoffset_yy)/60,0)

'insert char tile reactions here

if Super_Mario_Bros_test_mode= 105 and calculate_text_map_tiling= true 'test mode
map_one_tile_print= as string (viewoffset_yy,4)

tile_count_xdraw= tile_count_xdraw+60 'this is the spacing between numbers

if tile_count_xdraw>600
tile_count_xdraw= 30
tile_count_ydraw= tile_count_ydraw+20
end if

if tile_count_ydraw> 450
tile_count_ydraw= 20
end if

mario_right_movement= 30
mario_left_movement= 30

calculate_text_map_tiling= false
end if

sprite 6,sprite_Super_Mario_Bros_charx-(viewoffset_x-viewoffset_xx),sprite_Super_Mario_Bros_chary-(viewoffset_y-viewoffset_yy),mario_image
Set Sprite Priority 6,100

set viewport offset 5,viewoffset_x,viewoffset_y

draw frame
wend

stop music
end proc

procedure mario_jump() 'parabolic jump
if redeclare= true then sprite_Super_Mario_Bros_charxx= equation_sprite_Super_Mario_Bros_charx

equation_sprite_Super_Mario_Bros_charx= equation_sprite_Super_Mario_Bros_charx+1

sprite_Super_Mario_Bros_chary= (0.35*(equation_sprite_Super_Mario_Bros_charx-340)^2+100)

redeclare= false

if equation_sprite_Super_Mario_Bros_charx>= sprite_Super_Mario_Bros_charxx+40
jumping= false
redeclare= true
equation_sprite_Super_Mario_Bros_charx= sprite_Super_Mario_Bros_charx
end if
end proc

05-09-2008 21:46

Posted by:
tntfan3

Find more posts by tntfan3

Any help would be greatly apprichiated!

05-10-2008 14:58

Posted by:
tntfan3

Find more posts by tntfan3

Please help ASAP!

05-11-2008 05:04

Posted by:
tntfan3

Find more posts by tntfan3

bump

05-11-2008 13:53

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

can you post the scrolling code only.? my eyes cant read TNT b so well anymore :<

05-11-2008 16:43

Posted by:
tntfan3

Find more posts by tntfan3

Here it is:

if right then viewoffset_xx= viewoffset_xx+mario_right_movement
if right then mario_image= 1


if left then viewoffset_xx= viewoffset_xx-mario_left_movement
if left then mario_image= 4

viewoffset_x=viewoffset_xx
viewoffset_y=viewoffset_yy

if viewoffset_x< 0 then viewoffset_x= 0
if viewoffset_y< 0 then viewoffset_y= 0

if viewoffset_x> map width()*60-640 then viewoffset_x= map width()*60-640
if viewoffset_y> map height()*60-480 then viewoffset_y= map height()*60-480

.
.extra spaces indicating that i am now skipping to offset setting.

set viewport offset 5,viewoffset_x,viewoffset_y

draw frame

.

05-11-2008 18:15

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I can't spot anything obviously wrong, though the difference between viewoffset_x and viewoffset_xx seems a bit unclear

usually, it is better to position the camera relative to the main character, and not make it move along key pressed

like (pseudo-code) :

viewport_x = mario_x - 640/2
if viewport_x<0 then viewport_x=0
if viewport_x>(...you found it don't remember...) then viewport_x=...

and the same for Y

unfortunately that map tutorial is quite old so it may not always use the best ways possible of doing things

05-13-2008 21:20

Posted by:
tntfan3

Find more posts by tntfan3

Can you be more specific? Also can you fiox my code not give another method?

05-14-2008 13:34

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

To fix your code, i would need to know the difference between viewport_x and viewport_xx, the difference between both is very unclear

05-18-2008 20:08

Posted by:
tntfan3

Find more posts by tntfan3

Sure. The difference is as outlined in the map tutorial. It is "viewportx" being the actual x position of the viewport as set by the: "set viewport offset" command. "Viewportxx" is an internal viewport that is used for input. Hence, when the users presses "right" the "viewportxx" increases. Later (or earlier in the code, depending on how you look at it), thereby allowing for other calculations to be made, prior to the actual view port movement. For a further explanation of them please look at the map tutorial. Look for the viwport's x's (I believe in said tutorial it is called mapX.

Thank you for wanting to help and any further help is greatly appreciated.

05-18-2008 22:26

Posted by:
tntfan3

Find more posts by tntfan3

Also, how do I do a sprite col with an object sprite (I'm using n+2 for the objects sprite's index/id, so what index/id do I use in the collision? Where do I put it? Lastly, how do I utilize a background image in my map (what code and where do i put it)?

05-20-2008 01:00

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I personnaly don't quite like this way of having viewport_x and viewport_xx. My personnal way of seeing it is that pressing the arrow keys should *only* move the character

So you can have for instance :

if left then mario_x = mario_x - 5
if right then mario_x = mario_x + 5

Note that I believe hitting keys should *not* move the viewport offset. it can probably be done but from my experience i think it only causes more problem.

Then, once the character as moved, you can just calculate the position of the camera as to have the character near the center of the screen

viewport_x = mario_x - screen_width/2
viewport_y = mario_y - screen_height/2

This way the camera will just follow the character and it's much easier to manage. You might just need to add a check so that the camera doesn't go out of bounds. Something like

if viewport_x < 0 then viewport_x = 0
etc.

I will not fix your code cause programming involves trying by ourselves ;) But feel free to post improved code I can look at.

About collision, the fact that the ID is of the form 2+n does not matter, you can do a regular 'if sprite col(3,2+n)=2+n then ...' (as long as you are inside the correspondant 'for' loop of course)

You currently cannot use background images in TNT. You can only try to fake it with tiles

05-20-2008 02:15

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

can't you use:

http://tntbasic.com/learn/help/commands/pasteimage.htm

to paste images on to canvas?

The sprites will be drawn over it, because they're 'sprites', right?

05-20-2008 19:04

Posted by:
tntfan3

Find more posts by tntfan3

Thanks however none of you answered my MAIN issue as to WHY tiles are re-scrolling and reappearing in places where they are not in actuallity. These tiles are drawn on screen repetitively yet even the TNT engine does not acknoledge thier presence in that if I test the value of the tile at said location it does not think that a tile is there. Also, my map rescrolls the same tiles yet the X value IS still increasing. Furthermore, the map ceases scrolling at the end of the map properly. My code appears fine, is it a TNT mapping bug?! HELP please!

05-20-2008 19:15

Posted by:
tntfan3

Find more posts by tntfan3

Also, I want to move the viewport as it suits my program much better!

05-27-2008 19:17

Posted by:
tntfan3

Find more posts by tntfan3

I still have tiles appearing that sould NOT be there!

Also, I have TNT thinking that they are not there yet these extrenuous tiles do still appear.

05-27-2008 22:50

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Maybe you could try uploading the full project if it's not too big, it will be easier if people can try and see what you mean

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.