In year 3547, civilizations all over the galaxy have settled their own planets, living in peace and harmony with its environment. But outside the contemplative habitats, the GREAT WAR is raging. As a famous fighter on your way to never ending honor and prosperity, you have to protect your planet from the oncoming doom of your jealous neighbours! Please post all support issues in the forums for the game.

Post tutorial Report RSS Modifying weapons (on Ubuntu)

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

Posted by on - 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))

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:

make


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

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
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
M.A.R.S. - A Ridiculous Shooter
Platforms
Windows, Mac, Linux
Developer & Publisher
M.A.R.S. Core Team
Engine
Custom
Contact
Send Message
Homepage
Marsshooter.org
Release date
Game watch
Follow
Tutorial
Browse
Tutorials
Report
Report
Share
Related Games
Related Groups
Curly Bracket Programming Realm
Curly Bracket Programming Realm Hobbies & Interests with 76 members
Indie Devs
Indie Devs Hobbies & Interests with 1,637 members
Linux Gamers
Linux Gamers Fans & Clans with 2,971 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 33 members
Ubuntu fans
Ubuntu fans Hardware & Tech with 20 members