Log In  

Hi all.

A newbie question!

I am using the PGET command to read the value of a pixel as you move a point around the screen.

The code I have written seems to work fine in the X axis, but the y-axis is offset for some reason.

If you move the point over the yellow square from left to right, the PGET command successfully reads the pixel colour value.

If you move the point over the yellow square from top to bottom, the PGET command is offset by approx 6 pixels.

Strange.

Am I missing something?

Any advice would be very much appreciated.

Many thanks

Paul :-)

PS:

Code pasted below.

x={}
y={}
x=50
y=50
cls()

function _update()
if btn(1) then x=x+1 end
if btn(0) then x=x-1 end
if btn(3) then y=y+1 end
if btn(2) then y=y-1 end
a=pget(x,y)
end

function _draw()
rectfill (0,0,124,124,0)
rectfill (50,50,70,70,10)
pset(x,y,7)
print(a)
end

P#40796 2017-05-20 10:46 ( Edited 2017-05-21 20:22)

print(a) scrolls the screen upwards.
comment your black rectfill to see what really happens
print(a,0,120) to fix the problem
cheers :)

P#40800 2017-05-20 14:48 ( Edited 2017-05-20 18:48)

Ultrabrite,

Many thanks for your help! That did the trick. I hadn't considered that the print command was scrolling the screen.

I am trying to write a little 2d mining game, and am just testing out a few ideas for collision detection. The first method I have tried is based on checking pixel colours below and next to my sprite. If the colour is "black", representing rock in my game, then the Y value of the sprite doesnt change. If the colour is blue (that is, air in my world), then the sprite drops until it sees a black pixel again - simulating falling under gravity I guess. Likewise, if there are black pixels immediately to the left or right of the sprite, it prevents further travel in that direction. The 'rock' blocks the way.

This seems to work ok (although not perfect by any means) for simple worlds (created using a sprite map), but Im still trying to figure out how to mine down, through rock, by adding blue pixels below the sprite upon a key press. It works in the single game cycle during which the little man digs, but because of the CLS() command, the blue space he created from mining is wiped out the next time the game cycle repeats. He can still travel down, but the CLS() wipes out his mining progress!!

I think there must be a better way to do this using sprite maps and collisions between sprites, but I am not sure if sprites can be "pasted" during game play, so that I can paste a blue sprite under the character when he starts mining, and the copy of the sprite will stay there. Needs more work. Its good fun playing around to figure what works and what doesn't - its the best way to learn I guess!

Anyway, off to do more experimenting :-)

Thanks again for the help.

Kind regards,
Paul.

P#40825 2017-05-21 16:22 ( Edited 2017-05-21 20:22)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 12:25:50 | 0.005s | Q:12