Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs - add tictactoe example, and improve docs #23

Merged
merged 2 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ julia> rungame("C:\\path\\to\\game\\Spaceship\\Spaceship.jl")
This is an early release. Please try to make new games, and [report](https://github.com/aviks/GameZero.jl/issues) any bugs, usability issues or missing features. We particularly welcome more games in the [GZExamples](https://github.com/SquidSinker/GZExamples) repository.

## Acknowledgement
The design of this library is inspired by the python package [PyGameZero](https://pygame-zero.readthedocs.io) by [Daniel Pope](https://github.com/lordmauve). Much of the design however has been changed to make things more Julian, and the implementation is independent.
The design of this library is inspired by the python package [PyGameZero](https://pygame-zero.readthedocs.io) by [Daniel Pope](https://github.com/lordmauve). Much of the design however has been changed to make things more Julian, and the implementation is independent.

GameZero uses [SDL2](https://www.libsdl.org/) via the [Julia wrapper](https://github.com/jonathanBieler/SimpleDirectMediaLayer.jl).
4 changes: 3 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Literate.markdown("gzexamples/Spaceship/Spaceship.jl", out_path; config=config)
Literate.markdown("gzexamples/Pandemic Sim/pandemicsim.jl", out_path; config=config)
Literate.markdown("gzexamples/Galaxian/Galaxian.jl", out_path; config=config)
Literate.markdown("gzexamples/Flappy bird/flappybird.jl", out_path; config=config)
Literate.markdown("gzexamples/Tic-tac-toe/tictactoe.jl", out_path; config=config)

makedocs(;
modules=[GameZero],
Expand All @@ -32,12 +33,13 @@ makedocs(;
"Pandemic Sim" => "examples/pandemicsim.md",
"Galaxian" => "examples/Galaxian.md",
"Flappy Bird" => "examples/flappybird.md",
"Tic-Tac-Toe" => "examples/tictactoe.md"

],
"API" => "api.md"
],
sitename="GameZero.jl",
authors="Avik Sengupta"
authors="Avik Sengupta", "Ahan Sengupta"
)

deploydocs(;
Expand Down
26 changes: 21 additions & 5 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## Overview
The aim of this package is to remove accidental complexity from the game development process. We therefore always choose simplicity and consistency over features. The users of this package will include young programmers learning their first language, maybe moving up from Scratch. While we aim to support reasonably sophisticated 2D games, our first priority will remain learners, and their teachers.

## Example
## Examples
The best way to learn how to use this package is by looking at code. There are some simple examples in the [example subdirectory](https://github.com/aviks/GameZero.jl/tree/master/example/BasicGame). More comprehensive examples are listed in the [GZExamples](https://github.com/SquidSinker/GZExamples) repository. The example source code can also be viewed as part of this documentation -- see the menu on the left.

## Running Games
## Running games

Games created using GameZero are `.jl` files that live in any directory. To play the games, start the Julia REPL and:

Expand Down Expand Up @@ -38,13 +38,24 @@ All of these are optional, and if not specified, will default to 400x400, and a
## Actors
Game objects on-screen are represented as `Actors` which have several associated attributes. Using `Actors`, you can change position, change the image and check for collisions. However, not all moving parts need to be Actors as those without a specific image can be defined as a `Circle` or a `Rect`, which have the same associated attributes (apart from image). `Actors` are usually the primary game objects that you move around.

## Rects and Circles
`a = Actor(image.png, xpos, ypos)`

## Rects, circles, and lines
GameZero.jl also includes basic geometric shapes. `Rects`, `Circles` and `Lines` can be used to do everything an `Actor` can, having the same attributes (apart from image).

```julia
r = Rect(xpos, ypos, width, height)
c = Circle(xpos, ypos, radius)
l = Line(xpos1, ypos1, xpos2, ypos2)
```

## Drawing in-game objects
To draw an in-game object, the `draw` function is used, which takes the object (Actor, Line, Rect or Circle) and renders it on-screen at its current position. If taking a shape (i.e. not an Actor), the draw function can also take a `colorant` object from [Colors.jl](https://github.com/JuliaGraphics/Colors.jl). This is done inside the `draw` game loop function (see [Draw and update methods](@ref)).

## Moving objects
All objects have many attributes to define position. The corners — `topleft`, `topright`, `bottomleft`, and `bottomright` — are tuples (x and y coordinates). The sides — `top`, `bottom`, `left` and `right` — read either the x or y coordinate (top and bottom are x, left and right are y). These position attributes can be used either to read position or to set position. In addition, objects also have an `x` and `y` attribute which are anchored to the top left of the objects. Finally, the `position` attribute is a synomym for `topleft`

## Draw and Update methods
## Draw and update methods
You write a game by defining your own `draw` and `update` methods. These functions are run by the game engine automatically every frame, meaning developers do not have to define their own event loop. The `update` function is used to change game state and attributes of the Actors and the `draw` function renders on-screen objects.

The `draw` method can be defined to take zero or one argument. If present, the single argument is the `Game` object. In other words, define one of
Expand Down Expand Up @@ -75,6 +86,11 @@ For a constant input, such as for movement, you can check for keypress within th
## Mouse input
Mouse movement can be tracked defining the `on_mouse_move` function in your game. The inputs to the function should be the `Game` object, and the mouse position as a tuple of numbers. For mouse clicks, use the `on_mouse_down` function, which takes as input the `Game` object, position, and the button.

```julia
function on_mouse_move(g::Game, pos)
function on_mouse_down(g::Game, pos, button)
```

## Playing sounds
To play sound effects, you can call the `play_sound` function. To play music on a loop, call the `play_music` function. Both these functions can take `.wav`, `.mp3` and `.ogg` files.

Expand All @@ -83,7 +99,7 @@ To set a timer in a normal program, `sleep` would be used. However, in this inst

## Animation
To animate an actor, the image is changed several times as seen in the loop below. Better animation is most likely coming very soon.
```
```julia
function shoot_animation()
global shoot_frame
if shoot_frame < 16
Expand Down