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 / Syncing / Cls Issue

Author
Message
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 27th Jan 2009 22:54 Edited at: 27th Jan 2009 23:09
Okay, I'm starting a game and I'm n the very beginning of production, when i get this thing.

Okay, here's what it is:
You are the player circle (purple) trying to kill the enemy (blue) by shooting it with fireballs (red). The enemy has 10 hp, and you take away 5 hp from each hit of the fireball. Obviously, it takes two hits to kill. Gameplay goes: you click anywhere (for now) to select the enemy and then press 1 to shoot a fireball.

The problem is that something is up with the syncing, or I made a typo and can't catch or, or what, but it just totally messes up (you'll see if you run it, no media).

Oh, and here's the code:



~QJ
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 28th Jan 2009 18:33
From what I see, the fireball 'misses' the enemy, though it goes right through it. Use this code:
in place of your move_fireball routine. You could then eliminate your calc_damage routine altogether.

The reason it is 'missing' the target is that you are telling it that it has to be the exact same coordinates in order to register a hit, which is very unlikely to happen. You should also put a limit on the distance the fireball can travel.

I would suggest instead of using cls in your main loop, draw and move_fireball subroutines, to use the backdrop to redraw it.
Simply add the code:

to your setup subroutine and delete all of the cls'.

I assume you are using the circles as placeholders, but why not just use sprites, even if you make an image out of the circles? Drawing circles is slow.

LB

Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 28th Jan 2009 19:11
When using only 2d it should be faster to use a bitmap and cls to clear the screen instead of using backdrop. Also if using images instead of circle statement, sprites are slower than a simple paste image.


@Quirkyjim
I know of 4 ways to check a hit collision in 2d.

1) Use a CheckArea function. Check if the Fire position is within the box area of the enemy. When calling the function if it returns 1 then it hits.


2) Use a CheckDistance function. See if the Fire is within a certain radius distance of the enemy.


3) Use Sprite and check for collision. Although sprites are not tecnecly 2d.

4) Use memblock and check for color. This method is the most accurate but also the most complecated, but dispite that it's also still very fast!
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 28th Jan 2009 21:08
Quote: "Distance = abs( sqrt(DiffX*DiffX + DiffY*DiffY) )"

Dump the abs - it's redundant and unnecessarily processor consuming when using squared values.

Quote: "Although sprites are not tecnecly 2d"

I believe in the DirectX version 7 DBC is written, sprites are still 2d - actual BOBS or MOBS .

Enjoy your day.
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 28th Jan 2009 22:07
Quote: "Dump the abs - it's redundant and unnecessarily processor consuming when using squared values."

LOL, that's right. For some dump reason I keep thinking Distance might return a negative.
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 29th Jan 2009 17:02
I think I'll go with way #1, Ashingda. However, I have some questions.

1) Just making sure: X1, Y1, X2, and Y2 are the points of a box around the enemy circle, correct?

2) If so, how would I found out where those co-ords are?

Oh, and thank you all for your advice!

~QJ
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 29th Jan 2009 19:03 Edited at: 29th Jan 2009 20:00
1) Yes that's correct.

2) The enemie's XY position is the center of the circle. Simply take the enemy XY and subtract or add the radius value.

You dont really need the parenthesis it's just to clarify.

[edit]

hehe I copy and paste then forget to correct.
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 29th Jan 2009 19:41
Typo, typo, I see a typo! (2 actually)

~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 31st Jan 2009 03:18
btw I'm coming in here a little late but your program worked fine for me unless i held down the one button then the program froze up. if i just tapped it then it worked fine. i don't know why mine it working well kinda working lol

Login to post a reply

Server time is: 2025-05-18 05:49:41
Your offset time is: 2025-05-18 05:49:41