Smash Project

Hey there! I thought I would show you a small project I've been working on. This project (currently dubbed "Smash") was to test networking in Gamemaker:Studio and try to make a simple multiplayer mobile game.

The main idea is that each player will have to collect power-ups (the rotating circles) to get new powers. There will be an attack power that allows the player to smash through other players thus eliminating them.

There are still a lot of bugs. I'm going to completely rewrite the networking code (and hopefully share it with you). However some basic things work: physics, player state and power-ups, cool trail effect. I made the trail effect using a tutorial so it's not actually original. I think it looks pretty cool though.

The game uses GM:Studio's physics (which implements the Box2D library). You swipe or click and drag to move. This applies a force on the object in the swipe direction:
(player step event)
if mouse_check_button_pressed(mb_left) { //mouse pressed?
    if !mouseJustPressed {
        x1 = mouse_x; //pressed down position x
        y1 = mouse_y; //pressed down position y
        mouseJustPressed = true;
else {
    if mouseJustPressed { //mouse was pressed but now is not meaning it was just released
        if canSwipe || PlayerState == STATE_AGILE {
        canSwipe = false; //allows only one swipe before the player hits a wall and stops
        x2 = mouse_x; //released position x
        y2 = mouse_y; //released position y
        //creates an angle based on the pressed position and the released position
        angle = point_direction(x1, y1, x2, y2) + 90; //90 degrees was added to turn the angle correctly
        pwr = point_distance(x1, y1, x2, y2)/5; //finds the distance b/w the press pos and the release pos

        phy_rotation = -angle; //physics rotation is inverse of nornal angles
        physics_apply_local_impulse(0, -1, 0, pwr*speedMult); //force applied based on angle and power
        mouseJustPressed = false; 

This looks complicated but is actually pretty simple. The first part checks if the mouse has just been pressed and if it has it assigns the mouse x and y to x1 and y1. When the mouse is released, the mouse x and y is assigned to x2 and y2. An angle is then calculated using Gamemaker's built in function "point_direction()". I had to add 90 degrees to this angle (something about the way box2d uses angles). The physics rotation is set to the negative of this angle (also to do with the differance between normal Gamemaker angles and box2d angles). A local force is then applied using this angle.
(Note: this is not exactly the code I used as I have set up a server-client network system. The player actually stores variables that are altered by the server. The server changes these variables every time the client associated with the player swipes the screen.)

More projects and code coming!


Popular Posts