Giter Site home page Giter Site logo

pumice's Introduction

pumice

A hole-y vulkano-made light and brittle game engine that rocks

Note: Doesn't rock yet

I wanted to make a game engine and learn vulkan with vulkano. It might become useable to make simple games quickly, but I'm not planning on adding features beyond what makes it useable.

Goals:

  • Proper color input
  • Some way to handle different window sizes
  • Support for custom shaders?
  • Sprites

Try out the examples:

cargo run --example flappy

or

cargo run --example bouncy

Simple Example:

use pumice::winit;
use pumice::GraphicsContext;

const RADIUS: f32 = 0.175;

// the struct that holds all the main data for the game
struct Data {
    x: f32,
    y: f32,
    dx: f32,
    dy: f32,
    paused: bool,
}

// the main update function that accepts an &mut GraphicsContext and Data
// drawing and updating data are both done here.
fn update(ctx: &mut GraphicsContext, data: &mut Data) {
    ctx.new_circle([data.x, data.y], RADIUS, [1.0, 0.0, 0.0, 1.0]);

    if !data.paused {
        data.x += data.dx;
        data.y += data.dy;

        if data.x + RADIUS >= 1.0 || data.x - RADIUS <= -1.0 {
            data.dx *= -1.0;
        }
        if data.y + RADIUS >= 1.0 || data.y - RADIUS <= -1.0 {
            data.dy *= -1.0;
        }
    }
}

// Right now the winit events aren't preparsed in any way but I might change that
fn handle_event(winit_event: &winit::Event, data: &mut Data) {
    match winit_event {
        winit::Event::DeviceEvent { event, .. } => match event {
            winit::DeviceEvent::Key(input) => {
                let keycode = input.virtual_keycode;
                match keycode {
                    Some(winit::VirtualKeyCode::Space) => {
                        if input.state == winit::ElementState::Pressed {
                            data.paused = !data.paused;
                        }
                    }
                    _ => {}
                }
            }
            _ => {}
        },
        _ => {}
    }
}

fn main() {
    let ctx = GraphicsContext::new();
    let mut data = Data {
        x: 0.0,
        y: 0.0,
        dx: 0.025,
        dy: -0.01,
        paused: false,
    };

    // tell ctx the Data struct to use, the update function, event handling function,
    // and clear color
    ctx.run::<Data>(&mut data, &update, &handle_event, [0.0, 0.0, 0.0, 1.0]);
}

pumice's People

Contributors

mkhan45 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

pumice'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.