Coder Social home page Coder Social logo

peekpoke's Introduction

PEEKPOKE

Tiny minimum retro fantasy console having only two commands: peek and poke.

Sample game 'BOMB SNAKE'

BOMB SNAKE

Games for PEEKPOKE can be written in simple JavaScript code. PEEKPOKE games run in the browser of any PC or mobile device.

Memory map

memory_map

You can draw pixels or text by writing a number to a specific address in memory (poke), or get the input status of a key by reading a number from the address (peek).

Getting started

Download docs/getting_started/index.html and write your game code in the <script> element. Open index.html in a browser and play the game.

Use with npm

% npm i peekpoke

The peekpoke library must be imported and initialized.

import "peekpoke";
initPeekpoke({ setup, loop, enableSplashScreen: false });

function setup() { ... }

function loop() { ... }

Sample snippets

Draw a pixel

// Draw a red pixel at (x, y).
poke(ADDRESS_VIDEO + x + y * VIDEO_WIDTH, COLOR_RED);

Draw a text

// Draw a 'A' text at (x, y).
poke(ADDRESS_TEXT + x + y * TEXT_WIDTH, "A",charCodeAt(0));

Set text color

// Make the text color green.
poke(ADDRESS_TEXT_COLOR + x + y * TEXT_WIDTH, COLOR_GREEN);

Set text background color

// Make the text background color blue.
poke(ADDRESS_TEXT_BACKGROUND + x + y * TEXT_WIDTH, COLOR_BLUE);

Check keystroke state

// Check if the up key is pressed.
if (peek(ADDRESS_KEY + KEY_UP) & KEY_STATE_IS_PRESSED) ...
// Check if the left key is just pressed.
if (peek(ADDRESS_KEY + KEY_LEFT) & KEY_STATE_IS_JUST_PRESSED) ...
// Check if the X key is just released.
if (peek(ADDRESS_KEY + KEY_X) & KEY_STATE_IS_JUST_RELEASED) ...

Buzzer

// Buzzer at 500 (50 x 10) Hz.
poke(ADDRESS_BUZZER, 50);
// Stop buzzer.
poke(ADDRESS_BUZZER, 0);

Other sample games

Click on the image to play the game.

The source code is located in the docs directory. See main.js in the directory for each game.

peekpoke's People

Contributors

abagames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

peekpoke's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.