AI aiming
Moderator: Moderators
-
- Posts: 2158
- Joined: Sun Jun 05, 2005 2:04 pm
- Location: Minneapolis, Minnesota, United States
- Contact:
AI aiming
Okay, I'm currently designing a short little game where you are a flying saucer, and you are flying around trying to shoot this guy below to get points. So, what is hard about this is that there are two cannons trying to shoot you down. Okay, I am wondering how to do this. I was trying to find out a way to say increase cannon balls x pos and y pos according to saucer's x and y pos. I know how to compare the x and y poses, but I don't know how to say the "increase according to" part of it. Any suggestions?
-
- Posts: 2158
- Joined: Sun Jun 05, 2005 2:04 pm
- Location: Minneapolis, Minnesota, United States
- Contact:
Yeah, how would you even detirmene the displacement vector in the first place? This is what I was confused about. I'm going to brain storm here:
I just randomly named lables, by the way. Okay, do you think that would work? Is there anything wrong?
Code: Select all
;ay = y coord of the upper left tile of the 2x2 saucer sprite
;ax = x coord of the upper left tile of the 2x2 saucer sprite
;gy = y coord of the cannon
;gx = x coord of the cannon
;iy = y coord of the cannon ball
;ix = x coord of the cannon ball
;yd = y distance
;xd = x distance
;yd1
;xd1
stuff:
sec
lda gy ;since y coord increases as it goes down the screen
sbc ay ;subtract ay from gy
sta yd
sec
lda ax ;since it's the other way for x coord
sbc gx ;subtract gy from ay
sta xd
stuffr:
lda yd
and #$07
sta yd1
lda xd
and #$07
sta xd1
stuffe:
ldx yd1
strwr:
inc iy
dex
bne strwr
stufft:
ldx xd1
sarst:
inc ix
dex
bne sarst
-
- Posts: 2158
- Joined: Sun Jun 05, 2005 2:04 pm
- Location: Minneapolis, Minnesota, United States
- Contact:
Okay, I'm a little stuck on one thing. Here is my current idea:
Okay, I have that. ax and ay are sprite vars, gx and gy are sprite vars for the cannon, and xd and yd stand for x distance to the cannon and y distance to the cannon. Okay, what I'm trying to do is this:
I think that code looks like it'd work. The logic is simple. If xd= 10 and yd= 2, you want to divide xd(10) by yd(2) and ix will increase by 5, then iy will decrease by 1! But of course, my problem is I don't know how to divide xd by yd! Any suggestions? And does this code look good?
Code: Select all
stuffr:
sec
lda gy
sbc ay
sta yd
sec
lda ax
sbc gx
sta xd
clc
rts
Code: Select all
stuff:
load xd1
cmp #0
beq keepgoing
jmp morestuff
keepgoing:
load xd
divide by yd
store in xd1
morestuff:
inc ix ; cannon ball
dec xd1
bne return
dec iy
rts
return:
rts
Yeah, I also have a lot of trouble for division. Some CPUs have a DIV instruction, but the 6502 doesn't, and doing it via a binary way is often glitchy/incomplete.
A simple way to do it is :
You exit with A=rest and Y=quotient. This way have no flaws, it even hold divison by zero, where Y will stay at zero and A will keep the rest, but it will cycle 256 times while doing stupid substractions by zero. That's the only problem, it will be way to slow with low dividends. There exists other methods, but I'm unable to get how they works, and they often doesn't work very accuratly.
A simple way to do it is :
Code: Select all
ldy #$00
lda Divisor
- cmp Dividend
bcc +
sbc Dividend
iny
bne -
+
Useless, lumbering half-wits don't scare us.