Drawing question

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Drawing question

Post by wild8900 »

Hey, Im just curious how you guys draw game maps and the active objects like the player.
They way I do it is that before the level starts, it draws the matrix line by line. Then it draws the player. I am having a problem with the player drawing part. I use the output command btw. So, when the player presses a button, I have it so sets the position to " " and updates the output with the new X and Y. Sometimes, the " " goes over the already drawn level and that is bad. D:

How should I draw my character and map?
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

Not line by line from the matrix!
I know very little about this subject, but even though drawing from a matrix makes sense, it's way too slow for anything useful. Maybe turning the matrix into a different data-type that can be accessed faster. Like I said, I have no idea.
I think, therefore iMac
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

is this assembly or basic?
in basic I would use xLIB (use real(2 for the map and real(1 for the player - sprite)
in assembly its even easier, just draw the map (wouldn't use a floating-pointing matrix for this, you won't need 9 bytes for each entry) and then draw the play over it, and don't forget to copy your buffer to the LCD
User avatar
anykey
Extreme Poster
Posts: 420
Joined: Mon 31 Jan, 2005 3:36 am
Location: In the matrix
Contact:

Post by anykey »

He's using a matrix and he's fairly new, so I'm assuming it's basic.
Check out the tilemapping functions in xlib. They're quite cool.
I think, therefore iMac
Image
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Also there is a program called "bytedraw" at ticalc.org that draws 8 pixels at once, which makes any drawing routine 8 times as fast as it would have been with pixelOn or pixelOff.

But xLIB is way better for tilemaps, bytedraw is good for drawing things that are stored as "picture" in lists/strings/matrices
cjgone
Regular Member
Posts: 83
Joined: Tue 18 Apr, 2006 5:33 am
Location: Washington->UC Berkeley '15

Post by cjgone »

" " and output... I'm assuming this is text based?... To save the next square, you know you can't read the screen and a location and put it as a string or whatever.. The method that I did for replacement was when the text thingy moves, the square it's on is checked on the matrix with whatever value it contains, then the appropiate lil text thing is drawn on the (A,B) the current location of the "character" before its moved in its direction.

I hope this was what your looking for? :?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Then it would still be better to draw the letters on a picture, save it, and use xLIB
much faster and cleaner that way
cjgone
Regular Member
Posts: 83
Joined: Tue 18 Apr, 2006 5:33 am
Location: Washington->UC Berkeley '15

Post by cjgone »

Not everyone uses xlib...Especially when you just start programming..

And drawing letters on a picture is easier?! You don't draw letters if you can draw cool images. It's also a lot easier to go through two for-loops and output lil' characters to the screen, corresponding to the maxtrix. This wouldn't work if he was scrolling, then xlib would pwn.. But then you wouldn't be moving the center drawing if it was scrolling (except at edges..)..It would be in the center.
User avatar
CDI
Maxcoderz Staff
Posts: 321
Joined: Tue 24 May, 2005 7:25 pm
Location: If I find out, you'll be first to know.
Contact:

Post by CDI »

A string that matches up with a matrix is easter, but bloated
ImageImage
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

Yes, Im using Basic. And yes its text based ;P
I clear the player's position then move him THEN draw him again. Pretty simple.

[quote=cjgone]
" " and output... I'm assuming this is text based?... To save the next square, you know you can't read the screen and a location and put it as a string or whatever.. The method that I did for replacement was when the text thingy moves, the square it's on is checked on the matrix with whatever value it contains, then the appropiate lil text thing is drawn on the (A,B) the current location of the "character" before its moved in its direction.
[/quote]
I was thinking of something similar but I worried that it might take too long to execute. Have you tested?

Btw, I was thinking of trying xlib but Im pretty new, maybe some day.

Thanks everyone that helped! I will try to put all of your tips to good use.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

tip: move BEFORE clearing him, avoids flickering

and really, just use xLIB, it is much easier then text-based (if you read the manual!) and you could have it draw any shape (well, any 2-dimensional shape that is supported by the TI)
cjgone
Regular Member
Posts: 83
Joined: Tue 18 Apr, 2006 5:33 am
Location: Washington->UC Berkeley '15

Post by cjgone »

Using the 'non-xlib' way, it's not that slow actually (Do not try smooth-scrolling, does not work [slow]).

(I'm not known for efficiency.. Nor do I care..It's BASIC..

Pretty much:

Code: Select all

For a,1,8
For b,1,16
If [A](a,b) = 1
then 
Ouput(A,B,"X"
end
If [A](a,b) = 2
then 
Output(A,B,"O"
end
end
end
Location1 -> a   ;aka x and y
Location2 -> b
output(a,b,"?"  ; your main character -_-
While 1
getkey -> z
if z = 24 and B =/ 1    ; not equal.. 
then
;------- This is the redraw matrix crap
If [A](a,b) = 1
then
Ouput(A,B,"x"
end
If [A](a,b) = 2
then
Output(A,B,"O"
end
;------------ pretty much
B-1 -> B
output(a,b"?"  ;; yep creative.. '?' is your character...
end
end
This thing works nicely for level editing too.. You can't make platformer games (obviously).. maybe an rpg... Go with xlib :D

Oh, assembly is also a good choice..
wild8900
New Member
Posts: 35
Joined: Mon 19 Sep, 2005 11:26 pm

Post by wild8900 »

Thanks for the idea. :D
Ill try xlib some day. At the moment Im making a metroid platformer. At the moment I have gravity down, secure movement in all areas of screen (none of the errors if it checks for non existant vars in a matrix), shooting in both directions. I had opening doors but my calc crashed or something and all ram cleared. Luckily I had pretty recent backups ^.^;
Is it safe to use "while" loops within "while" loops?

By the way, how do you put comments into your code? other languages that I write in use two forward slashes followed by a comment.
It would really help to keep tabs and show what does what.

Lastly, I cant get the PC program editor to work for some reason, I need it so I can make the level matrix values easier. Is there any way to get it working or any external editors? It says something about .net being needed. If it needs a windows update, no can do -_- I supposedly have a pirated windows.
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

You can use while loops within other while loops so long as all of your ends are in the right places.

You can make a line with :"This is a comment
on it, but since the interprator will store that as a string into Ans, it takes up processor time.
The short answer is you can't use comments.

My windows updates no problem, and my neighbor gave it to me for my birthday on a burnt CD he made at work. I don't think .NET requires a whole windows update, just a .NET framework update.
Image
cjgone
Regular Member
Posts: 83
Joined: Tue 18 Apr, 2006 5:33 am
Location: Washington->UC Berkeley '15

Post by cjgone »

Yeh, to bad for no comments.. =\

You can use mutiple while loops.. (While 1 means always true, so it will loop on forever.. that's why they made a command called 'stop' to kill ya program).

If you already know, you probably do, I don't care :

A while loop is a loop where as long as the statement is true, the code will be executed.. (something like that).
So:

Code: Select all

1 -> a
While A<=8 ; height of screen
1 -> b
While B<= 16  ;width
output(a,b,"Y"
B+1->B
end
A+1->A
end
I think I messed up on the whiles but thats every but the point..lol .... Umm.. your project is a bit difficult for pure Basic.. speed and memory wise.. :?


Oh the matrix gumbo... I have no clue.. I don't code basic on comps..
Post Reply