It is currently Sun Dec 10, 2017 8:55 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: AI aiming
PostPosted: Fri Nov 04, 2005 6:13 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
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?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 6:49 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19322
Location: NE Indiana, USA (NTSC)
Have you heard of fixed-point math?

For each shot, store the displacement vector and the velocity vector. Every frame, add the velocity vector to the displacement vector.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 7:42 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I think the problem is determining the displacement vector in the first place, having it go the proper angle towards the player (and then to add the "I" of AI, to have it collide with the player will be if he doesn't change his course).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 12:51 pm 
i was wondering same thing. but what do you mean by displacment vector?


Top
  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 3:17 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
The vector here is a pair of values. The displacement is the movement of the object. Thus, a displacement vector tells how far to move the object in the X and Y direction each time unit.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 5:28 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
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:
Code:
;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


I just randomly named lables, by the way. Okay, do you think that would work? Is there anything wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 5:51 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2142
Location: Minneapolis, Minnesota, United States
Okay, I'm a little stuck on one thing. Here is my current idea:

Code:
stuffr:
        sec
        lda gy
        sbc ay
        sta yd
        sec
        lda ax
        sbc gx
        sta xd
   clc
   rts


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:

Code:
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



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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 10:10 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7312
Location: Chexbres, VD, Switzerland
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 :
Code:
ldy #$00
lda Divisor
- cmp Dividend
bcc +
sbc Dividend
iny
bne -
+

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.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group