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.

Newcomers DBPro Corner / 2D hitscans?

Author
Message
Yakkers
13
Years of Service
User Offline
Joined: 15th Jul 2011
Location:
Posted: 29th Aug 2011 04:28
I've been playing around with making a 2D top-down shooter, wasd to move and mouse to aim and shoot. I'd like to implement hitscans for the shooting (http://en.wikipedia.org/wiki/Hitscan).

My only idea was to use the line command to draw a yellow line for one frame and then use a for command nested in another to check each pixel of the sprite's hitbox if it's touching the yellow color, but this was much far CPU intensive and I'm sure there's a better way to do it. It also doesn't matter to me if it requires a visible line or not, without would perhaps be better because then I could implement a separate one purely to be cosmetic.

I did some research both here and elsewhere on how hitscans are typically coded with no results, so does anybody have ideas on how it could be done with DBPro's commands?
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 31st Aug 2011 23:49
I've never heard of the term "hitscan" but if I understand this correctly, you want to be able to shoot at a target and instantly know whether the player has hit the target, without seeing a bullet move across the screen?

If so then what you can do is create a bullet sprite (a dot say) move it along the line of fire, detect if it's hit a target but do all of this without refreshing the screen.

The below example uses this idea. It's a bit basic, use the up and down arrow keys and spacebar to shoot. The invisible bullet will move horizontally to the right. If a hit is score the word hit will appear on the screen (just under the instructions), otherwise the word miss appears.





I hope this makes sense and is what you're after.

Login to post a reply

Server time is: 2024-11-22 16:57:25
Your offset time is: 2024-11-22 16:57:25