Creating The Game Pong

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

Creating the Game Pong

Alvian Bastian, S.ST., M.Sc.


Resources
Download resources file dan simpan pada folder Data untuk Project Game

Background: 800x600 px
Shapes
Menampilkan background game

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Shapes
Menampilkan background game
Shapes
Menambahkan pad 1

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Shapes
Menambahkan pad 1
Shapes
Menambahkan pad 2 dan ball
//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);
Shapes
Menambahkan pad 2 dan ball
Movement
Menggerakkan pad 1

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Movement
Menggerakkan pad 1
Movement
Mencegah pad melewati window

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Movement
Mencegah pad melewati window
Movement
Menggerakkan ball dan mencegah ball melewati window

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Movement
Menggerakkan ball dan mencegah ball melewati window
AI and Collision
Menggerakkan pad2 dan mencegah keluar window

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
AI and Collision
Menggerakkan pad2 dan mencegah keluar window
AI and Collision
Membuat bola memantul

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
AI and Collision
Membuat bola memantul
AI and Collision
Mengatur kecepatan bola

//States
bool up = false;
bool down = false;

//Variables
int yVelocityPad1 = 0;
int xVelocityBall = -4;
int yVelocityBall = -4;
int yVelocityPad2 = 0;

////////Shapes
//background
sf::RectangleShape background;
background.setSize(sf::Vector2f(800, 600));
background.setPosition(0, 0);
background.setTexture(&tex_background);

AI and Collision
Memasukkan sound

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
AI and Collision
Memasukkan sound
Finishing
Meletakkan Score
//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Finishing
Meletakkan Score
Finishing
Menambahkan score

//Libraries
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <SFML/Audio.hpp>

//Global variables, functions, classes

int main()
{
//Creating the window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Game");

//setting the framerate limit to 60 fps


window.setFramerateLimit(60);

window.setKeyRepeatEnabled(false);

//variable that keeps the game loop running


bool play = true;
Finishing
Menambahkan score
Finishing
Release program untuk mendistribusikan game

Rubah debug ke release

Jalankan program

Setelah itu close program


Finishing
Release program untuk mendistribusikan game

Copy dll file dan folder Data pada game


Finishing
Release program untuk mendistribusikan game

Paste ke folder Release


Finishing
Release program untuk mendistribusikan game
Jalankan program exe, dan game siap didistribusikan (file debug bisa dihapus)

You might also like