small 2D shooter with some impressive effects

Advanced game related topics
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

lol, mp303. :lol:

Anyhow, now that it is established that you're always right (at least to the person who counts most) - how about helping out the folks who request solutions in "coding questions"? They can be sure they're getting good solid code and answers. :)
Dare2 cut down to size
mp303

Post by mp303 »

Dare wrote:now that it is established that you're always right...
all I've established so far, is my right to have an opinion. ;)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

One little question mp303, how did you make the bullets appear from that relative position?
I like logic, hence I dislike humans but love computers.
u9
User
User
Posts: 55
Joined: Tue May 09, 2006 8:43 pm
Location: Faroe Islands
Contact:

Post by u9 »

Joakim Christiansen wrote:One little question mp303, how did you make the bullets appear from that relative position?
I would recommend initializing the position and orientation of the bullets as follows:

Code: Select all

bullet\xPos = ship\xPos + cos( ship\angle ) * ship\radius
bullet\yPos = ship\yPos - sin( ship\angle ) * ship\radius
bullet\angle = ship\angle
No offence to anyone, bullet and ship are structs, not objects :P Anyways, this places the bullet centered in front of the ship. As the guns on the ship are a bit off-center, you can add that distance to the bullets initial position as follows:

Code: Select all

bullet\xPos = bullet\xPos + cos( ship\angle -90 ) * gunDist
bullet\yPos = bullet\yPos - sin( ship\angle -90 ) * gunDist
Where gunDist is the distance from the center of the ship to the gun. This code moves the bullet in front of one of the guns. Notice that to move the bullet in front of the other gun you need to add +90 to the ships angle instead of subtracting.

The angles I've used are in degrees, but in think (haven't checked, I'm at work) that the input to cos() and sin() should be radians. If so, you'll need to convert the input like this:

Code: Select all

... cos( ship\angle * Pi / 180 ) ...
Come to think of it, if Pi is not defined either you can approximate it using 22/7 - or maybe it's a constant (#Pi).

Anyways, hope this helps, or hopefully mp303 will give you the correct answer ;)
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
http://www.wirednerd.com
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Thank you u9, but I don't think it will help much in my case.

I have many different images (for different weapons) and for each I have a XY value of where the bullet should be created on the image, but when the image rotates i'm having difficulty calculating where this would be... :oops:
Last edited by Joakim Christiansen on Thu Jun 15, 2006 8:23 pm, edited 2 times in total.
I like logic, hence I dislike humans but love computers.
u9
User
User
Posts: 55
Joined: Tue May 09, 2006 8:43 pm
Location: Faroe Islands
Contact:

Post by u9 »

Ok, then I don't understand the problem. Maybe mp303 might know.
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
http://www.wirednerd.com
u9
User
User
Posts: 55
Joined: Tue May 09, 2006 8:43 pm
Location: Faroe Islands
Contact:

Post by u9 »

Does this help:
Image
This matrix rotates XY coordinates around the origo theta radians. But your XY coordinates need to be relative to the center by which you rotate your image. Let me know if you don't know how to multiply two matrices. The image is from wikipedia
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. (Nathaniel Borenstein)
http://www.wirednerd.com
mp303

Post by mp303 »

Joakim Christiansen wrote:Thank you u9, but I don't think it will help much in my case.

I have many different images (for different weapons) and for each I have a XY value of where the bullet should be created on the image, but when the image rotates i'm having difficulty calculating where this would be... :oops:
what u9 described, is basically what I'm doing.

your situation is a bit different. you probably need to create a vector from the origo of rotation, to the XY of your bullet's starting position. then rotate that vector around the same origo. (I don't know if that's at all useful to you - I'm not very good at "formal" maths, I just sort of look at things and use my common sense)
storck
User
User
Posts: 83
Joined: Sat Oct 18, 2003 4:56 pm
Location: Sweden

Thanks for sharing

Post by storck »

Thank you for sharing mp303.

What I have liked about this forum is that people can say pretty much what they want. Try saying PureBasic in the IBasic forum and chances are that your post is deleted or locked.

Why do we start all this oop thing all over? As far as I am concerned (no I am not god :-)) mp303 is entitled to his opinion as is every one else. If you can live without oop use purebasic, if not it is oviously the wrong tool. Buy something else.

Making the asumption that people are less eperienced programmers just because they use a basic langugage is just plain stupid. Most people here use other languages as well. It is possible to develop pretty much any software using pretty much any programming language. Like all other things in life it is a question of selecting the right tool for the job you want to get done. You can even do a lot of things with the wrong tool, it's just more work.

Why do I even bother, it is all so obvious - isn't it?

Have a nice summer all!

// Storck
mp303

Re: Thanks for sharing

Post by mp303 »

storck wrote:Making the asumption that people are less eperienced programmers just because they use a basic langugage is just plain stupid.
I never made that assumption, certain others just assumed that I did.

What I said was, that a lot of beginners use Basic, which is the truth. I think PB is a pretty damn good Basic for beginners, as in a single day, I was able to teach my 11-year old boy how to do a basic sprite that moves around on screen and fires a bullet. I myself was doing similar stuff at that age, studying the excellent "kiddie programming books" (don't remember their names) for the C=64 by Erwin Neutzky-Wulff...

Anyways, I never said that 11-year olds was the ONLY audience for a Basic compiler. That was somebody else's assumption.

Basic is an excellent learning language, was basically my only point. I never said that's all it was good for.
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

This is old now. Time to beat swords into ploughshares, methinks.
Dare2 cut down to size
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

mp303, How are you able to draw a sprite smooth like that?
I like logic, hence I dislike humans but love computers.
mp303

Post by mp303 »

well, more people have had questions, and let's be realistic - I'm never going to finish this ... so I've decided to make the source code available:

download here.

Enjoy! :)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

mp303, Thank you, that's very nice of you! :D
I like logic, hence I dislike humans but love computers.
storck
User
User
Posts: 83
Joined: Sat Oct 18, 2003 4:56 pm
Location: Sweden

Post by storck »

@ mp303
Are you going to tell me that this forum is full of programmers with many years of experience with lots of different high-level programming languages? I think you'd be wrong.
Sounds a little bit like making the asumption that people here are less eperienced programmers. A lot of people here have been programming for years and a fair share have been using different (if not lots of) high-level programming languages as well.

Anyways, who really cares. Why don't we just go on with our lives. I am sure that you never intended having this discussion when posting your demo. I should have kept my mouth shut. For me this debate ends right here. I think your demo is great. Also, thank you for sharing the source.

// Storck
Locked