A group dedicated to indie and standalone game development.

Post tutorial Report article RSS Feed Modifying weapons (on Ubuntu)

Modification of M.A.R.S. weapons - a simple tutorial.

Posted by feillyne on Apr 20th, 2011
Basic Client Side Coding.

The tutorial assumes you've installed/compiled SFML2 and M.A.R.S. successfully:
Indiedb.com

First, navigate to the /src/ folder (it contains workable C++ files).

Then we'll head straight into the Weapons folder, and then open AFK47.cpp file.

Let's take a loot at this file. At the beginning there's a GPL licence, then files referenced/included by this particular weapon file.

Then we have AFK47::draw() function. It basically draws/shows the spaceship gun barrels in-game.

Farther down, we have another important function, AFK47::fire(), that spawns specific weapon's ammo (particles of the ammo, to be exact). We'll modify this weapon part a bit. ;-)

particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 - faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+( faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());
particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 + faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());

You don't see a difference between the two lines? How about this tiny fragment:

parent_->location().y_+( faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7))
parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7))

Quote:faceDirection.x
-faceDirection.x

(the second one is a negative value, -faceDirection.x)

So what will we do? We'll simply double the trouble AFK47 weapon does to opponents. Before:

particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 - faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+( faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());

Paste:

particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.7 - faceDirection.y_*parent_->radius()*0.7), parent_->location().y_+( faceDirection.x_*parent_->radius()*0.5 + faceDirection.y_*parent_->radius()*0.5)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());

And before:

particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 + faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());

Paste the code for the fourth particle spawner:

particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7), parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.5 + faceDirection.y_*parent_->radius()*0.5)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());

Now the whole fire() function code should look something like:

void AFK47::fire() const {
    float time = timer::totalTime();
    if (time - timer_ > 0.1) {
        timer_ = time;
        float angleRad = parent_->rotation()*M_PI / 180;
        Vector2f faceDirection(std::cos(angleRad), std::sin(angleRad));
        particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.7 - faceDirection.y_*parent_->radius()*0.7), parent_->location().y_+( faceDirection.x_*parent_->radius()*0.5 + faceDirection.y_*parent_->radius()*0.5)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());
        particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 - faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+( faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());
        particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7), parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.5 + faceDirection.y_*parent_->radius()*0.5)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());
	particles::spawn(particles::pAmmoAFK47, Vector2f(parent_->location().x_+(faceDirection.x_*parent_->radius()*0.9 + faceDirection.y_*parent_->radius()*0.9), parent_->location().y_+(-faceDirection.x_*parent_->radius()*0.7 + faceDirection.y_*parent_->radius()*0.7)), faceDirection, parent_->velocity(), Color3f(), parent_->getOwner());
        sound::playSound(sound::Laser, parent_->location());
    }
}

Okay, that's almost all, head to the /build/ folder and open up Terminal there, type:

Quote:make


A new version of M.A.R.S. - our own one - should be built. Type

Quote:cd .. && ./mars


or simply run the mars binary in the main M.A.R.S. folder.

And now, in-game:
Start Local Game -> DeathMatch (reduce the number of bots to 0) -> Weapon Options -> tick off all the Weapons options except AFK-47. Then Start, and if everything went well, you should see a quadrupled cannon ammo shot out instead of just the double one.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Established
Jan 21, 2009
Privacy
Public
Subscription
Open to all members
Contact
Send Message
Membership
Join this group
Group Watch
Track this group
Tutorial
Browse
Tutorials
Report Abuse
Report article
Share
Related Games
M.A.R.S. - A Ridiculous Shooter
M.A.R.S. - A Ridiculous Shooter Single & Multiplayer Arcade
Related Groups
Curly Bracket Programming Realm
Curly Bracket Programming Realm Hobbies & Interests with 75 members
Indie Devs
Indie Devs Hobbies & Interests with 1,233 members
Linux Gamers
Linux Gamers Fans & Clans with 2,913 members
M.A.R.S. Core Team
M.A.R.S. Core Team Developer & Publisher
Open Source Initiative (unofficial)
Open Source Initiative (unofficial) Other with 31 members
Ubuntu fans
Ubuntu fans Hardware & Tech with 20 members