I wanted to begin making a simple game where you must dodge various moving objects. I have it so it will set up the area around the screen, and put a "*" as the moveable character. How would I get input from the user to move the "*" This was my first idea, and I thought it would work, but it doesn't. Right now it just ends before I can move.

P.S. All of the extra spaces are so I can check each little bit of code at a time.

Code:

ClrHome
1->A
1->B
13->C
5->D
Repeat B>25
   Output(A,B,"0
   B+1->B
End
Pause
Repeat A>9
   Output(A,B,"0
   A+1->A
End
Pause
Repeat B<2
   Output(A,B,"0
   B-1->B
End
Pause
Repeat A<1
   Output(A,B,"0
   A-1->A
End
Pause
Output(6,1,"
Pause
Output(6,26,"
Pause
Output(1,12,"
Pause
Output(10,12,"
Pause
Output(1,13,"
Pause
Output(10,13,"
Pause
Output(1,14,"
Pause
Output(10,14,"
Output(D,C,"*
While getKey=25
   Output(D,C,"
   D-1->D
   Output(D,C,"*
End
Pause

Thanks for your help.
Sorry, ignore that last post, unless you saw more to fix, then please tell me.

I think I figured out how to prevent the sudden end of the program, but a new, even stranger problem arose. When I try to move, it will only move after I press the arrow several times, or it won't move at all


Code:

ClrHome
1->A
1->B
13->C
5->D
1->E
1->F
1->G
1->H
Repeat B>25
   Output(A,B,"0
   B+1->B
End
Pause
Repeat A>9
   Output(A,B,"0
   A+1->A
End
Pause
Repeat B<2
   Output(A,B,"0
   B-1->B
End
Pause
Repeat A<1
   Output(A,B,"0
   A-1->A
End
Pause
Output(6,1,"
Pause
Output(6,26,"
Pause
Output(1,12,"
Pause
Output(10,12,"
Pause
Output(1,13,"
Pause
Output(10,13,"
Pause
Output(1,14,"
Pause
Output(10,14,"
Output(D,C,"*
Repeat getKey=105
   While getKey=25
   Output(D,C,"
   D-1->D
   Output(D,C,"*
End
While getKey=34
   Output(D,C,"
   D+1->D
   Output(D,C,"*
End
While getKey=24
   Output(D,C,"
   C-1->C
   Output(D,C,"*
End
While getKey=26
   Output(D,C,"
   C+1->C
   Output(D,C,"*
   End
End

I have no idea what is going on and would appreciate the help. Sorry for being so needy Sad .
If you'll excuse an advertisement for a moment, my book Programming the TI-83 Plus/TI-84 Plus has a whole chapter (Chapter 6) devoted to explaining this sort of thing. I believe they actually offer it for free as a teaser if you click through.
To accomplish what you are trying to do, I would use code that looks like this:

Code:

Repeat G=45 //This loops until the getKey (stored in g) is the clear button

//This draws the character if the x or y has changed since the last drawing. Excuse me not having the not equals symbol.
If X is not equal to S or Y is not equal to T
Then
Output(Y,X,"*
Output(T,S,"
End

getKey->G

//I store these values to create a backup of x and y so that I know where to erase
X->S
Y->T

 //Checks for each of the arrow keys and then increments/decrements x or y. I use Then so that you can put multiple lines in the statement, such as checking for collision.
//Arrow keys repeat their value, so there's no need for the while that you added, you will only have to press the button once
If G=24
Then
X-1->X
End
If G=26
Then
X+1->X
End
If G=25
Then
Y-1->Y
End
If G=34
Then
Y+1->Y
End
End
KermMartian wrote:
If you'll excuse an advertisement for a moment, my book Programming the TI-83 Plus/TI-84 Plus has a whole chapter (Chapter 6) devoted to explaining this sort of thing. I believe they actually offer it for free as a teaser if you click through.

I do have the book, but I'm in chapter 4. I guess I got ahead of myself. Smile
Would this work then. I looked at dankcalculatorbro's post and tried to modify it to fit my variable and I got this. I also tried to implement a detection system if the "*" touches all wall.

Code:

Repeat G=45
   If C!=E or D!=F
   Then
      Output(C,D,"*
      Output(E,F,"
   End
   C->E
   D->F
   If G=24
   Then
      C-1->C
   End
   If G=25
   Then
      D-1->D
   End
   If G=26
   Then
      C+1->C
   End
   If G=34
   Then
      D+1->D
   End
   If (C=1 and D<=5) or (C=1 and D>=7)
   Then
      ClrHome
      Output(5,13,"Game Over
   End
End
That probably could work, but here's a much more optimized version of the movement system (I think you're using a color calculator):

Code:

If G
Then
Output(E,F," " //I added the end quote to show that there is a white space here
max(1,min(26,C+sum(ΔList(G={24,26→C
max(1,min(10,D+sum(ΔList(G={25,34→D
End
Output(E,F,"*

Looks pretty complex right? I'll break it down the best I can.


Code:

getKey→G
If Ans //this detects if getKey is not 0. 0 is returned when no key is pressed

Then //I hope you know what this does :P

Output(E,F," " //I added the end quote to show that there is a white space here

//I'll break the  next line down into it's individual parts
max(1, //this sets the minimum value that the variable you want to change (in this case it's C) can be. I'll explain why it uses max( at the end

min(26, //this sets the maximum value that the variable you want to change (again, it's C) can be. I'll explain why it uses min at the end

C+sum(ΔList(G={24,26 //ok this is going to be the hardest to explain. I'll start from right to left
so
G={24,26 //this looks at variable G and compares it to the list {24,26}, depending on what G equals, this command will return  {1,0} if G equals 24, or {0,1} if G equals 26, or {0,0} if G doesn't equal 24 nor 26. (it cant return {1,1} because G cant equal two different values at the same time)

ΔList( //according to TIBasicDev, "ΔList( calculates the differences between consecutive terms of a list, and returns them in a new list." So if the previous command I explained  returned {1,0} (remember, this would happen if G=24) then ΔList( would return {-1} because 0-1=-1 . If it returned {0,1} (remember, this would happen if G=26) then ΔList( would return {1} because 1-0=1 . If it returned {0,0} (remember, this would happen if G didn't equal 24 nor 26) then ΔList( would return {0} because 0-0=0 .

sum( //this takes the list ΔList( returned and converts it into an integer. (or in Laymans terms, a plain number) So {-1} becomes just -1 and so on

C+ //this takes the value that sum( created and changes C accordingly. So if C equaled 5 at first, and sum( returned -1 , C would now equal 4 . And so on

//Gear shift: So why does it use max( for the minimum value? Because it's comparing (in this case 1) to the new C value to see which is bigger. If C>1 then it will return C because C is the bigger of the two options. If C<1 then it will return 1 because in this case 1 is larger. (If C=1 then it will just return 1)

//The same goes for min( , it's comparing (in this case 26) to C. If C>26 then it will return 26 because 26 is smaller, if C<26 then it will return C because C is smaller. (again, if C=26 it will return 26)

→C //don't forget to store the new value to C!


//This is exactly the same as the previous, only with different numbers and variable. In this case, C is just replaced with D, the minimum value of D can only be 1, the maximum value of D is 10,
max(1,min(10,D+sum(ΔList(G={25,34→D
End
Output(D,C,"*


I hope this helped!
Without getting too complicated, is there a way to optimise this code used to detect if the "*" hits a barrier?

Code:

If (C=1 and D<=5) or (C=1 and D>=7) or (D=1 and C<=11) or (D=1 and C>=15) or (D=10 and C<=11) or (D=10 and C>=15) or (C=26 and D<=5) or (C=26 and D>=7)
This was my attempt at writing an "A.I." for the enemies that follow your movements. However, when they get drawn in, it freezes and then gives a domain error

Code:

randInt(1,50)->X
   If X<=3
   // This determines if the enemy moves by drawing a random integer between 1 and 5. If it is three or less, it will move
   Then
      Output(G,H,"
      If (D<=5 and C<=13)
      // this looks to see if player is in top left quadrant
      Then
         randInt(1,2)->Z
         If Z=1
         Then
            G-1->G
         End
         If Z=2
         Then
            H-1->H
         End
         // This determins if the enemy will move up or side to side. 1=up 2=side to side
         Output(G,H,"+
      End
      If (D<=5 and C>=13)
      // This determins if the player is in the top right quadrant
      Then
         randInt(1,2)->Z
         If Z=1
         Then
            G-1->G
         End
         If Z=2
         Then
            H+1->H
         End
         Output(G,H,"+
      End
      If (D>=5 and C<=13)
      // This determins if the player is in bottom left quadrant
      Then
         randInt(1,2)->Z
         If Z=1
         Then
            G+1->G
         End
         If Z=2
         Then
            H-1->H
         End
         Output(G,H,"+
      End
      If (D>=5 and C>=13)
      // This determins if the player is in the bottom right quadrent
      Then
         randInt(1,2)->Z
         If Z=1
         Then
            G+1->G
         End
         If Z=2
         Then
            H+1->H
         End
         Output(G,H,"+
      End
   End

I am afraid I have gotten in over my head.
You asked about collision detection:

The reason I gave the relatively inefficient code that I did was for ease of understanding and for ease of adding in collision detection.

For each If-Then statement, you can add another if in to control the screen boundaries. For example,

Code:

If G=26
Then
X+1->X
End

Can become,

Code:

If G=26
Then
If X<26 //26=Right screen boundary
X+1->X
End


As for the AI, if I wanted to be able to add more enemies as the game progressed, I would store all the AI x and y values in a list.
dankcalculatorbro wrote:
You asked about collision detection:

The reason I gave the relatively inefficient code that I did was for ease of understanding and for ease of adding in collision detection.

For each If-Then statement, you can add another if in to control the screen boundaries. For example,

Code:

If G=26
Then
X+1->X
End

Can become,

Code:

If G=26
Then
If X<26 //26=Right screen boundary
X+1->X
End


As for the AI, if I wanted to be able to add more enemies as the game progressed, I would store all the AI x and y values in a list.


I'm not sure what you were trying to show with this code.
dankcalculatorbro wrote:
You asked about collision detection:

The reason I gave the relatively inefficient code that I did was for ease of understanding and for ease of adding in collision detection.

For each If-Then statement, you can add another if in to control the screen boundaries. For example,

Code:

If G=26
Then
X+1->X
End

Can become,

Code:

If G=26
Then
If X<26 //26=Right screen boundary
X+1->X
End


As for the AI, if I wanted to be able to add more enemies as the game progressed, I would store all the AI x and y values in a list.

That's inefficient and takes up room. This is the simplest way to do it.

Code:
If K=24 and X<#:X-1->X

Also, the Y variable doesn't work on any calculator, I would recommend X and Z.
What exactly do you mean by this? I have never had a problem with Y not working.

mets11rap wrote:
Also, the Y variable doesn't work on any calculator, I would recommend X and Z.
dankcalculatorbro wrote:
What exactly do you mean by this? I have never had a problem with Y not working.

mets11rap wrote:
Also, the Y variable doesn't work on any calculator, I would recommend X and Z.

Hm, interesting. It doesn't work for me or my friends.
After drawing the map and the enemy, the game freezes, and then either the enemy shoots out of bounds, (even though I thought it was coded to not allow that) or it will appear instantly be on top of the player. I have tweaked it several times, but it still doesn't seem to work. It also will randomly draw a second enemy.

Here is the link to the code: http://sc.cemetech.net/?hash=DvP3IvPTeQvWbQctucVT66fmSrmR

If you have some extra time, please look at it, laugh at the clutter, and maybe find a mistake. Thanks!
I think it is instantly going on top of you is because

Code:

If (D and C)=(G and H)

should be

Code:

If D=G and C=H

and it is shooting out of the map is because you used G for getKey and for your enemy's position. So if no keys are clicked it will set G to 0 causing it to be out of bounds (or at the value of getKey for the random second enemy).
mets11rap wrote:
dankcalculatorbro wrote:
What exactly do you mean by this? I have never had a problem with Y not working.

mets11rap wrote:
Also, the Y variable doesn't work on any calculator, I would recommend X and Z.

Hm, interesting. It doesn't work for me or my friends.


Due to an old bug in the calculator’s OS, the Y variable is reset every time you call ClrDraw.

According to the footnotes on the TIBD page this has been fixed on the CSE, but not the CE.
_iPhoenix_ wrote:
mets11rap wrote:
dankcalculatorbro wrote:
What exactly do you mean by this? I have never had a problem with Y not working.

mets11rap wrote:
Also, the Y variable doesn't work on any calculator, I would recommend X and Z.

Hm, interesting. It doesn't work for me or my friends.


Due to an old bug in the calculator’s OS, the Y variable is reset every time you call ClrDraw.

According to the footnotes on the TIBD page this has been fixed on the CSE, but not the CE.


I think this explains why one of my programs hasn't been working, I've been banging my head on the table trying to debug it for weeks. I kept thinking I had to be doing something wrong. Thanks for this information. Very Happy (Also, this is on my CSE but it's quite possible that I need to update it)
_iPhoenix_ wrote:
mets11rap wrote:
dankcalculatorbro wrote:
What exactly do you mean by this? I have never had a problem with Y not working.

mets11rap wrote:
Also, the Y variable doesn't work on any calculator, I would recommend X and Z.

Hm, interesting. It doesn't work for me or my friends.


Due to an old bug in the calculator’s OS, the Y variable is reset every time you call ClrDraw.

According to the footnotes on the TIBD page this has been fixed on the CSE, but not the CE.

Interesting. I have the latest OS and still can't use it.
Will outputting a character where something already is cause a domain error? That is the only thing that I can think about for why my program is giving an error:DOMAIN. Thanks.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement