It is currently Tue Sep 25, 2018 4:42 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 8 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: AI aimingPosted: Fri Nov 04, 2005 6:13 pm

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2149
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

 Post subject: Posted: Fri Nov 04, 2005 6:49 pm

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20573
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

 Post subject: Posted: Fri Nov 04, 2005 7:42 pm

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

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

Top

 Post subject: Posted: Sat Nov 05, 2005 3:17 pm

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

 Post subject: Posted: Sat Nov 05, 2005 5:28 pm

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2149
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

 Post subject: Posted: Wed Nov 09, 2005 5:51 pm

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2149
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:
cmp #0
beq keepgoing
jmp morestuff

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

 Post subject: Posted: Thu Nov 10, 2005 10:10 am

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7522
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 8 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

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

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki