Jump to content
IGNORED

Aim Demo/Source


Mord
 Share

Recommended Posts

As I mentioned over in the homebrew forum, here's a demo/source/tutorial/etc showing a way to aim projectiles at a target. It's basically a way of setting the X and Y speeds of a projectile based on the coordinates of the firing enemy and the target. The source has some commented out code that can make the enemy a little less precise at aiming, which can be good for having it spread it's fire out.

 

You can move the player with player 1 controls, or the enemy with player 2 controls.

 

binaries, source, and a zip of both attached. :)

 

 

aim.bas.a78

aim.bas.bin

aim.zip

aim.bas

  • Like 9
Link to comment
Share on other sites

Thanks, hopefully someone finds it useful in their own games or at least gets them thinking. The demo has several places it can use improvement or be tinkered with, including making it a bit more generalized and turned into a standalone function, or adjusting the minimum speeds - or trying to cap a maximum speed. I'll be doing stuff like that in graze hopefully during this week along with a bunch of other things - weather pending. Heat makes me useless.

  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Hey would someone mind explaining a part of this code further please?

 

Particularly, these two lines:

if HeroX <= BulletX[z] then BulletDirection[z] = BulletDirection[z] | %00000010  else BulletDirection[z] = BulletDirection[z] & %11111101
if HeroY <= BulletY[z] then BulletDirection[z] = BulletDirection[z] | %00000001  else BulletDirection[z] = BulletDirection[z] & %11111110

I understand what an 'and' and 'or' operation is, but I don't understand what's actually happening here.

I copied these lines into my own code to see what happens. I had to flip the '<' signs and I also replaced 'BulletX' and Y with the 'enemyX' and Y variables. But after that my enemy sprites only fired imprecisely and only down and to the right. Does anyone know why I got that behaviour in my code as opposed to the precise shooting in this code? It's probably worth mentioning that I have two direction variables, one for up/down and one for left/right rather than just 'BulletDirection' which seems to be the case here.

 

I think I just need to alter the part after the 'else' to get it to fire up and left too, but unfortunately I don't know what's actually happening in order to change it.

Thanks for any help

Link to comment
Share on other sites

Those two lines are defining the direction for the bullet for vertical and horizontal directions via two bits in the "BulletDirection" variable.

 

Based on what I'm seeing above it looks bit 1 specifies if the bullet is travelling left or right, and bit 0 specifies up or down.

 

The bullet wants to go towards the player, so I guess if bit 1 is 1, it will travel left. if bit 1 is 0, it'll travell right. If bit 0 is 1, it'll travel up. otherwise, travel down.

 

All it's doing to determine this is comparing the screen coordinates of the target (the player) with the source (the shooting mob). If you switched the < conditions, you might need to switch the then and else portions of the if statements as well.

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...