Join us on Discord!
You can help CodeWalrus stay online by donating here.

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

Started by Unicorn, January 05, 2015, 02:24:46 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Snektron

#75
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
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


CKH4

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
  • Calculators owned: TI-83+, TI-84+


Unicorn

Yeah, I just couldn't figure out how to do that correctly. I really need to read up on For loops.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Dream of Omnimaga

Wait, CKH4, did you forget a Then somewhere or something? Because it looks like you have one too many End instruction.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Unicorn

cumred, in the for loop could I add collision detection with the displayin of the bullet?
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Snektron

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)
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Unicorn

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.
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Snektron

#82
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
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


CKH4

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)
  • Calculators owned: TI-83+, TI-84+


Dream of Omnimaga

I was wondering because there seemed to be too many Ends for the amount of blocks.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Unicorn

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?
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Snektron

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
  • Calculators owned: TI-84+
Legends say if you spam more than DJ Omnimaga, you will become a walrus...


Unicorn

#87
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?
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Unicorn

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?)
  • Calculators owned: I own all of them: PICKACHUP TI 84+ CSE TI 83+ SE TI something something ??? ??? ??? ??? ???
  • Consoles, mobile devices and vintage computers owned: PICKACHUP ??? ??? ??? ??? ???



??? ??? ??? ??? ???

Dream of Omnimaga

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.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Powered by EzPortal