ソースを参照

initial commit

master
sauer2 2年前
コミット
de770a9714
4個のファイルの変更381行の追加0行の削除
  1. 222
    0
      .gitignore
  2. 17
    0
      Makefile
  3. 119
    0
      main.cpp
  4. 23
    0
      main.hpp

+ 222
- 0
.gitignore ファイルの表示

@@ -0,0 +1,222 @@
*.dll
*.exe
*.o
*.lnk
SFML21/
mingw32/

#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

#############
## Windows detritus
#############

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

+ 17
- 0
Makefile ファイルの表示

@@ -0,0 +1,17 @@
CC = g++
CFLAGS = -O2 -Wall -Wextra -std=c++11
# to avoid the console window with mingw, add -mwindow

INC = -I "SFML21/include"
# for Linux
LDFLAGS = -L "SFML21/lib" -lsfml-system -lsfml-window -lsfml-graphics
# for Windows using MinGW
#LDFLAGS = -L "SFML21/lib" -lmingw32 -lsfml-main -lsfml-system -lsfml-window -lsfml-graphics

OBJ = main.o

game: $(OBJ)
$(CC) $(CFLAGS) -o game $(OBJ) $(LDFLAGS)

%.o: %.cpp
$(CC) $(INC) $(CFLAGS) -c $<

+ 119
- 0
main.cpp ファイルの表示

@@ -0,0 +1,119 @@
#include <iostream>
#include <string>

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

#include "main.hpp"


namespace Game {
// because we want to create the objects in init(), we use the default constructor, so nothing can go wrong here
sf::RenderWindow window{};

GameState state = GameState::MainMenu;

bool init() {
sf::ContextSettings settings;
// set antialising for shapes
// this doesnt affect textures
// (requires sf::Texture::setSmooth() )
settings.antialiasingLevel = 4;
window.create(sf::VideoMode(xResolution, yResolution, colorDepth), gameTitle, sf::Style::Default, settings);
window.setPosition(sf::Vector2i(0, 0));
// hide mouse cursor
window.setMouseCursorVisible(false);
if(!window.isOpen()) {
std::cout << "Unable to open window object. Aborting execution.";
return false;
}
return true;
}

void update() {
switch(state) {
case GameState::Game:
// state = update game with updateTimestep.asSeconds()
if(state != GameState::Game) {
// game.uninit();
}
break;
case GameState::MainMenu:
// state = update menu
if(state == GameState::Game) {
// start a game
}
break;
case GameState::Exit:
window.close();
break;
}
}

void draw(float lagTime) {
window.clear(sf::Color::Black);
switch(state) {
case GameState::Game:
// draw game with lagTime
break;
case GameState::MainMenu:
// draw main menu
break;

case GameState::Exit:
break;
}
window.display();
}

void mainloop() {
sf::Clock clock;
sf::Time previousTime = sf::milliseconds(0);
sf::Time lagTime = sf::milliseconds(0);
while(window.isOpen()) {
sf::Time currentTime = clock.getElapsedTime();
sf::Time elapsedTime = currentTime - previousTime;
previousTime = currentTime;
lagTime += elapsedTime;
while (lagTime >= updateTimestep) {
update();
lagTime -= updateTimestep;
}
draw(lagTime.asSeconds());
}
}
int run() {
if(!init()) return 1;
mainloop();
return 0;
}

}



int main() {
return Game::run();
}

+ 23
- 0
main.hpp ファイルの表示

@@ -0,0 +1,23 @@
#include <string>

#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#pragma once


namespace Game {

enum class GameState { Game, MainMenu, Exit };
// configuration
const int xResolution = 1150;
const int yResolution = 750;

const int colorDepth = 32;
const std::string gameTitle = "Proto4";
const sf::Time updateTimestep = sf::seconds(0.0004);
const float middleX = xResolution / 2;
const float middleY = yResolution / 2;
}

読み込み中…
キャンセル
保存