I coded some enemies and the parallax effect for
the game. The enemies I did were: the bird,
the frog and a falling dandelion seed.
Bird
The Bird is a simple enemy which flies
from right to left and kills the player on
impact
The Bird
Frog
The Frog at first seems like the bird,
only on the ground. But it is way more
dangerous. When the player flies through a hit
box in front of the frog, the frog will
jump and try to catch the player midair.
The Frog
Falling Seed
The seeds are an enemy, which
was coded but not implemented. It was
supposed to be a hazard from up above. It would
fall downwards in a sinus curve to
emulate the wind hitting the seed and the
player would have to avoid it.
Parallax Effect
As with every old-school arcade game we used the
parallax effect to simulate depth, but as a
deliberate design choice instead of being limited by
our resources. I was in charge of Coding the effect,
while Elizabeth Seeman would draw the background
layers. The Effect works by displaying the same
three pieces of background three times in a row. The
camera would then move to the right while the pieces
would follow with different velocities to simulate
the depth of moving.
When a certain point is reached the first background
would be set to the end of the last background to
simulate a permanent background.
public class Parallax : MonoBehaviour{
private float _lenght;
private float _startpos;
public GameObject cam;
public float parallaxEffect;
public float scrollspeed;
// Start is called before the first frame update
void Start()
{
_startpos = transform.position.x;
_lenght = GetComponent<SpriteRenderer>().bounds.size.x;
}
// Update is called once per frame
void FixedUpdate()
{
float temp = (cam.transform.position.x * (1 - parallaxEffect));// helps with resetting the background
float distance = (cam.transform.position.x * parallaxEffect);// distance is calculated relative to the main camera
transform.position = new Vector3(_startpos + distance, transform.position.y); //relative Position of Background is done here
cam.transform.position += new Vector3(scrollspeed, 0); //automatic forward movement is defined here -> the higher the scrollspeed added the higher the movement
//reset values when border is reached
if (temp > _startpos + _lenght-1) _startpos += _lenght;
else if (temp < _startpos - _lenght+1) _startpos -= _lenght;
}