[TI-BASIC] Platformers

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
ProphetsDementia
Regular Member
Posts: 81
Joined: Wed 06 Dec, 2006 2:20 am
Location: Tokyo, Kanto, Japan

[TI-BASIC] Platformers

Post by ProphetsDementia »

I need a little bit of help. I'm making a game with xLib and it's a platformer. However, here's the checklist of things I need.

[ ] Jumping Sequence
[ ] Mid-Air Moving Sequence
[ ] Collision Detection (w/ enemies)
[ ] Collision Detection (w/ platforms and items)

Thanks.

( If the sequences are in the programming format, it would be appreciated. Your name goes in the credits.)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

What exactly do you want?
Floodkiller
Sir Posts-A-Lot
Posts: 245
Joined: Mon 14 Nov, 2005 9:47 pm
Location: Getting overwhelmed by everything
Contact:

Re: Platformers

Post by Floodkiller »

ProphetsDementia wrote:I need a little bit of help. I'm making a game with xLib and it's a platformer. However, here's the checklist of things I need.

[ ] Jumping Sequence
[ ] Mid-Air Moving Sequence
[ ] Collision Detection (w/ enemies)
[ ] Collision Detection (w/ platforms and items)

Thanks.

( If the sequences are in the programming format, it would be appreciated. Your name goes in the credits.)
Well, without knowing what type of code you need according to your engine, I can give you explanations of some of them.

Jumping Sequence- decrease the height coordinate for x amount of time over y periods, until a determined height is reached (you may decide to plateau the height to add air time for a period of time). Because it is a platformer as well, you will have to add a gravity that will always pull down on the player, and after the height of the jump (and optional plateau) is done, reinstate gravity to pull the player back down.

Midair movement- Following the above stuff, all you really need is just for your engine to use the same movement system you have when you are on the ground, it will react about the same (unless you are doing some physics related jumping, then you have to have something different for your movement engine on the ground to pick up and slow down speed for walking/running, and jumping will cancel out further movement in air and the speed will carry you with jumping)

Collision with enemies-Easy enough, when character coordinates are equal to enemy coordinates, take damage or die.

Collision with levels- Since xLib uses matrixes to tilemap anyway, make it so that your character is not able to move through tiles that contain obstacles in level. Items work about the same as enemies if they are pick ups, just have it so that they do something other than what enemies do. If items are pushable, then have it so that when your character moves into them, it checks the getkey to see what direction, and, if there is no matrix level part in the way, it will move it according to direction pushed.
Main Projects:
Zombie Attack: 20%

Side Projects:
???-25%

Image

Staff member of Hikaru Rakuen Programming.
User avatar
ProphetsDementia
Regular Member
Posts: 81
Joined: Wed 06 Dec, 2006 2:20 am
Location: Tokyo, Kanto, Japan

Post by ProphetsDementia »

Alright, here's the full explanation.

I am making TowelMan. (See Program Ideas.) I need help making the platforms, HUD, enemies, and bosses. I'm using xLIB 0.601b. I need the snippets below in order to finish it.

[ ] Jumping Sequence
[ ] Mid-Air Moving Sequence
[ ] Collision Detection (w/ enemies)
[ ] Collision Detection (w/ platforms and items)
[ ] Level Up Knit Sequence

Thanks for your help.
"Choice. The problem is choice."
"Quite correct. Strange; that was quicker than the others."
"Others?"

"In your case, this is the sixth version of the Matrix."
"Sixth version? Then, either no one told me or no one knew."
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

HUD is easy, xLIB lets you leave empty space around your map, xStart Ystart xEnd and yEnd are your friends there. Depening on where you want to leave space and how much you change their values from their "defaults" (xStart and yStart are usually zero, xEnd is 11 and yEnd is 7, I think..)

platforms? well just make a tile with a platform on it? and map it to the right place ofcourse..

Collision detection - now it gets a little harder then Floodkiller suggested, but it really depends on how difficult you make it yourself, the bare minimum of collisiondetection is what Floodkiller said, anytime you move you will have to check the tile you are moving to, AFTER you checked whether its inside of the map. A pitty because you lose a nice optimisation there, but its necesary to avoid DIM errors. If you want a smoothwalking dude, then you'll have to make it a sprite, and do something funny with xOffset and yOffset multiplied by 8 and added to the x and y on the sprite on the screen, then divided by 8 and iParted (is that all necesary? Im afraid it is..) that should give the coords to check in the map itself (its usefull to either make all unwalkeble tiles above or below some number, or make a list of walkable tiles and compare the whole list the the one matrix entry, [A](y,x) = LTILES something like that, the first one is faster and smaller though.)
Alright that wasn't fun - Items are something else to worry about, you'll need a drawing or every item you'll ever use (how else could you display it?) and you can only have 12*8 sprites per picture, IF you don't intend to use the last column of the 11th sprite in each row and the last row of the last row of sprites. For items that shouldn't be a problem.

Animations can be made by changing the aligned sprite number of whatever sprite it is about, ofcourse to values at which the next frame is located, and it's easy to have them in the right order and close together.

If you need actual code for any of those things.. well it wouldn't really be a problem but it isn't all that hard, so I expect you can figure it out yourself (with some more help probebly). I can't really write code if I don't know what variables you are using for what, or the locations of the sprites you're using, it matters a whole lot because optimisations may not allways work on all values or all variables.
Floodkiller
Sir Posts-A-Lot
Posts: 245
Joined: Mon 14 Nov, 2005 9:47 pm
Location: Getting overwhelmed by everything
Contact:

Post by Floodkiller »

Well, I could tell you how to do the threading stuff according to your idea of how you want it (keypresses). You might need to optimize it because, as King Harold pointed out with my collision detection, I just do the bare minimum for making the coding work, then look back for optimization later. I don't know if it is the smallest it can be, but I make sure it works.

Depending on if it is timing or not (I'll do timing, without forgiveness if you hit the wrong button):

Code: Select all

:x->dim(LKEY - Make x however amount of keypresses you need.  I assume you know how to use lists.  Don't mistake this lowercase x as a variable later!
:for(A,1,x
:randInt(1,4->LKEY(A - The 1-4 is just for arrow keys, make it whatever range you wish. Next, you can either use xLib getKey (and save maybe a little space on coversions), or convert it to normal getKey (which I will do). Also, I am not so good at the parenthesis cutting yet, so I don't know if I have this line right with it.
:End
:100->T:1->A - T is amount of time, A is the arrow you are currently on.
:ClrHome - I won't be using xLib for this, since I am still learning it myself, but you can substitute in displays in xLib where you see fit.
:While T>100 or A>x
:T-1->T:0->B -See below for B.
:If LKEY(A)=1
:Output(1,1,"LEFT
:If LKEY(A)=2
:Output(1,1,"UP
:If LKEY(A)=3
:Output(1,1,"RIGHT
:If LKEY(A)=4
:Output(1,1,"DOWN
:getKey->G
:1(G=24)->B - Optimized.
:2(G=25)->B
:3(G=26)->B
:4(G=34)->B
:If not(B:Then - Optimized.
:If LKEY(A)/=B:Then - Fixed
:Pause "YOU FAIL!!11! - Whatever failiure you want it to be.
:Return
:Else
:A+1->A
:End
:End
:If T=0
:Pause "YOU FAIL!!11!
:If A>x:Then
:Pause "SUCCEED!
:prgmTBATKADD - Or whatever else adds an attack to your regime.  Fill in your blank here.
:End
Again, as I stated before, I make things extremely unoptimized, so feel free to optimize to this as you will. I am sure someone here could optimize this into about 1/3 of its size or less. Also, if you don't want timing, take out the parts relating to timekeeping. If you don't want error unforgiveness, take out the part that will return you to the main program if you fail once.

Edit: Fixed (I think) according to King Harold's post below.
Last edited by Floodkiller on Thu 07 Dec, 2006 3:27 pm, edited 13 times in total.
Main Projects:
Zombie Attack: 20%

Side Projects:
???-25%

Image

Staff member of Hikaru Rakuen Programming.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Code: Select all

If X=n
i->Y
for whatever X Y and n can be optimised A LOT by doing this:

Code: Select all

i(X=n)->Y

Code: Select all

B /= 0
is the same as

Code: Select all

not(B
no closing parenthesis needed for not(

Code: Select all

LKEY(A/=B
will result in an index of 0 (zero) or 1 (one) depending on whether A equals B or not. You will need a closing parenthesis between the A and the logic-operator.
tifreak8x
Sir Posts-A-Lot
Posts: 297
Joined: Mon 11 Jul, 2005 4:42 pm
Location: Indiana
Contact:

Post by tifreak8x »

Watch yourself with such code though (i(X=n)->Y), because if it is in a loop where speed is important, it will slow it down, especially if you have several such lines of code.
http://tifreakware.net - Connecting TI communities
User avatar
ProphetsDementia
Regular Member
Posts: 81
Joined: Wed 06 Dec, 2006 2:20 am
Location: Tokyo, Kanto, Japan

Post by ProphetsDementia »

Thank you guys so much. :D :D
I have worked the credits and so far:

FloodKiller
King Harold

Please continue helping this game along.
All help is much appreciated. :wink:

<Checklist>

[ ] Jumping Sequence
[ ] Mid-Air Moving Sequence
[ ] Collision Detection (w/ enemies)
[ ] Collision Detection (w/ platforms and items)
:arrow: [X] Level Up Knit Sequence
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

@tifreak: did you time that? :P notice also that there is a difference in timing between IF and IF : THEN, one of those takes longer if FALSE, the other if TRUE, forgot which though. Anyhow, no IF at all seems to be fater in any case, just like a For( loop is allways the fastest

so, ProphetsDementia, are you keeping the enemies and the Dude on a tilemap? or are they sprites? It matters a LOT when you're doing collision detection (if they are on tilemaps its a whole lot easier, but they will have to move by atleast 8 pixels at once)

Tilemap:

Code: Select all

assuming X and Y are the coords and tiles below 10 are walkable and A and B determine the direction to travel (A posive is right, neg is left, B positive is down, neg is up), [A] is tilemap
:If [A](Y+B,X+A)<10
:Then
:Y+B->Y
:X+A->X
:End
move if possible, otherwise don't.
as sprites:

Code: Select all

assuming everything is the same as in the last example, except the Dude is a sprite..
:If [A](int((Y+B)/8)+1,int((X+A)/8)+1)<10
:Then
:Y+B->Y
:X+A->X
:End
which really is not much different..

these checks come AFTER the check whether X+A and Y+B are inside of the matrix containing the tilemap.
A and B should be -1, 0, or 1. Unless you want to move faster.
User avatar
ProphetsDementia
Regular Member
Posts: 81
Joined: Wed 06 Dec, 2006 2:20 am
Location: Tokyo, Kanto, Japan

Post by ProphetsDementia »

I drew both elements ("the dude" and the platforms) in the same pic if that's what you're asking. (Remember that I'm new to xLib.)

(P.S. @FloodKiller: Some pieces of the code don't work.)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

LSOMELIST(A/=B
will not work - other then that I didn't see anything major in Flood's code..

Im actually asking where you keep the location of "the Dude" and how you tell xLIB to draw it, if you keep it in a matrix then you can only use the code named "Tilemap" if you use reall coordinates and you draw it like a sprite then you can use the sprite code, sprites allow for smoother movement.
If you use real coordinates you might want to store them in a list (how else?) and use the 1st element for the X and Y of "the Dude" and the rest for enemies (something like that), you could store the X part as the iPart and the Y devided by 1000 as the fPart (that way you can just add them, and you use only half the storage, and you will hardly ever need coords over 1000, if you do then just use 10000) iPart(LCOORDS(1)) will return the X and 1000fPart(LCOORDS(1)) the Y. The slight speed loss is so small that the smaller datasize is very much worth it, you're not going to have a lot of RAM left with a giant matrix in it (its 50*50 max, not counting the actual program, the calc allows for 99*99 but you would not be able to unarchive it) fortunately the picture can stay archived.
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 »

http://tifreakware.calcgames.org/tutori ... cdi/l4.htm

Try that, it is a nicely readable tutorial for creating a homescreen platformer game, and would suffice easily for xLIB games if you know how to program
ImageImage
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

Hi and welcome to MC, I hope we can all help you. So it seems as if you want us to program your game? I haven't done much in basic for a few months now, but if you want you can look at some platformers on ticalc from kevin and cdi. If you are needing help then just let us know.
User avatar
ProphetsDementia
Regular Member
Posts: 81
Joined: Wed 06 Dec, 2006 2:20 am
Location: Tokyo, Kanto, Japan

Post by ProphetsDementia »

Thanks, kalan_vod.
Trust me. You'll hear from me a lot.

I think MaxCoderz are the gods of BASIC and ASM.
"Choice. The problem is choice."
"Quite correct. Strange; that was quicker than the others."
"Others?"

"In your case, this is the sixth version of the Matrix."
"Sixth version? Then, either no one told me or no one knew."
Post Reply