-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
209 additions
and
3,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,37 @@ | ||
# starship | ||
|
||
Here's a basic "Hello, world!" example: | ||
|
||
```ts | ||
import { | ||
StarshipConfig, | ||
StarshipInit, | ||
StarshipDestroy, | ||
StarshipUpdate, | ||
run, | ||
drawText, | ||
FONT_8x8, | ||
isButtonDown, | ||
Button, | ||
} from '@vsmode/starship' | ||
|
||
// The game state | ||
interface GameState { | ||
x: 0 | ||
y: 0 | ||
} | ||
|
||
// Set game configuration options | ||
const config: StarshipConfig = { | ||
title: 'My Game', | ||
canvas: { x: 256, y: 144 }, | ||
fps: 60, | ||
} | ||
|
||
// Creates the initial game state | ||
const init: StarshipInit<GameState> = () => { | ||
return { | ||
x: 0, | ||
y: 0, | ||
} | ||
} | ||
|
||
// Do any clean up here before the game ends | ||
const destroy: StarshipDestroy<GameState> = _ => { | ||
// ... | ||
} | ||
|
||
// This runs every frame | ||
const update: StarshipUpdate<GameState> = (state, _) => { | ||
clear() | ||
drawText(FONT_8x8, 'Hello, World!', state) | ||
if (isButtonDown(Button.Up)) { | ||
state.y-- | ||
} | ||
if (isButtonDown(Button.Down)) { | ||
state.y++ | ||
} | ||
if (isButtonDown(Button.Left)) { | ||
state.x-- | ||
} | ||
if (isButtonDown(Button.Right)) { | ||
state.x++ | ||
} | ||
} | ||
|
||
// Start the game! :) | ||
run(config, init, destroy, update) | ||
|
||
``` | ||
# 🚀 Starship | ||
|
||
<img src="https://raster.shields.io/npm/v/@vsmode/starship?style=for-the-badge" /> | ||
|
||
Simple 2D game framework with no dependencies | ||
|
||
## Installation | ||
|
||
```bash | ||
npm i @vsmode/starship | ||
``` | ||
|
||
## API | ||
|
||
Full API documentation can be found on the website. | ||
|
||
### [View API Docs →](https://vsmode.github.io/starship/) | ||
|
||
## Examples | ||
|
||
Check out these basic examples to see how to get started. | ||
|
||
### Drawing Text | ||
|
||
Learn how to display the text "Hello, World!" in the middle of the screen. | ||
|
||
 | ||
|
||
[](https://codesandbox.io/s/autumn-water-eqoqv?fontsize=14&hidenavigation=1&theme=dark) | ||
|
||
### Handling Button Input | ||
|
||
Learn how to move a rectangle around with the arrow keys. | ||
|
||
 | ||
|
||
[](https://codesandbox.io/s/dreamy-grothendieck-1o6h7?fontsize=14&hidenavigation=1&theme=dark) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.