top of page
Search
  • Writer's pictureNg Wei Shun

Space Defenders Devlog 1

Updated: Apr 1, 2020

(Before we start, you can play the latest version of Space Defenders at Stencyl Arcade by clicking here.)


For our second Assignment for Fundamentals of Game Technology class, we were tasked to make a space shooter game and add our own touch to it. An example of a space shooter game is the famous Galaga, which pioneered arcade gaming.

Gameplay of the timeless classic, Galaga


In a classic space shooter game, enemies would fly towards you and damage you like a suicidal bomber, or they shoot projectiles towards you that damage you as well. This created a chaotic bullet hell gameplay. Although bullet hell games are fun, I wanted to experimnt on a different type of gameplay where the enemies mainly attack an objective instead of you.


And that’s how Space Defenders was born.


The idea also stemmed from my recent playthrough of the Battlestar Galactica board game, where Human players can pilot ships to defend their space station against alien spaceships.


With that said, let’s start with the art assets.


Making Collecting art assets


I’m gonna be honest, I’m no artist. Even the thought of making art for a game of this scale scares me. So I went and found art on OpenGameArt.org, which I will link below: -



Though, these spaceship assets were way too big, even when I scaled them down in Stencyl. So, I had to rescale them from 1024x1024 to 128x128 in Photoshop.


The background of the game also needed to be seamless, since I wanted the map to be able to scroll infinitely. Turns out ‘seamless space background’ did not show many good results. I did manage to find one that I deemed suitable.

Setting up the game scene


The setup of the game would have the player start at the bottom right of the screen, right next to the space station in the center of the map.

Setup of the game


Because I didn’t want the players to be able to see the whole map, as that would make it too easy for the players to defend the space station if they could see every enemy at a glance, I made the game scene way bigger than the screen, then have the camera follow the player.

Size of the scene, which equates to 1280x1024

Size of the screen, also meaning size of the camera

Code to have camera center on the player


I also made the background to constantly scroll vertically on its own, to add a sense of movement, as many classic space shooter games do as well. This is done by adjusting the scroll speed of the background.


Creating player controls


Let’s start with player controls so that I can move around the game to see if everything works as intended.


I used the 4-way movement behaviour in Stencyl. I chose to not use 8-way behaviour this time as the assets did not have diagonal versions (it also made it easier to code, more on that later). I would consider coming back and change it to 8-way-movement if I deem it necessary.


I wanted to add linear damping to the player movement to allow the player to slide across the map after they released the movement keys. I remembered learning this in class, mainly because it was the first online class we had (of which later on turn out to be many). But when I added it, the ship would stop instantly as usual instead of sliding after the movement keys were released.


At first, I thought it was because the value of linear damping was too low, as I set it to be 0.5. I then tried setting it to be 20, an extreme value but I wanted to be sure that it was the value that was causing problems.


It wasn’t.


I was confused, as I clearly remembered using linear damping in our class exercise. I then referred to the exact exercise, and I realised the problem.


In the exercise, we coded movement for the player on our own, instead of using Stencyl’s built-in behaviour. The difference was that Stencyl’s behaviour instantly sets the ship’s speed to 0 once the movement keys were released, and our code didn’t.


And thus, I stopped using Stencyl’s behaviour and made my own.

I could have modified Stencyl’s behaviour to do whatever I needed, but I found it hard to capture everything that Stencyl’s behaviour was doing in my head, as is for all code that is not your own without some sort of explanation. (Stencyl's behaviour so long that I decided to not include it here, not like anyone would bother going through it)


Now, I have a ship that can slide across space.

Until it gets blocked by the space station.

At first, the space station had a square collision box. I then changed it into a circle to fit the size of the space station.

The space stations's collision shape, not to be confused with Leonardo Da Vinci's Vitruvian Man


However, I felt that was not a lot of space (pun not intended) for the player to move, especially above and below the space station. It was then that I decided to let the player move across the ship instead to make movement easier. I did this by changing the collision groups and their interactions with each other.

The ship(player) will not collide with space station(actor)


Now, I have a ship that can slide across space without obstructions.


Next, let’s make the ship shoot stuff.


This is pretty easy. I just create a bullet at the front of the ship when the spacebar is pressed.

But bullets need to travel. How do we decide where the bullet travels (or in technical terms, its x-speed and y-speed) towards depending on where the ship is facing?


I solved this problem by tracking the player’s last pressed direction key using a game attribute and saving it as a number (1 for up, 2 for down, 3 for left, 4 for right). I then use this number to determine the x-speed and y-speed of the bullet. This is a solution I came up with because I was using 4-way movement. This solution would be way more complicated with 8-way movement(again, I’m still considering 8-way movement if I deem it necessary).

Alternatively, I could use two Booleans ‘isLeft’ and ‘isUp’ to see if the last pressed horizontal key was left and the last pressed vertical key was up respectively. If they were, it would set the x-speed or y-speed to negative. The reason this should be considered is because Booleans is known to be more memory-efficient than numbers, which would make the game run smoother.


Also, as seen in the code, I wanted the bullet to disappear after travelling a certain distance, to discourage players from shooting at enemies from a distance. However, there was no block in Stencyl that tracks how far an actor has travelled. I resorted to kill the bullet after a set amount of time, which roughly translates to the same thing in the end. (Speed=Distance/Time, because speed of the bullet is set, making distance a fixed value would make time a fixed value as well, and vice versa)


And that’s it for now. I now have a ship that can move freely in a space environment that scrolls infinitely and can shoot bullets that travel based on where the ship was facing, and a space station that doesn’t block the ship’s movement.


Later on, I will make enemies that spawn around the map and move towards the space station and reduce the space station’s health.


Thanks for reading.

17 views0 comments

Comments


bottom of page