Path: chuka.playstation.co.uk!news From: "Rikki Prince" Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: What do'you mean I have to brush up on me maths! Date: Tue, 22 Jun 1999 17:33:05 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 53 Message-ID: <7kodt4$33u26@chuka.playstation.co.uk> References: <7ko1jf$33u25@chuka.playstation.co.uk> NNTP-Posting-Host: th-gt145-002.pool.dircon.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Rad wrote in message news:7ko1jf$33u25@chuka.playstation.co.uk... > At the moment I have an enemy ship which only fires forward but I want the > bullet to travel in the direction of the player, but not follow the player. > So the bullet uses the player's x and y position when it is first fired and > continues traveling in that direction until it leaves the screen. > Well you just set the x and y of the bullet sprite to the x and y of the ship sprite, when the player presses the fire button. Then each loop you test whether a bullet has been fired, and if it had update its position. As for the angle to move it, I'm not too sure, but there's a few examples out there, such as Nick F's aw_special.zip from www.netyaroze-europe.com/~rookie1 I hope that helps in at least the slightest (not likely!) > I wrote some code ages ago based on Bresenham's algorithm that I might be > able to use but to be honest I can't be arsed to find it, plus I'm not sure > it will work for this. > > So any ideas on how I can do this? > > Thanks, > > Rad. > rad@cyberdude.com > http://www.netyaroze-europe.com/~radpsx > > p.s. another question: > > If I increment a variable every frame/program loop (i.e. counter++) > and want to do something if counter reaches x > then is it safe to do a test like this: if (counter == x) > or is it better to do this: if (counter >= x) ? > > I take it the second 'if' performs two 'if' statements where as the first > only performs one which makes the first one quicker? But is it safer? (i.e. > to assume that counter will ALWAYS increment by one). > > As far as I know, it shouldn't skip, so I don't think you'd need to check to see if its equal to or above than x. However, if you're changing the counter elsewhere, in other functions, it my not change once every frame, which would muck up your testing. If you definitely will never change the variable more than once per frame, then == should be ok. However, I don't know if there's any history of counters skipping, and if you're that worried, use >=, or do some testing.