about summary refs log tree commit diff stats
path: root/update.sh
blob: 22ff05c648bc5c070a6e579442ee1721a05f3e09 (plain) (blame)
1
2
3
4
#!/bin/sh

git fetch
git checkout origin/master -- dscip
#0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "pong.h"

void ball(Rectangle *Player, Rectangle *Enemy, struct Balls *Ball, int *PlayerScore, int *EnemyScore) {
	
	bool NoEnemy = false;
	if (Enemy == NULL) {
		NoEnemy = true;
	}

	/* Moves */
	int CurrentTick = SDL_AtomicGet(&Ticks);
	if(Ball->NextTick <= CurrentTick){
		int RunThisManyTimes = 0;
		if (CurrentTick > Ball->NextTick) {
			RunThisManyTimes = (CurrentTick - Ball->NextTick);
		}
		int i = 0;
		for (i = 0; i <= RunThisManyTimes; i++) {
			Ball->Y += Ball->Angle;
			if (Ball->Direction == LEFT) {
				Ball->X -= Ball->Speed;
			} else {
				Ball->X += Ball->Speed;
			}

			/* Moves hitbox with ball. */
			Ball->HitBox.x = Ball->X;
			Ball->HitBox.y = Ball->Y;

			/* Check collisions against players. */
			if (CheckCollisionRecs(*Player, Ball->HitBox) && Ball->Direction == LEFT) {
				Ball->Direction = RIGHT;
				Ball->Speed *= 1.5f;
				if (Ball->Speed > 40) {
					Ball->Speed = 40;
				}
				if (Ball->Speed != 40) {
					Ball->Angle = GetRandomValue(-10, 10);
				} else {
					Ball->Angle = GetRandomValue(-30, 30);
				}
				play_audio(0);
			}
			if (NoEnemy == false) {
				if (CheckCollisionRecs(*Enemy, Ball->HitBox) && Ball->Direction == RIGHT) {
					Ball->Direction = LEFT;
					Ball->Speed *= 1.5f;
					if (Ball->Speed > 40) {
						Ball->Speed = 40;
					}
					if (Ball->Speed != 40) {
						Ball->Angle = GetRandomValue(-10, 10);
					} else {
						Ball->Angle = GetRandomValue(-30, 30);
					}
					play_audio(SOUND_BOUNCE);
				}
			}
			/* Bounce ball if touches top or bottom of screen. */
			if ( (Ball->Y+32 >= 720 && Ball->Angle >=1) || (Ball->Y <= 0 && Ball->Angle <= -1) ) {
				Ball->Angle *= -1;
				play_audio(SOUND_BOUNCE);
			}
		}
		Ball->NextTick = SDL_AtomicGet(&Ticks)+1;
	}

	/* Calculates score and resets ball. */
	bool Scored = false;
	if (Ball->X < 0 && NoEnemy == false) {
		*EnemyScore += 1;
		Scored = true;
	} else if (Ball ->X > 1280 && NoEnemy == false) {
		*PlayerScore += 1;
		Scored = true;
	} else if (Ball->X > (1280-32) && NoEnemy == true) {
		*PlayerScore += 1;
		Scored = false;
		Ball->Direction = LEFT;
		play_audio(SOUND_PLAYER_SCORE);
	} 
	if (Scored == true) {
		Ball->X = 1280/2.0f;
		Ball->Y = 720/2.0f;
		Ball->Speed = 3.0f;
		Ball->Angle = 0;
	}

	return;
}