You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

[TI-84+CSE] Caticle Chronicles (split from Cat Nipper)

b/Calculator Development Started by Unicorn, January 05, 2015, 02:24:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

u/Snektron February 26, 2015, 07:36:01 AM
Isn't this bad code for your calc? Everytime you use the goto
You dont exit the while loop, which causes memory leak (right?). Also you miss an end, but i assume it's on the end of the snippet, after the 2 other end's?

Lbl 1
Repeat getKey=21
End
<set coords and variables>
For (c,c,3)
Output(D,C,".
End
Goto 1

Note: this is untested, but ill test it in a min on my 84+ (not cse)
Edit: tested and it works, but im not sure if this code works for you if you do other things in the first while loop, since my snippet simply waits for a key press
In case the first while loop was a game loop and connects to the missing end it would be something like this:

While 1
getKey->M
If M=21
Then
<set coords and variables>
For (C,C,3)
Output(D,C,".")
End
End
<more code>
End
Last Edit: February 26, 2015, 07:47:33 AM by Cumred_Snektron
u/CKH4 February 26, 2015, 02:29:45 PM
Cumreds code is pretty good. Like he said about the memory leak. Its never good to exit loops or conditionals with goto. A simple alternative is to have a big if statement like:

Lbl 1
While 1
<code that does something>
If M≠0 or C=3 or A=7
End
<more code>
End <the while loop>
<conditionals>
Goto 1
u/Unicorn February 26, 2015, 06:35:43 PM
Yeah, I just couldn't figure out how to do that correctly. I really need to read up on For loops.
u/Dream of Omnimaga February 26, 2015, 07:27:56 PM
Wait, CKH4, did you forget a Then somewhere or something? Because it looks like you have one too many End instruction.
u/Unicorn February 26, 2015, 07:55:37 PM
cumred, in the for loop could I add collision detection with the displayin of the bullet?
u/Snektron February 26, 2015, 08:14:02 PM
Probably, but how do you check for objects in your code?
I mean is there some array or something it's stored in? (Maybe post a test expression)
u/Unicorn February 26, 2015, 08:19:40 PM
I just check if the variable coords of the bullets equals the variable coords of the enemies.

If A=C and B=D
Do health reduction code.
u/Snektron February 26, 2015, 08:34:17 PM
I assume the bullet only travels from left to right:

While 1
getKey->M
If M=21
Then
<set coords and variables>
For (C,C,3)
If A=C and B=D
Then
<health reduction>
3->C //to break from the for loop
Else
Output(D,C,".")
End
End
End
<more code>
End

This stops the bullet after it hits something too
EDIT: okay i did some oncalc testing and i came up with this code:

While 1
  getKey->M
  If M=21
  Then
    <set coords and variables>
    For(C,C,3-(4-A)*(B=D)
      Output(D,C,".
    End
  If C!=4
    <health reduction code>
End
<more code>
End

The 4 in this case is 3+1, so if you wanted to let the bullet travel to eg 10 you would replace 3 with 10 and 4 with 11 :P
Edit 2: fixed error and i think this is about the best i can do:
<max x, in your case 3> ->X
While 1
  getKey->M
  If M=21
  Then
    <set coords and variables>
    X-(X+1-min(A,X+1))*(B=D)->E
    For(C,C,E
      Output(D,C,".
    End
    If C=A
      //hitpoint is stored in C and D, so you could
      //have something like Output(D,C,"X as explosion :P
      <health reduction>
  End
  <more code>
End

X can be replaced in the code, theres no need to save it in a var :P
Last Edit: February 26, 2015, 09:32:41 PM by Cumred_Snektron
u/CKH4 February 26, 2015, 09:05:03 PM
Quote from: DJ Omnimaga on February 26, 2015, 07:27:56 PM
Wait, CKH4, did you forget a Then somewhere or something? Because it looks like you have one too many End instruction.
Just taking out the extra end statement optimizes it for size. If you add a then it will be optimized for speed. (I guess but I'm failing at coding right now so don't take my word on anything being right)
u/Dream of Omnimaga February 26, 2015, 09:08:29 PM
I was wondering because there seemed to be too many Ends for the amount of blocks.
u/Unicorn February 26, 2015, 11:00:36 PM
Cumred: I am shooting the bullets from top to bottom. What would I have to change your last code? The X-(X+1-min(A,X+1))*(B=D)->E ? Can you explain what that is doing to me?
u/Snektron February 26, 2015, 11:17:20 PM
Yeah its a tricky one :P
Basically, It calculates the distance to the hit point.
The X-(X+1-max(A,X+1) part calculates the (in this case) x coord of the collision. The first X is standard, its what i did without collision. Then, i subtract from it the distance to A. I do this instead of just setting the distance to A so i can multiply it with 0 to cancel the substraction. The (B=D) part checks if the Y coordinates are the same. If so, the substraction continues (it returns 1) and the final x pos is of the collision. If the Y coordinates are not the same, the bullet will miss. (B=D) will return zero and the substraction is cancelled. The final x pos is the maximum x pos.
(Im sorry it's hard to explain)

Anyway, the code for shooting from the top would look like this:

<max y, in your case 3> ->X
While 1
  getKey->M
  If M=21
  Then
    <set coords and variables>
    X-(X+1-min(B,X+1))*(A=C)->E
    For(D,D,E
      Output(D,C,".
    End
    If D=B
      //hitpoint is stored in C and D, so you could
      //have something like Output(D,C,"X as explosion :P
      <health reduction>
  End
  <more code>
End

I just switch A&B  and  C&D ;D
u/Unicorn March 01, 2015, 03:48:29 AM
Sorry if I am asking to much, But could you refrase it with these variables?

Output(A,B,"Is the player controlled sprite
Output(C,D,"Is the bullet
Output(G,H,"Is the enemy
The enemy health is stored in Q
If I had 2 enemies I would replace all of the G and Hs with the other varibles for the enemy right?
Last Edit: March 01, 2015, 04:00:21 AM by Unicorn
u/Unicorn March 23, 2015, 06:59:58 PM
So, I think I am going to halt development on this project for now, as I don't have the necessary skills in xlibC to create an asteroid game. Once I get TokensIDE working, I will finish my first xlibC program MonyWal. (Throwing money at Walruses) Then I may start development on Cateroid. (Good name? Yes? No?)
u/Dream of Omnimaga March 23, 2015, 07:11:55 PM
Sorry to hear D:. I hope you continue calculator developement, though. You could maybe ask for help in a new xLIBC thread?
Cateroid sounds like a good name but make sure it wasn't already taken in Cemetech's contest.
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal