Skip to content

Commit 33fcf6b

Browse files
committed
SFML tennis example in go + basic window revamped
1 parent 91193ad commit 33fcf6b

File tree

15 files changed

+391
-45
lines changed

15 files changed

+391
-45
lines changed

examples/basic_window/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Basic window example
2+
3+
1. Open `build.bat` script and update its `CSFML_PATH` variable to match the path of your CSFML installation
4+
2. Run the `build.bat` script
5+
3. Run `basic_window.exe`, the following result should appear!
6+
7+
![image](https://user-images.githubusercontent.com/19146183/182536297-c974050f-28df-4658-b8cb-51e4d89d610c.png)
8+
9+
If you're having issues building & running this example, please read the [general README](https://github.com/Telroshan/go-sfml#usage), and feel free to open an issue if your problem is not listed in here.

examples/basic_window/build.bat

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@ECHO OFF
2+
3+
rem This script sets the environment variables to be able to build the app, and copies the CSFML DLLs over if there aren't any in the folder
4+
5+
rem Edit the CSFML_PATH variable to match the path of your CSFML installation
6+
set CSFML_PATH=C:\CSFML_2.5.1
7+
rem Edit the COMPILER_NAME variable if you're not using gcc
8+
set COMPILER_NAME=gcc
9+
10+
set CGO_CFLAGS="-I%CSFML_PATH%\include"
11+
set CGO_LDFLAGS="-L%CSFML_PATH%\lib\%COMPILER_NAME%"
12+
13+
go get
14+
if %ERRORLEVEL% NEQ 0 (echo go get failed && exit /b %ERRORLEVEL%)
15+
16+
go build
17+
if %ERRORLEVEL% NEQ 0 (echo go build failed && exit /b %ERRORLEVEL%)
18+
19+
echo Build complete
20+
21+
if not exist "%~dp0*.dll" (
22+
echo No DLLs in folder, getting them from CSFML folder
23+
xcopy /s "%CSFML_PATH%\bin" "%~dp0"
24+
if %ERRORLEVEL% NEQ 0 (echo failed to copy DLLs && exit /b %ERRORLEVEL%)
25+
)

examples/basic_window/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module basic_window
2+
3+
go 1.18
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"runtime"
55

6-
"github.com/teh-cmc/go-sfml/graphics"
7-
"github.com/teh-cmc/go-sfml/window"
6+
"github.com/telroshan/go-sfml/v2/graphics"
7+
"github.com/telroshan/go-sfml/v2/window"
88
)
99

1010
func init() { runtime.LockOSThread() }

examples/gosfml_example_c/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/gosfml_example_c/main.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/gosfml_example_go/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/tennis/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tennis example
2+
3+
Go version of the [eponymous SFML example](https://github.com/SFML/SFML/tree/master/examples/tennis)
4+
5+
This code follows the same structure, call orders, with the same comments _(with just fixed maths lol)_ as the original, so it should give you a good idea on how to transpose C++ SFML code to go-sfml!
6+
7+
1. Open `build.bat` script and update its `CSFML_PATH` variable to match the path of your CSFML installation
8+
2. Run the `build.bat` script
9+
3. Please note that you may need the `openal32.dll` to run the executable, you'll find it in SFML's _(not CSFML)_ `bin` folder
10+
4. Run `tennis.exe`, the following result should appear!
11+
12+
![tennis](https://user-images.githubusercontent.com/19146183/182578103-eaef7229-0cc2-43a1-b184-9bf4950de8e7.gif)
13+
14+
If you're having issues building & running this example, please read the [general README](https://github.com/Telroshan/go-sfml#usage), and feel free to open an issue if your problem is not listed in here.

examples/tennis/asset_licenses.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Assets used by SFML's example projects.
2+
3+
All assets are under public domain (CC0):
4+
5+
| Name | Author | Link |
6+
| ------------------------------- | ------------------------- | -------------------------- |
7+
| Tuffy 1.1 font | Thatcher Ulrich | [Ulrich's fonts][1] |
8+
| ball.wav | MrZeusTheCoder | [public-domain][2] |
9+
10+
[1]: http://tulrich.com/fonts/
11+
[2]: https://github.com/MrZeusTheCoder/public-domain

examples/tennis/build.bat

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@ECHO OFF
2+
3+
rem This script sets the environment variables to be able to build the app, and copies the CSFML DLLs over if there aren't any in the folder
4+
5+
rem Edit the CSFML_PATH variable to match the path of your CSFML installation
6+
set CSFML_PATH=C:\CSFML_2.5.1
7+
rem Edit the COMPILER_NAME variable if you're not using gcc
8+
set COMPILER_NAME=gcc
9+
10+
set CGO_CFLAGS="-I%CSFML_PATH%\include"
11+
set CGO_LDFLAGS="-L%CSFML_PATH%\lib\%COMPILER_NAME%"
12+
13+
go get
14+
if %ERRORLEVEL% NEQ 0 (echo go get failed && exit /b %ERRORLEVEL%)
15+
16+
go build
17+
if %ERRORLEVEL% NEQ 0 (echo go build failed && exit /b %ERRORLEVEL%)
18+
19+
echo Build complete
20+
21+
if not exist "%~dp0*.dll" (
22+
echo No DLLs in folder, getting them from CSFML folder
23+
xcopy /s "%CSFML_PATH%\bin" "%~dp0"
24+
if %ERRORLEVEL% NEQ 0 (echo failed to copy DLLs && exit /b %ERRORLEVEL%)
25+
)

0 commit comments

Comments
 (0)