Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: hellninjas on November 16, 2011, 06:32:16 pm

Title: Stages and Collision
Post by: hellninjas on November 16, 2011, 06:32:16 pm
I am making an attempt to continue my game Cross the defender... HOWEVER, I don't know how I would make stages that my character, the cross, can go through, really all I need is one stage, but I don't know where to stage.
I also need to work with collision, like if something hits my character, he will bounce away, and the ability to stand and move around on platforms... I just need to make some examples for myself to study so I can get the basic concept of which I am trying to do!
-> = STO key
=/ = not equal to

Thanks!
Code: [Select]
.CROSSTD
[18187E7E18181818]->GDB0
44->X
30->Y
Repeat getkey(15)
Dispgraph
ClrDraw
Pt-On(X,Y,GDB0)
If getkey(4) and (Y=/0)
Y-1->Y
End
If getkey(1) and (Y=/56)
Y+1->Y
End
If Getkey(2) and (X=/0)
X-1->X
End
If getkey(3) and (X=/88)
End
End
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 06:34:47 pm
for stage do you mean you use a drawing program and save stage aka: level as an appvar? and then recall it in the program?
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 06:36:35 pm
I do not know how I would do that...
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 06:40:46 pm
can you do a simple drawing program in axe?
if so, do that and
then do:
Code: [Select]
:If getKey(whatever) //see if press certain key
:GetCalc("appvSTAGE",768)->A //appvar for stage created and stored into pointer A
:Copy(L6,A,768) //copies buffer (L6) into appvar
:Archive "appvSTAGE" //archives it so you don't lose it in RAM clear
:End
and then to recall it:
Code: [Select]
:GetCalc("appvSTAGE",Y0) //gets it
:Copy(Y0,L6,768) //copies into buffer
is that what you mean?
Title: Re: Stages and Collision
Post by: Darl181 on November 16, 2011, 06:44:01 pm
I am making an attempt to continue my game Cross the defender... HOWEVER, I don't know how I would make stages that my character, the cross, can go through, really all I need is one stage, but I don't know where to stage.
What do you mean by stage?  Do you mean levels?
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 06:52:00 pm
Parser, thats what I needed to know, but... Drawing program? How would I aquire such an impossible tool? xD
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 07:27:18 pm
impossible? is that a joke or a real question?
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 07:28:29 pm
impossible? is that a joke or a real question?
joke xD
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 07:32:41 pm
impossible? is that a joke or a real question?
joke xD
lol
do you still need help with collisions?
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 07:34:01 pm
Yes, also with doing the drawing program, do I make this or is it in code? (Hopefully made)
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 07:36:24 pm
Yes, also with doing the drawing program, do I make this or is it in code? (Hopefully made)
well, it has been made hundreds of times, however nobody has (as far as I know) made a program to do that, everyone codes it to fit their specific need for their games.
but someone smarter than me: has one been made?
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 07:37:58 pm
I have no idea how I would make one, but could someone please help? //As seen above//
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 07:39:36 pm
ok, I'll make one and post it... :)
(please wait...)
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 08:23:18 pm
Ok here's the source :D
controls:
2nd-turn pixel on
mode-turn pixel off
Y=-clear screen
Store-store pic as appvar
Enter-draws stored appvar on screen
Graph-Displays your current X,Y coordinates (I don't think you'll be needing this but I threw it in anyway :))

NOTE: greyscale isn't very good, but it still functions :)
Title: Re: Stages and Collision
Post by: hellninjas on November 16, 2011, 08:24:56 pm
Thanks!! Now for collision...
Ok, now how would I display the appv"TheEnd" ?
So as if my character can run around on the stage, i can do, but not the displaying...
Title: Re: Stages and Collision
Post by: parserp on November 16, 2011, 10:51:19 pm
Ok, now how would I display the appv"TheEnd" ?
it's in the source: just look for: If getKey(9)
(I think it's at the end :))
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 12:37:36 am
Ok I put it in but its not displaying, how would I implement this with my code?
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 09:15:45 am
Ok I put it in but its not displaying, how would I implement this with my code?
hmmmm, did you do it exactly like the source? maybe need dispgraph? did you save it before displaying it?
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 05:38:30 pm
The first part of the code you showed me I put before the repeast getkey, I do not want it to display when I press I key, I want it always to be on the screen. So I placed the second part of the code you showed me right after Clrdraw under Dispgraph.
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 06:05:42 pm
??? I have no Idea what you just said. is there still a problem?
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 06:21:48 pm
Just in displaying the appv"TheEnd" it wont appear!
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 06:23:30 pm
what is the bit of code that should be doing that but isn't?
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 06:26:57 pm
can you do a simple drawing program in axe?
if so, do that and
then do:
Code: [Select]
:If getKey(whatever) //see if press certain key
:GetCalc("appvSTAGE",768)->A //appvar for stage created and stored into pointer A
:Copy(L6,A,768) //copies buffer (L6) into appvar
:Archive "appvSTAGE" //archives it so you don't lose it in RAM clear
:End
and then to recall it:
Code: [Select]
:GetCalc("appvSTAGE",Y0) //gets it
:Copy(Y0,L6,768) //copies into buffer
is that what you mean?

I did all this but its not working...
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 06:30:20 pm
no,  I meant from the actual source that you are using XD
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 06:40:40 pm
Here it is...

Ok It displays,, but not the Pic i need, its all a jumbled up mess!!
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 08:06:47 pm
Here's the source, it works, but ONLY if you have an appvar "TheEnd" saved in archive. :)
EDIT: I also optimized it a bit  ;)
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 08:21:08 pm
OMFG IT WORKS!!! Thanks Parser, and btw, nice job on swords! (I'm stuck on level 3 xD)

Collision I got covered, i took some notes...
But now I need some help with bullets... I want to be able to shoot in any of the normal 8 way directions, which i can handle, but because of arrays and stuff, i need to know a way to make bullets shoot from my characters spot...
Could you help me with bullets?
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 08:24:18 pm
yeah, sure.
so, you can do the direction of the bullets, you are just having trouble starting them at your characters position?
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 08:28:44 pm
I can't do bullets in general xD
I'm just saying that I am smart enough to learn it but can't figure out how.
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 08:29:38 pm
oh XD
Title: Re: Stages and Collision
Post by: epic7 on November 17, 2011, 08:31:16 pm
You can learn it... but you cant? I think bullets are pretty easy, personally :P
Title: Re: Stages and Collision
Post by: hellninjas on November 17, 2011, 08:35:28 pm
Well im the softmore at my school who has been programming in Basic for the past few years and placing games onto other peoples calcs, yet, none of my games have bullets...
But back to the topic... (Help with Bullets now...)
Title: Re: Stages and Collision
Post by: parserp on November 17, 2011, 09:01:27 pm
ok, so you need some help?
I've never done this before, so here goes:
have a var to see which way player/gun is facing (so bullet goes in right direction)
when you press a key, a variable is created (direction) and the bullet is drawn at the gun's X,Y coords.
then, every loop, the bullet's position is added/subtracted from depending on which way gun is facing- thus creating the illusion it is being "shot"
Ah! it's 7:00! I gtg! bbl!
Title: Re: Stages and Collision
Post by: epic7 on November 17, 2011, 09:04:29 pm
And have a variable to space the bullets if you have more than one at a time :)
I have 2 vars that check the bullet. The first one is turned on when the bullet is fired. I have that set the coords and direction. The second one is activated (and first deactivated) afterward which, if 1, makes the bullet move in the direction. Thats my way. :P

Coded example coming up :P

For a simple 1 bullet, here is what I would use. I actually could just use one bullet check var, that would be easier :P

Repeat getkey(15)
If getkey(9)
!If F
. F is a bullet check. It equals 1  when the bullet is being fired, 0 when it isnt.

X->A
Y->B
R->C
.R is if the player is facing left or right (right is 1, left is 0 here)
.Save that so the bullet wont go backwards :P
.X and Y are the player's coordnates, thats where the bullet starts
1->F
.When F is 1, that makes it so it wont go through this again.
End
End
If F
.So if F is 1, that means to start moving the bullet.
If C
A++
Else
A--
End
.That checks if it is going left or right.
PtOn(A,B,Pic1)
.Put it on the screen with whatever pic your bullet is
End
If A>96 or (A+8<0)
.If the bullet is outside the screen
0->F
.When F is zero, the bullet stops moving and another bullet can be shot
99->A
.Putting the Coords outside of the screen so it wont interfere
End
End

I dont think I'm forgetting anything other than bullet to enemy collision detects.
Since I didn't put a variable for bullet spacing, this code will make your bullets fire really fast if you're at the edge of the screen, however.
Title: Re: Stages and Collision
Post by: hellninjas on November 18, 2011, 02:31:55 pm
How would I fire multiple bullets? Like a space shooter or like Shmup?
Title: Re: Stages and Collision
Post by: epic7 on November 18, 2011, 03:45:43 pm
Here:

Pick a variable for your for loops. I used V.
Pick L1, L2, L3 etc. I used L5.

Im taking this from my game

.Outside the main loop
For(V,0,5)
.I put 5 there to say what the max possible bullets on the screen would be.
0->{V*4+L5}
End
.That sets the bullet check to zero.
25->S->T
.S and T will be what spaces the bullets. T will gain 1 every time the loop finishes and when it reaches S, which is set to 25, a bullet will be ready to be fired.
Repeat getkey(15)
.Inside the main loop somewhere
If getKey(54)
For(V,0,5)
If T=S
.Checks if T=S so that the bullets are spaced out
!If {V*4+L5}
.If the bullet check is 0, set it to 1
1->{V*4+L5}
.Turn T back to 0 and it will have to go back up to 25 (T) to fire again
0->T
.Exits this loop now since we already have our bullet
Goto X
End
End
End
End
Lbl X
.Other stuff
For(V,0,5)
If {V*4+L5}=1
.If bullet check = 1
.Set the coordnates of the player to the bullet
X->{V*4+L5+1}
Y->{V*4+L5+2}
.Display
Pt-On({V*4+L5+1},{V*4+L5+2},Pic2
.Turn on the bullet check to 2 now.
2->{V*4+L5}
.You should have a variable that tells if the character is left or right. Save that to the bullet like here
R->{V*4+L5+3}
End
End
For(V,0,I)
If {V*4+L5}=2
.Checks if the bullet check is 2...
If {V*4+L5+3}
.If facing right..
{V*4+L5+1}+2->{V*4+L5+1}
Else
.If its not,
{V*4+L5+1}-2->{V*4+L5+1}
End
.Display
Pt-On({V*4+L5+1},{V*4+L5+2},Pic2)
End
End
For(V,0,I)
If {V*4+L5+1}>90
.If the bullet is off the screen (Works for both left and right side)
.Set the bullet checksback to zero and put the coordnates off the screen to not interfere
0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
Return
End
End
.Make T move up to S for the bullet spacing
If T<S
T++
End

Thats for just the bullets. I also have collision detects if you need.
To clear up the bullet check, this is what it does.

When
{V*5+L5}=0
That means a new bullet is ready to be shot

When
{V*4+L5}=1
That means the bullet's coordinates and left/right need to be set.

When
{V*4+L5}=2
That means to move the bullet.


Whoo... Done! :P
Title: Re: Stages and Collision
Post by: hellninjas on November 18, 2011, 08:28:11 pm
JESUS!! There's alot more to it than I thought! Thanks!
*Takes Notes*
This will be helpful for future games...
Title: Re: Stages and Collision
Post by: epic7 on November 18, 2011, 09:17:28 pm
Its probably enough to be its own tutorial.

In fact, I just made it one.
Why not? :P
Title: Re: Stages and Collision
Post by: hellninjas on November 19, 2011, 03:06:57 pm
And yes, could you help me a bit with stage collision?
Lets say if I had a stage like on stage one for "Swords" how would I make my character stand or land on the platforms?
Title: Re: Stages and Collision
Post by: epic7 on November 19, 2011, 03:08:48 pm
The easy way would just to do a pxl-test.
Title: Re: Stages and Collision
Post by: saintrunner on November 19, 2011, 03:10:18 pm
*pxl-test*
Title: Re: Stages and Collision
Post by: epic7 on November 19, 2011, 03:12:21 pm
Whoops. :P /me edits previous post
Title: Re: Stages and Collision
Post by: saintrunner on November 19, 2011, 03:15:28 pm
mhmm! and to hellninjas, just pxl-test the feet of your characters sprite. so when you jump, it first checks to see if your feet are touching a line then it jumps and falls till you touch a line again, here is a game I started a while ago that uses this, tell me if this isn't what your looking for!

edit: wrong screenie one sec

edited:here is the right one! also I can show you an easier but less advanced way for bullets
Title: Re: Stages and Collision
Post by: epic7 on November 19, 2011, 03:26:17 pm
If pxl-Test(x,y+8) or (pxl-Test(x+8,y+8))

I think that will check, right?
I need to start using pxl tests :P
I'll use them if I finish that jump game
Title: Re: Stages and Collision
Post by: saintrunner on November 19, 2011, 03:40:02 pm
yeah that will work, but you also need the ( at the beginning, but I think that was just a typo. lol
and then you need to tell it to add to 'y' if it is not equal 1
Title: Re: Stages and Collision
Post by: hellninjas on November 19, 2011, 03:45:36 pm
So implementing this into my code... How would this look in code form? (Axe)
Title: Re: Stages and Collision
Post by: epic7 on November 19, 2011, 03:46:14 pm
What? The pxl-test?

Title: Re: Stages and Collision
Post by: hellninjas on November 19, 2011, 03:50:03 pm
Yes, collision with the stage
Title: Re: Stages and Collision
Post by: epic7 on November 19, 2011, 03:55:32 pm
If pxl-test(x,y+8) or (pxl-test(x+WIDTH OF SPRITE,y+8)
.put something so that the player won't go down
End

Or, just use the inverse of this to make him fall instead if you'd like
Title: Re: Stages and Collision
Post by: saintrunner on November 19, 2011, 04:01:26 pm
I make it like this

set motion variables.and set any variable as 0...lets make it J

then in your main loop before the display graph put this part in

This should work,
here it is at the loop

:repeat getkey(15)
:if getkey(2) and (X/=0)   //   /= means doesn't equal
:X-1->X
:end
:if getkey(3) and (X/=89)
:X+1->X
:end
:if getkey(4) and ((pxl-test(X,Y+8) and (pxl-test(X+8,Y+8))  //checks to see if you are on the ground
:15->J    //what ever number you use will change the jump height
:if (J>0)
:Y-1->Y
:J-1->J
:end
if ((pxl-test(X,Y+8) and (pxl-test(X+8,Y+8)=0) and (J=0)
:Y+1->Y
:end
:now do all of your ptchange's and display graphs!


get rid of the j stuff if you don't want jumping
Title: Re: Stages and Collision
Post by: hellninjas on November 20, 2011, 03:02:00 am
Ok I input the code for a simple test and my character flies up passed the top of the screen and soon I can no longer see him...
Please help I can't fix this!
I uploaded the SRC below...
Im new to the Pxl-Test( command so if you can get a tutorial somewhere to help me out a bit I would be very greatful!!
Thanks...
EDIT: I think i might want to include the stage1 appvar as well huh xD
Title: Re: Stages and Collision
Post by: hellninjas on November 20, 2011, 03:51:06 am
Here's the code, please help!
Code: [Select]
:.JUMPDUDE
:[1C141C080C081C22]→Pic0MR
:[1C141C0818081C22]→Pic0ML
:ClrHome
:ClrDraw
:44→X
:50→Y
:1→D
:DiagnosticOff
:Repeat getKey(15)
:DispGraph
:ClrDraw
:GetCalc("vSTAGE1",Y0
:conj(Y0,L6,768)
:If D=1
:Pt-On(X,Y,Pic0MR)
:Else
:Pt-On(X,Y,Pic0ML)
:End
:If getKey(2) and (X≠0)
:X-1→X
:2→D
:End
:If getKey(3) and (X≠89)
:X+1→X
:1→D
:End
:If getKey(4) and pxl-Test(X,Y+8) and (pxl-Test(X+8,Y+8)
:15→J
:End
:If J>0
:Y-1→Y
:J-1→J
:End
:If pxl-Test(X,Y+8) and (pxl-Test(X+8,Y+8)=0) and (J=0)
:Y+1→Y
:End
:End

Title: Re: Stages and Collision
Post by: hellninjas on November 20, 2011, 04:35:05 am
ok I gave J a value in the beggining, of 0
But now my character is not coming down from the air!
AAAGH!
Title: Re: Stages and Collision
Post by: epic7 on November 22, 2011, 03:37:35 pm
Maybe try

:If (pxl-Test(X,Y+8)=0) and (pxl-Test(X+8,Y+8)=0) and (J=0)
Title: Re: Stages and Collision
Post by: saintrunner on November 22, 2011, 03:45:07 pm
I can fix this, give me a sec!

change the and to an or in the second pixl test

It should look like this!


:.JUMPDUDE
:[1C141C080C081C22]→Pic0MR
:[1C141C0818081C22]→Pic0ML
:ClrHome
:ClrDraw
:44→X
:50→Y
:1→D
:0->J
:DiagnosticOff
:Repeat getKey(15)
:DispGraph
:ClrDraw
:GetCalc("vSTAGE1",Y0
:conj(Y0,L6,768)
:If D=1
:Pt-On(X,Y,Pic0MR)
:Else
:Pt-On(X,Y,Pic0ML)
:End
:If getKey(2) and (X≠0)
:X-1→X
:2→D
:End
:If getKey(3) and (X≠89)
:X+1→X
:1→D
:End
:If getKey(4) and (pxl-Test(X,Y+8) or (pxl-Test(X+8,Y+8)
:15→J
:End
:If J>0
:Y-1→Y
:J-1→J
:End
:If pxl-Test(X,Y+8) or (pxl-Test(X+8,Y+8)=0) and (J=0)
:Y+1→Y
:End
:End



and you will keep falling though, cause you need to draw all of those lines in the level itself, or it will make you go right through them!
Title: Re: Stages and Collision
Post by: saintrunner on November 22, 2011, 04:46:01 pm
sorry to double post, but I'm assuming this will be a critical fix to your game, hellninjas!

I just remade, what I think your going for in your game, and you can feel free to use it!
Below is the source and screenie! But you are going to have to draw the rest of the lines for the level! just put them in under all the other lines in the source!

Good luck and I hope this helps!
Title: Re: Stages and Collision
Post by: hellninjas on November 22, 2011, 05:38:23 pm
Thanks! I made a few more tests to add to this, thanks for all the help everyone! :D
Title: Re: Stages and Collision
Post by: saintrunner on November 22, 2011, 05:46:05 pm
what tests do you need to add? and did my source help?
Title: Re: Stages and Collision
Post by: hellninjas on November 22, 2011, 10:26:56 pm
Yes it helped alot! And i didn't add anything to THIS source, I made other games and was practicing :D
Title: Re: Stages and Collision
Post by: C0deH4cker on November 23, 2011, 12:22:09 am
This is the best way:

Code: [Select]
0->C
For(A,0,7)
C + pxl-test(X+A,Y+8)->C
End
If C
.Player is standing
Else
.Player is in the air
End

This will work in cases like this:

     @
    _||_
     / \
      #
      #

Where the pixels under the feet arent on but one under the player is.