Jump + Right / left commands

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Jump + Right / left commands

Stormtrooper2001
Hello guys,
I'm trying to make a 2d game in which my player can jump (Go up and come down) while i press the up key and Jump to the right if I press the up and the right arrow. To move my character around I implemented my code similar to the square dance program.
Any suggestions on this?
Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
The keyboard interface for the Hack is extremely limited in that it can only present the keycode for one key that is currently pressed. If you press more than one key at the same time, it picks one of them. There's no way to detect multiple keys.
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
Okay what if I make it such a way that if the user presses space it does the jump operation(which im not sure how to implement either any tips would be great) and then release the upper key and press right arrow?
Basically I want the system to read from the keyboard while executing a function. Is this feasible?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
What is the "upper key" that you are referring to?

If you want to read the keyboard while a function is executing, then that function needs read the keyboard at the moment that it wants to know what key is currently being pressed. You don't have to use the OS functions to do this -- remember, the key code that is currently being pressed is stored at RAM[24576] and you can use Peek to read it (unless the VM emulator implementation traps it, which it might).
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
Okay, I confused the upper key and the space key.
After some brainstorming, I came up with this idea at all times there is a constant force that pushes the character down so if I press the up arrow/space (i used them interchangeably by mistake) the char just jumps up and the right key after it mover alternating steps of right and down movements cuz of the function that ensures the char is pushed down at all times
However, now I face another issue. To read whether the char is in the air or on some block I used the peek function P=Memory.peek(((Y+size)*32)+((x+size)/16)) but i get an error saying "a built-in function tried to access a value outside the screen or heap "
what do i do?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
Stormtrooper2001 wrote
However, now I face another issue. To read whether the char is in the air or on some block I used the peek function P=Memory.peek(((Y+size)*32)+((x+size)/16)) but i get an error saying "a built-in function tried to access a value outside the screen or heap "
what do i do?
What are x and Y? What do they represent?

What is size? What does it represent?

What is the maximum value of x and Y?

What is the maximum value of size?

Using those maximum values, what is the maximum value of the memory address that you are passing to the peek() function? Is that value within the screen or heap?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
I tried a different implementation to solve the problem. However my x was in range(0 to 512) and y was in range(0 to 255)
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
So let's set size=1.

If x=512 and y=255, what address do you pass to the peek() function?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
 P=Memory.peek(((Y+size)*32)+((x+size)/16)) this is the address i passed. Sorry for the late reply .
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
Stormtrooper2001 wrote
P=Memory.peek(((Y+size)*32)+((x+size)/16)) this is the address i passed. Sorry for the late reply .
Do the math!

You are trying to figure out why you are getting an error that says that your program is trying to access memory that is outside the heap/screen.

So do the math and see what memory addresses your program might be trying to access.

You haven't given what the values of 'size' can be, so I'll just set it to 1.

IF X=0 and Y=0, what is the address you will be looking it?

P=Memory.peek(((Y+size)*32)+((x+size)/16)) => Memory.peak(32)

Is RAM[32] in the heap or screen?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
Hello size is the size of my char it is fixed and does not change it is around 5 along x-axis and 15/2 along y-axis(x+size) and (y+size) give the coordinates of the point just below my character along the center .
i noticed the error i changed it to P=Memory.peek(16384+((Y+size)*32)+((x+size)/16) but it still shows the same error . What do I do?
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
Stormtrooper2001 wrote
Hello size is the size of my char it is fixed and does not change it is around 5 along x-axis and 15/2 along y-axis(x+size) and (y+size) give the coordinates of the point just below my character along the center .
i noticed the error i changed it to P=Memory.peek(16384+((Y+size)*32)+((x+size)/16) but it still shows the same error . What do I do?
You have a single variable called size. What is the value of that variable? I can't tell from your description. You say it is 5 along the x-axis and 15/2 along the y-axis (which is 7, since Jack doesn't support non-integers). So what is size? Is it 5 or is it 7 or what?

Let's assume it's 5.

So when Y=255 (not the 256 max value you previously stated) and x=511, what is the address of the memory location you are going to try to access?

Again, do... the... math!

P=Memory.peek(16384+((Y+size)*32)+((x+size)/16)
P=Memory.peek(16384+((255+5)*32)+((511+5)/16)
P=Memory.peek(16384+(260*32)+(516/16))
P=Memory.peek(16384+8320+32)
P=Memory.peek(24736)

Is this within the Heap/Screen memory space?




Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

Stormtrooper2001
My Y and X are just integers (y+7) and (x+5) are the coordinates of the point right below my character
so:
0<(y+7)<255 and
0<(x+5)<511.
Sorry I used one variable called size which might have been confusing. Maybe I should have used different variables. I replaced the constant with size as I felt the constant wasn't of much importance. you can basically assume (x+size) as x and (y+size) as y.
Taking point (255,512)
P=Memory.peek(16384+(255*32)+(512/16)
P=Memory.peek(16384+8160+32)
P=Memory.peek(24576)
I think the error might be in the values of X and Y and not the equation itself. Will check that once more.
Reply | Threaded
Open this post in threaded view
|

Re: Jump + Right / left commands

WBahn
Administrator
If you are having a problem with a line of code that is throwing an error, then use THAT LINE OF CODE when talking about the problem and use the values that the variables in that line of code are actually using.