Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / sprite collision messup?

Author
Message
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 23rd Jun 2009 06:20
I have done the sprite collision on my game and on the Y collision
it works fine but on the X collision it sometimes goes past the
collision a few pixels and if your up against the a X wall you can't
go up or down.Works fine on the Y collision though.

-Try attachment.

-Here's the code.

[img]null[/img]

If at first you don't succeed-Pause-Go to last checkpoint

Attachments

Login to view attachments
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Jun 2009 13:44
Your movement sub doesn't have a return.
A few things could be tidied up here, then we'd have a better chance of seeing what's going wrong, or even solve it in the process.

You draw everything twice, get rid of the second block.
You have a strange way of updating x/y this can be put into one statement.

The old values never seem to be used, they only change value when the player hits a wall. Your problem probably comes from the use of these old values. I can't see why you need them so I'd say ditch them.

Your movement code could be shorter. We want to be able to move our chocobo in eight directions; so there are eight possible values for movement. We can use binary numbers to stack each key into one variable: Up=1, Right=2, Down=4, Left=8.

Then to adjust x/y we could do this


There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Jun 2009 13:51
Or we could store movement for each direction in an array beforehand.


A real benefit of having one variable is animation. For each direction we can assign a start and end image using an array.

Here walking up displays images 1 to 6, while walking right is 7 to 14.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 24th Jun 2009 18:50
I have a similar problem to his except mine occurs when I'm on the left side of an object and I try to move left. It registers collision, yet the blocks are no where near touching yet and the code only stops my block from moving in that direction if they collide. The weird thing is, I'm able to halfway move, it doesn't stop me completely. Look in the attachment to see what I'm talking about.

Attachments

Login to view attachments
t10dimensional
15
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 24th Jun 2009 20:15
@pictionary
Your box needs to move a little to the left.

@OBese
I have a return for my movement:,The done: is used as a goto.(I know no-one likes goto's but I find them Quiet useful).If you don't want me useing oldx and oldy then what do I use?I only wanted the player to go in 4 directions and I spent alot of time geting it just right.But what is bothering me is the Y collision works fine but the X is ~D up.

Whats the "!" and the "&" do on DB?

If at first you don't succeed-Pause-Go to last checkpoint
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 24th Jun 2009 20:26
they are binary operators, let obese explain them though, last time I attempted to I looked like an idiot

There are only 10 kinds of people in the world, those who understand binary and those who dont
pictionaryjr
15
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 25th Jun 2009 00:02
It's not that my boxes are too far to the left.
I tried making them smaller, Moving them to the left, Making them smaller and moving them to the left, but nothings working. It's like every object on its left side has an imaginary part of it sticking out, like in this picture.

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Jun 2009 05:01 Edited at: 26th Jun 2009 05:09
@razer
Quote: "my movement has a return"

Oh I see it's the "done" label that has no return, eesh that's not a pretty way of doing it though I have to say. I don't see the need for it; you do realise that if a condition is found to be false (eg "if 1=0") then none of the code inside the condition will be executed. So if you took out the "done" the only difference would be that the other three directions are checked and skipped over.
If you want to keep your direction variable as it is you might want to use SELECT.


You asked about & (and) and ! (not), there's also | (or).
NOT is the simplest to explain: it compares the bits (binary digits) of two numbers and returns a 1 if any bit from one number is different to the corresponding bit in the other.
AND and OR work in a similar way: AND will return the value of all bits that are 1 in both numbers eg 5 & 6 = 4

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Jun 2009 05:09
because both contain the third bit (4).
5 = 101
6 = 110
OR will return the value of all bits that are present in either number. eg 5 | 6 = 7 because together they cover all of the first three digits, which totals 7.

I did some playing around with these logic operators using memblocks of images, you can pick out single colours and tweak them to make some cool filters. I made one that makes the image look kind of like a painting.
BTW the way I used & originally wont work, I'll work on a better solution for you.

There is an eight letter word. You can insert a letter into it or remove a letter from it without changing its meaning. Answer
That1Smart Guy
15
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th Jun 2009 05:47
sorry for going off topic but I have to ask

obese, you mentioned you know stuff about image memblocks, could you stop by my green screen thread and check that out, thanx!

There are only 10 kinds of people in the world, those who understand binary and those who dont

Login to post a reply

Server time is: 2024-05-20 10:13:10
Your offset time is: 2024-05-20 10:13:10