fragment shader support implemented
|
@ -1,7 +1 @@
|
||||||
# Go Jetpack
|
Rolling cloud effect added to the Jetpack demo.
|
||||||
by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel)
|
|
||||||
|
|
||||||
Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys.
|
|
||||||
This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki)
|
|
||||||
|
|
||||||

|
|
|
@ -1,320 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
_ "image/png"
|
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
|
||||||
"github.com/faiface/pixel/text"
|
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
|
||||||
"github.com/golang/freetype/truetype"
|
|
||||||
"golang.org/x/image/colornames"
|
|
||||||
)
|
|
||||||
|
|
||||||
var fragmentShader = `// afl_ext @ 2016
|
|
||||||
|
|
||||||
#ifdef GL_ES
|
|
||||||
precision highp float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#extension GL_OES_standard_derivatives : enable
|
|
||||||
|
|
||||||
#define HOW_CLOUDY 0.4
|
|
||||||
#define SHADOW_THRESHOLD 0.2
|
|
||||||
#define SHADOW 0.2
|
|
||||||
#define SUBSURFACE 1.0
|
|
||||||
#define WIND_DIRECTION 5.0
|
|
||||||
#define TIME_SCALE 1.7
|
|
||||||
#define SCALE 0.3
|
|
||||||
#define ENABLE_SHAFTS
|
|
||||||
|
|
||||||
#define iGlobalTime time
|
|
||||||
#define iMouse (mouse.xy * resolution.xy)
|
|
||||||
#define iResolution resolution
|
|
||||||
|
|
||||||
mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION));
|
|
||||||
uniform float time;
|
|
||||||
uniform vec2 mouse;
|
|
||||||
uniform vec2 resolution;
|
|
||||||
|
|
||||||
float hash( float n )
|
|
||||||
{
|
|
||||||
return fract(sin(n)*758.5453);
|
|
||||||
}
|
|
||||||
|
|
||||||
float noise( in vec3 x )
|
|
||||||
{
|
|
||||||
vec3 p = floor(x);
|
|
||||||
vec3 f = fract(x);
|
|
||||||
float n = p.x + p.y*57.0 + p.z*800.0;
|
|
||||||
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
|
|
||||||
mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fbm( vec3 p )
|
|
||||||
{
|
|
||||||
float f = 0.0;
|
|
||||||
f += 0.50000*noise( p ); p = p*2.02;
|
|
||||||
f -= 0.25000*noise( p ); p = p*2.03;
|
|
||||||
f += 0.12500*noise( p ); p = p*3.01;
|
|
||||||
f += 0.06250*noise( p ); p = p*3.04;
|
|
||||||
f += 0.03500*noise( p ); p = p*4.01;
|
|
||||||
f += 0.01250*noise( p ); p = p*4.04;
|
|
||||||
f -= 0.00125*noise( p );
|
|
||||||
return f/0.984375;
|
|
||||||
}
|
|
||||||
|
|
||||||
float cloud(vec3 p)
|
|
||||||
{
|
|
||||||
p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25;
|
|
||||||
float a = min((fbm(p*3.0)*2.2-1.1), 0.0);
|
|
||||||
return a*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
float shadow = 1.0;
|
|
||||||
|
|
||||||
|
|
||||||
float clouds(vec2 p){
|
|
||||||
float ic = cloud(vec3(p * 2.0, iGlobalTime*0.01 * TIME_SCALE)) / HOW_CLOUDY;
|
|
||||||
float init = smoothstep(0.1, 1.0, ic) * 10.0;
|
|
||||||
shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW);
|
|
||||||
init = (init * cloud(vec3(p * (6.0), iGlobalTime*0.01 * TIME_SCALE)) * ic);
|
|
||||||
init = (init * (cloud(vec3(p * (11.0), iGlobalTime*0.01 * TIME_SCALE))*0.5 + 0.4) * init);
|
|
||||||
return min(1.0, init);
|
|
||||||
}
|
|
||||||
uniform sampler2D bb;
|
|
||||||
float cloudslowres(vec2 p){
|
|
||||||
return 1.0 - (texture2D(bb, p).a - 0.9) * 10.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 ratio = vec2(1.0, 1.0);
|
|
||||||
|
|
||||||
vec4 getresult(){
|
|
||||||
vec2 surfacePosition = ((( gl_FragCoord.xy / iResolution.xy ) * vec2(iResolution.x / iResolution.y, 1.0)) * 2.0 - 1.0)*SCALE;
|
|
||||||
vec2 position = ( surfacePosition);
|
|
||||||
vec2 sun = ((iMouse.xy/ iResolution.xy)* vec2(iResolution.x / iResolution.y, 1.0)*2.0-1.0) * SCALE;
|
|
||||||
float dst = distance(sun * ratio, position * ratio);
|
|
||||||
float suni = pow(dst + 1.0, -10.0);
|
|
||||||
float shaft =0.0;
|
|
||||||
float st = 0.05;
|
|
||||||
float w = 1.0;
|
|
||||||
vec2 dir = sun - position;
|
|
||||||
float c = clouds(position);
|
|
||||||
#ifdef ENABLE_SHAFTS
|
|
||||||
for(int i=0;i<50;i++){
|
|
||||||
float occl = cloudslowres(clamp((gl_FragCoord.xy / iResolution.xy) + dir * st, 0.0, 1.0));
|
|
||||||
w *= 0.99;
|
|
||||||
st *= 1.05;
|
|
||||||
shaft += max(0.0, (1.0 - occl)) * w;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE);
|
|
||||||
suni *= (shaft * 0.03);
|
|
||||||
return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main( void ) {
|
|
||||||
gl_FragColor = getresult().rgba;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
func loadPicture(path string) (pixel.Picture, error) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
img, _, err := image.Decode(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return pixel.PictureDataFromImage(img), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadSprite(path string) (pixel.Sprite, error) {
|
|
||||||
pic, err := loadPicture(path)
|
|
||||||
if err != nil {
|
|
||||||
return *pixel.NewSprite(pic, pic.Bounds()), err
|
|
||||||
}
|
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
|
||||||
return *sprite, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadTTF(path string, size float64, origin pixel.Vec) *text.Text {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
font, err := truetype.Parse(bytes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
face := truetype.NewFace(font, &truetype.Options{
|
|
||||||
Size: size,
|
|
||||||
GlyphCacheEntries: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
atlas := text.NewAtlas(face, text.ASCII)
|
|
||||||
|
|
||||||
txt := text.New(origin, atlas)
|
|
||||||
|
|
||||||
return txt
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() {
|
|
||||||
// Set up window configs
|
|
||||||
|
|
||||||
b := pixel.R(0, 0, 1024, 768)
|
|
||||||
|
|
||||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
|
||||||
Title: "Golang Jetpack!",
|
|
||||||
Bounds: b,
|
|
||||||
VSync: true,
|
|
||||||
}
|
|
||||||
win, err := pixelgl.NewWindow(cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Importantr variables
|
|
||||||
var jetX, jetY, velX, velY, radians float64
|
|
||||||
flipped := 1.0
|
|
||||||
jetpackOn := false
|
|
||||||
gravity := 0.6 // Default: 0.004
|
|
||||||
jetAcc := 0.9 // Default: 0.008
|
|
||||||
tilt := 0.01 // Default: 0.001
|
|
||||||
whichOn := false
|
|
||||||
onNumber := 0
|
|
||||||
jetpackName := "jetpack.png"
|
|
||||||
camVector := win.Bounds().Center()
|
|
||||||
|
|
||||||
bg, _ := loadSprite("sky.png")
|
|
||||||
|
|
||||||
c := pixelgl.NewCanvas(b)
|
|
||||||
|
|
||||||
var mouse mgl32.Vec2
|
|
||||||
var resolution mgl32.Vec2
|
|
||||||
var t float32
|
|
||||||
c.BindUniform("mouse", &mouse)
|
|
||||||
c.BindUniform("resolution", &resolution)
|
|
||||||
c.BindUniform("time", &t)
|
|
||||||
c.SetFragmentShader(fragmentShader)
|
|
||||||
c.UpdateShader()
|
|
||||||
|
|
||||||
// Tutorial Text
|
|
||||||
txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200))
|
|
||||||
fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!")
|
|
||||||
|
|
||||||
// Game Loop
|
|
||||||
for !win.Closed() {
|
|
||||||
win.Update()
|
|
||||||
win.Clear(colornames.Green)
|
|
||||||
|
|
||||||
// Jetpack - Controls
|
|
||||||
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = -1
|
|
||||||
radians -= tilt
|
|
||||||
velX += tilt * 30
|
|
||||||
} else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = 1
|
|
||||||
radians += tilt
|
|
||||||
velX -= tilt * 30
|
|
||||||
} else {
|
|
||||||
if velX < 0 {
|
|
||||||
radians -= tilt / 3
|
|
||||||
velX += tilt * 10
|
|
||||||
} else if velX > 0 {
|
|
||||||
radians += tilt / 3
|
|
||||||
velX -= tilt * 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if jetY < 0 {
|
|
||||||
jetY = 0
|
|
||||||
velY = -0.3 * velY
|
|
||||||
}
|
|
||||||
|
|
||||||
if jetpackOn {
|
|
||||||
velY += jetAcc
|
|
||||||
whichOn = !whichOn
|
|
||||||
onNumber += 1
|
|
||||||
if onNumber == 5 { // every 5 frames, toggle anijetMation
|
|
||||||
onNumber = 0
|
|
||||||
if whichOn {
|
|
||||||
jetpackName = "jetpack-on.png"
|
|
||||||
} else {
|
|
||||||
jetpackName = "jetpack-on2.png"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
jetpackName = "jetpack.png"
|
|
||||||
velY -= gravity
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jetpack - Rendering
|
|
||||||
jetpack, err := loadSprite(jetpackName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
|
||||||
jetMat := pixel.IM
|
|
||||||
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
|
||||||
jetMat = jetMat.Moved(positionVector)
|
|
||||||
jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1))
|
|
||||||
jetMat = jetMat.Rotated(positionVector, radians)
|
|
||||||
|
|
||||||
jetX += velX
|
|
||||||
jetY += velY
|
|
||||||
|
|
||||||
// Camera
|
|
||||||
camVector.X += (positionVector.X - camVector.X) * 0.2
|
|
||||||
camVector.Y += (positionVector.Y - camVector.Y) * 0.2
|
|
||||||
|
|
||||||
if camVector.X > 25085 {
|
|
||||||
camVector.X = 25085
|
|
||||||
} else if camVector.X < -14843 {
|
|
||||||
camVector.X = -14843
|
|
||||||
}
|
|
||||||
|
|
||||||
if camVector.Y > 22500 {
|
|
||||||
camVector.Y = 22500
|
|
||||||
}
|
|
||||||
|
|
||||||
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
|
||||||
|
|
||||||
win.SetMatrix(cam)
|
|
||||||
|
|
||||||
// Drawing to the screen
|
|
||||||
win.SetSmooth(true)
|
|
||||||
bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10))
|
|
||||||
txt.Draw(win, pixel.IM)
|
|
||||||
win.SetSmooth(false)
|
|
||||||
c.Draw(win, pixel.IM)
|
|
||||||
jetpack.Draw(win, jetMat)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pixelgl.Run(run)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 171 KiB |
|
@ -1,7 +0,0 @@
|
||||||
# Go Jetpack
|
|
||||||
by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel)
|
|
||||||
|
|
||||||
Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys.
|
|
||||||
This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki)
|
|
||||||
|
|
||||||

|
|
Before Width: | Height: | Size: 295 B |
Before Width: | Height: | Size: 314 B |
|
@ -1,391 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
|
||||||
|
|
||||||
_ "image/png"
|
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
|
||||||
"github.com/faiface/pixel/imdraw"
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
|
||||||
"github.com/faiface/pixel/text"
|
|
||||||
"github.com/golang/freetype/truetype"
|
|
||||||
"golang.org/x/image/colornames"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InstallShader ...
|
|
||||||
func InstallShader(c *pixelgl.Canvas, uTime *float32, uAmt *float32, uMouse, uGopherPos *mgl32.Vec2) {
|
|
||||||
c.BindUniform("u_time", uTime)
|
|
||||||
c.BindUniform("u_mouse", uMouse)
|
|
||||||
c.BindUniform("u_gopherpos", uGopherPos)
|
|
||||||
c.BindUniform("u_amount", uAmt)
|
|
||||||
c.SetFragmentShader(cloudsFragmentShader)
|
|
||||||
c.UpdateShader()
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadPicture(path string) (pixel.Picture, error) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
img, _, err := image.Decode(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return pixel.PictureDataFromImage(img), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadSprite(path string) (pixel.Sprite, error) {
|
|
||||||
pic, err := loadPicture(path)
|
|
||||||
if err != nil {
|
|
||||||
return *pixel.NewSprite(pic, pic.Bounds()), err
|
|
||||||
}
|
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
|
||||||
return *sprite, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadTTF(path string, size float64, origin pixel.Vec) *text.Text {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
font, err := truetype.Parse(bytes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
face := truetype.NewFace(font, &truetype.Options{
|
|
||||||
Size: size,
|
|
||||||
GlyphCacheEntries: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
atlas := text.NewAtlas(face, text.ASCII)
|
|
||||||
|
|
||||||
txt := text.New(origin, atlas)
|
|
||||||
|
|
||||||
return txt
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() {
|
|
||||||
// Set up window configs
|
|
||||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
|
||||||
Title: "Golang Jetpack!",
|
|
||||||
Bounds: pixel.R(0, 0, 1024, 768),
|
|
||||||
VSync: true,
|
|
||||||
}
|
|
||||||
win, err := pixelgl.NewWindow(cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Importantr variables
|
|
||||||
var jetX, jetY, velX, velY, radians float64
|
|
||||||
flipped := 1.0
|
|
||||||
jetpackOn := false
|
|
||||||
gravity := 0.6 // Default: 0.004
|
|
||||||
jetAcc := 0.9 // Default: 0.008
|
|
||||||
tilt := 0.01 // Default: 0.001
|
|
||||||
whichOn := false
|
|
||||||
onNumber := 0
|
|
||||||
jetpackOffName := "jetpack.png"
|
|
||||||
jetpackOn1Name := "jetpack-on.png"
|
|
||||||
jetpackOn2Name := "jetpack-on2.png"
|
|
||||||
camVector := win.Bounds().Center()
|
|
||||||
|
|
||||||
var uTime, uAmt float32
|
|
||||||
var uMouse, uGopherPos mgl32.Vec2
|
|
||||||
|
|
||||||
uAmt = 100
|
|
||||||
imd := imdraw.New(nil)
|
|
||||||
imd.Color = colornames.Green
|
|
||||||
|
|
||||||
bounds := win.Bounds()
|
|
||||||
bounds.Max = bounds.Max.ScaledXY(pixel.V(1.0, 1.0))
|
|
||||||
|
|
||||||
canvas := pixelgl.NewCanvas(bounds)
|
|
||||||
|
|
||||||
InstallShader(canvas, &uTime, &uAmt, &uMouse, &uGopherPos)
|
|
||||||
|
|
||||||
bg, _ := loadSprite("sky.png")
|
|
||||||
bg.Draw(canvas, pixel.IM)
|
|
||||||
|
|
||||||
// Jetpack - Rendering
|
|
||||||
jetpackOff, err := loadSprite(jetpackOffName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
jetpackOn1, err := loadSprite(jetpackOn1Name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
jetpackOn2, err := loadSprite(jetpackOn2Name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tutorial Text
|
|
||||||
txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200))
|
|
||||||
txt.Color = colornames.Black
|
|
||||||
fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!")
|
|
||||||
|
|
||||||
currentSprite := jetpackOff
|
|
||||||
start := time.Now()
|
|
||||||
b := win.Bounds().Moved(pixel.V(0, -760))
|
|
||||||
min := b.Min
|
|
||||||
max := b.Max
|
|
||||||
|
|
||||||
// Game Loop
|
|
||||||
for !win.Closed() {
|
|
||||||
uTime = float32(time.Since(start).Seconds())
|
|
||||||
mpos := win.MousePosition()
|
|
||||||
uMouse[0] = float32(mpos.X)
|
|
||||||
uMouse[1] = float32(mpos.Y)
|
|
||||||
|
|
||||||
win.SetTitle(fmt.Sprint(uGopherPos))
|
|
||||||
|
|
||||||
win.Clear(colornames.Green)
|
|
||||||
|
|
||||||
// Jetpack - Controls
|
|
||||||
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = -1
|
|
||||||
radians -= tilt
|
|
||||||
velX += tilt * 30
|
|
||||||
} else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = 1
|
|
||||||
radians += tilt
|
|
||||||
velX -= tilt * 30
|
|
||||||
} else {
|
|
||||||
if velX < 0 {
|
|
||||||
radians -= tilt / 3
|
|
||||||
velX += tilt * 10
|
|
||||||
} else if velX > 0 {
|
|
||||||
radians += tilt / 3
|
|
||||||
velX -= tilt * 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if jetY < 0 {
|
|
||||||
jetY = 0
|
|
||||||
velY = -0.3 * velY
|
|
||||||
}
|
|
||||||
|
|
||||||
if jetpackOn {
|
|
||||||
velY += jetAcc
|
|
||||||
whichOn = !whichOn
|
|
||||||
onNumber++
|
|
||||||
if onNumber == 5 { // every 5 frames, toggle anijetMation
|
|
||||||
onNumber = 0
|
|
||||||
if whichOn {
|
|
||||||
currentSprite = jetpackOn1
|
|
||||||
} else {
|
|
||||||
currentSprite = jetpackOn2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentSprite = jetpackOff
|
|
||||||
velY -= gravity
|
|
||||||
}
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyEqual) {
|
|
||||||
uAmt++
|
|
||||||
}
|
|
||||||
if win.Pressed(pixelgl.KeyMinus) {
|
|
||||||
uAmt--
|
|
||||||
}
|
|
||||||
|
|
||||||
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
|
||||||
jetMat := pixel.IM
|
|
||||||
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
|
||||||
jetMat = jetMat.Moved(positionVector)
|
|
||||||
jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1))
|
|
||||||
jetMat = jetMat.Rotated(positionVector, radians)
|
|
||||||
|
|
||||||
jetX += velX
|
|
||||||
jetY += velY
|
|
||||||
uGopherPos[0] = float32(jetX*0.00001 + 1.0)
|
|
||||||
uGopherPos[1] = float32(jetY*0.00001 + 1.0)
|
|
||||||
// Camera
|
|
||||||
camVector.X += (positionVector.X - camVector.X) * 0.2
|
|
||||||
camVector.Y += (positionVector.Y - camVector.Y) * 0.2
|
|
||||||
|
|
||||||
if camVector.X > 25085 {
|
|
||||||
camVector.X = 25085
|
|
||||||
} else if camVector.X < -14843 {
|
|
||||||
camVector.X = -14843
|
|
||||||
}
|
|
||||||
|
|
||||||
if camVector.Y > 22500 {
|
|
||||||
camVector.Y = 22500
|
|
||||||
}
|
|
||||||
|
|
||||||
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
|
||||||
|
|
||||||
win.SetMatrix(cam)
|
|
||||||
|
|
||||||
// Drawing to the screen
|
|
||||||
win.SetSmooth(true)
|
|
||||||
|
|
||||||
//bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)))
|
|
||||||
bg.Draw(canvas, pixel.IM)
|
|
||||||
|
|
||||||
canvas.Draw(win, pixel.IM.Moved(camVector))
|
|
||||||
imd.Clear()
|
|
||||||
imd.Push(
|
|
||||||
min.Sub(pixel.V(camVector.X, 0)),
|
|
||||||
max.Add(pixel.V(camVector.X, 0)),
|
|
||||||
)
|
|
||||||
imd.Rectangle(0)
|
|
||||||
imd.Draw(win)
|
|
||||||
txt.Draw(win, pixel.IM)
|
|
||||||
win.SetSmooth(false)
|
|
||||||
currentSprite.Draw(win, jetMat)
|
|
||||||
|
|
||||||
win.Update()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pixelgl.Run(run)
|
|
||||||
}
|
|
||||||
|
|
||||||
var cloudsFragmentShader = `
|
|
||||||
#version 330 core
|
|
||||||
|
|
||||||
#ifdef GL_ES
|
|
||||||
precision highp float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HOW_CLOUDY 0.2
|
|
||||||
#define SHADOW_THRESHOLD 0.4
|
|
||||||
#define SHADOW 0.3
|
|
||||||
#define SUBSURFACE 1.0
|
|
||||||
#define WIND_DIRECTION 0.3
|
|
||||||
#define TIME_SCALE 0.6
|
|
||||||
#define SCALE 0.1
|
|
||||||
//#define ENABLE_SHAFTS
|
|
||||||
in vec2 texcoords;
|
|
||||||
out vec4 fragColor;
|
|
||||||
mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION));
|
|
||||||
uniform float u_time;
|
|
||||||
uniform vec2 u_mouse;
|
|
||||||
//uniform vec2 u_resolution;
|
|
||||||
uniform vec4 u_texbounds;
|
|
||||||
uniform sampler2D u_texture;
|
|
||||||
uniform vec2 u_gopherpos;
|
|
||||||
uniform float u_amount;
|
|
||||||
|
|
||||||
float hash( float n )
|
|
||||||
{
|
|
||||||
return fract(sin(n)*758.5453);
|
|
||||||
}
|
|
||||||
|
|
||||||
float noise( in vec3 x )
|
|
||||||
{
|
|
||||||
vec3 p = floor(x);
|
|
||||||
vec3 f = fract(x);
|
|
||||||
float n = p.x + p.y*57.0 + p.z*800.0;
|
|
||||||
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
|
|
||||||
mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fbm( vec3 p )
|
|
||||||
{
|
|
||||||
float f = 0.0;
|
|
||||||
f += 0.50000*noise( p ); p = p*2.02;
|
|
||||||
f -= 0.25000*noise( p ); p = p*2.03;
|
|
||||||
f += 0.12500*noise( p ); p = p*3.01;
|
|
||||||
f += 0.06250*noise( p ); p = p*3.04;
|
|
||||||
f += 0.03500*noise( p ); p = p*4.01;
|
|
||||||
f += 0.01250*noise( p ); p = p*4.04;
|
|
||||||
f -= 0.00125*noise( p );
|
|
||||||
return f/0.784375;
|
|
||||||
}
|
|
||||||
|
|
||||||
float cloud(vec3 p)
|
|
||||||
{
|
|
||||||
p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25;
|
|
||||||
float a = min((fbm(p*3.0)*2.2-1.1), 0.0);
|
|
||||||
return a*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
float shadow = 1.0;
|
|
||||||
|
|
||||||
|
|
||||||
float clouds(vec2 p){
|
|
||||||
float ic = cloud(vec3(p * 2.0, u_time*0.01 * TIME_SCALE)) / HOW_CLOUDY;
|
|
||||||
float init = smoothstep(0.1, 1.0, ic) * 5.0;
|
|
||||||
shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW);
|
|
||||||
init = (init * cloud(vec3(p * (6.0), u_time*0.01 * TIME_SCALE)) * ic);
|
|
||||||
init = (init * (cloud(vec3(p * (11.0), u_time*0.01 * TIME_SCALE))*0.5 + 0.4) * init);
|
|
||||||
return min(1.0, init);
|
|
||||||
}
|
|
||||||
//uniform sampler2D bb;
|
|
||||||
float cloudslowres(vec2 p){
|
|
||||||
return 1.0 - (texture(u_texture, p).a - 0.9) * 10.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 ratio = vec2(1.0, 1.0);
|
|
||||||
|
|
||||||
vec4 getresult(){
|
|
||||||
vec2 uvmouse = (u_mouse/(texcoords - u_texbounds.xy));
|
|
||||||
vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw;
|
|
||||||
//vec2 surfacePosition = ((( t ) * vec2(u_gopherpos.x , u_gopherpos.y)) * 2.0 - 1.0)*SCALE;
|
|
||||||
vec2 surfacePosition = t+u_gopherpos*10.0;
|
|
||||||
vec2 position = ( surfacePosition * SCALE);
|
|
||||||
vec2 sun = (uvmouse.xy * vec2(texcoords.x / texcoords.y, 1.0)*2.0-1.0) * SCALE;
|
|
||||||
|
|
||||||
float dst = distance(sun * ratio, position * ratio);
|
|
||||||
float suni = pow(dst + 1.0, -10.0);
|
|
||||||
float shaft =0.0;
|
|
||||||
float st = 0.05;
|
|
||||||
float w = 1.0;
|
|
||||||
vec2 dir = sun - position;
|
|
||||||
float c = clouds(position);
|
|
||||||
#ifdef ENABLE_SHAFTS
|
|
||||||
for(int i=0;i<50;i++){
|
|
||||||
float occl = cloudslowres(clamp((t) + dir * st, 0.0, 1.0));
|
|
||||||
w *= 0.99;
|
|
||||||
st *= 1.05;
|
|
||||||
shaft += max(0.0, (1.0 - occl)) * w;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE);
|
|
||||||
suni *= (shaft * 0.03);
|
|
||||||
return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9);
|
|
||||||
}
|
|
||||||
uniform sampler2D backbuffer;
|
|
||||||
void main( void ) {
|
|
||||||
|
|
||||||
fragColor = getresult().rgba;
|
|
||||||
|
|
||||||
vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw;
|
|
||||||
float d = 1.0 / u_amount;
|
|
||||||
float ar = (t.y / t.x) * (u_gopherpos.y * 10);
|
|
||||||
float u = floor( t.x / d ) * d;
|
|
||||||
d = ar / u_amount;
|
|
||||||
float v = floor( t.y / d ) * d;
|
|
||||||
fragColor *= texture( backbuffer, vec2(u,v) );
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
`
|
|
|
@ -1,320 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
_ "image/png"
|
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
|
||||||
"github.com/faiface/pixel/text"
|
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
|
||||||
"github.com/golang/freetype/truetype"
|
|
||||||
"golang.org/x/image/colornames"
|
|
||||||
)
|
|
||||||
|
|
||||||
var fragmentShader = `// afl_ext @ 2016
|
|
||||||
|
|
||||||
#ifdef GL_ES
|
|
||||||
precision highp float;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#extension GL_OES_standard_derivatives : enable
|
|
||||||
|
|
||||||
#define HOW_CLOUDY 0.4
|
|
||||||
#define SHADOW_THRESHOLD 0.2
|
|
||||||
#define SHADOW 0.2
|
|
||||||
#define SUBSURFACE 1.0
|
|
||||||
#define WIND_DIRECTION 5.0
|
|
||||||
#define TIME_SCALE 1.7
|
|
||||||
#define SCALE 0.3
|
|
||||||
#define ENABLE_SHAFTS
|
|
||||||
|
|
||||||
#define iGlobalTime time
|
|
||||||
#define iMouse (mouse.xy * resolution.xy)
|
|
||||||
#define iResolution resolution
|
|
||||||
|
|
||||||
mat2 RM = mat2(cos(WIND_DIRECTION), -sin(WIND_DIRECTION), sin(WIND_DIRECTION), cos(WIND_DIRECTION));
|
|
||||||
uniform float time;
|
|
||||||
uniform vec2 mouse;
|
|
||||||
uniform vec2 resolution;
|
|
||||||
|
|
||||||
float hash( float n )
|
|
||||||
{
|
|
||||||
return fract(sin(n)*758.5453);
|
|
||||||
}
|
|
||||||
|
|
||||||
float noise( in vec3 x )
|
|
||||||
{
|
|
||||||
vec3 p = floor(x);
|
|
||||||
vec3 f = fract(x);
|
|
||||||
float n = p.x + p.y*57.0 + p.z*800.0;
|
|
||||||
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
|
|
||||||
mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fbm( vec3 p )
|
|
||||||
{
|
|
||||||
float f = 0.0;
|
|
||||||
f += 0.50000*noise( p ); p = p*2.02;
|
|
||||||
f -= 0.25000*noise( p ); p = p*2.03;
|
|
||||||
f += 0.12500*noise( p ); p = p*3.01;
|
|
||||||
f += 0.06250*noise( p ); p = p*3.04;
|
|
||||||
f += 0.03500*noise( p ); p = p*4.01;
|
|
||||||
f += 0.01250*noise( p ); p = p*4.04;
|
|
||||||
f -= 0.00125*noise( p );
|
|
||||||
return f/0.984375;
|
|
||||||
}
|
|
||||||
|
|
||||||
float cloud(vec3 p)
|
|
||||||
{
|
|
||||||
p-=fbm(vec3(p.x,p.y,0.0)*0.5)*1.25;
|
|
||||||
float a = min((fbm(p*3.0)*2.2-1.1), 0.0);
|
|
||||||
return a*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
float shadow = 1.0;
|
|
||||||
|
|
||||||
|
|
||||||
float clouds(vec2 p){
|
|
||||||
float ic = cloud(vec3(p * 2.0, iGlobalTime*0.01 * TIME_SCALE)) / HOW_CLOUDY;
|
|
||||||
float init = smoothstep(0.1, 1.0, ic) * 10.0;
|
|
||||||
shadow = smoothstep(0.0, SHADOW_THRESHOLD, ic) * SHADOW + (1.0 - SHADOW);
|
|
||||||
init = (init * cloud(vec3(p * (6.0), iGlobalTime*0.01 * TIME_SCALE)) * ic);
|
|
||||||
init = (init * (cloud(vec3(p * (11.0), iGlobalTime*0.01 * TIME_SCALE))*0.5 + 0.4) * init);
|
|
||||||
return min(1.0, init);
|
|
||||||
}
|
|
||||||
uniform sampler2D bb;
|
|
||||||
float cloudslowres(vec2 p){
|
|
||||||
return 1.0 - (texture2D(bb, p).a - 0.9) * 10.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 ratio = vec2(1.0, 1.0);
|
|
||||||
|
|
||||||
vec4 getresult(){
|
|
||||||
vec2 surfacePosition = ((( gl_FragCoord.xy / iResolution.xy ) * vec2(iResolution.x / iResolution.y, 1.0)) * 2.0 - 1.0)*SCALE;
|
|
||||||
vec2 position = ( surfacePosition);
|
|
||||||
vec2 sun = ((iMouse.xy/ iResolution.xy)* vec2(iResolution.x / iResolution.y, 1.0)*2.0-1.0) * SCALE;
|
|
||||||
float dst = distance(sun * ratio, position * ratio);
|
|
||||||
float suni = pow(dst + 1.0, -10.0);
|
|
||||||
float shaft =0.0;
|
|
||||||
float st = 0.05;
|
|
||||||
float w = 1.0;
|
|
||||||
vec2 dir = sun - position;
|
|
||||||
float c = clouds(position);
|
|
||||||
#ifdef ENABLE_SHAFTS
|
|
||||||
for(int i=0;i<50;i++){
|
|
||||||
float occl = cloudslowres(clamp((gl_FragCoord.xy / iResolution.xy) + dir * st, 0.0, 1.0));
|
|
||||||
w *= 0.99;
|
|
||||||
st *= 1.05;
|
|
||||||
shaft += max(0.0, (1.0 - occl)) * w;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
shadow = min(1.0, shadow + suni * suni * 0.2 * SUBSURFACE);
|
|
||||||
suni *= (shaft * 0.03);
|
|
||||||
return vec4(pow(mix(vec3(shadow), pow(vec3(0.23, 0.33, 0.48), vec3(2.2)) + suni, c), vec3(1.0/2.2)), c*0.1 + 0.9);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main( void ) {
|
|
||||||
gl_FragColor = getresult().rgba;
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
func loadPicture(path string) (pixel.Picture, error) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
img, _, err := image.Decode(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return pixel.PictureDataFromImage(img), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadSprite(path string) (pixel.Sprite, error) {
|
|
||||||
pic, err := loadPicture(path)
|
|
||||||
if err != nil {
|
|
||||||
return *pixel.NewSprite(pic, pic.Bounds()), err
|
|
||||||
}
|
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
|
||||||
return *sprite, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadTTF(path string, size float64, origin pixel.Vec) *text.Text {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
font, err := truetype.Parse(bytes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
face := truetype.NewFace(font, &truetype.Options{
|
|
||||||
Size: size,
|
|
||||||
GlyphCacheEntries: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
atlas := text.NewAtlas(face, text.ASCII)
|
|
||||||
|
|
||||||
txt := text.New(origin, atlas)
|
|
||||||
|
|
||||||
return txt
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() {
|
|
||||||
// Set up window configs
|
|
||||||
|
|
||||||
b := pixel.R(0, 0, 1024, 768)
|
|
||||||
|
|
||||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
|
||||||
Title: "Golang Jetpack!",
|
|
||||||
Bounds: b,
|
|
||||||
VSync: true,
|
|
||||||
}
|
|
||||||
win, err := pixelgl.NewWindow(cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Importantr variables
|
|
||||||
var jetX, jetY, velX, velY, radians float64
|
|
||||||
flipped := 1.0
|
|
||||||
jetpackOn := false
|
|
||||||
gravity := 0.6 // Default: 0.004
|
|
||||||
jetAcc := 0.9 // Default: 0.008
|
|
||||||
tilt := 0.01 // Default: 0.001
|
|
||||||
whichOn := false
|
|
||||||
onNumber := 0
|
|
||||||
jetpackName := "jetpack.png"
|
|
||||||
camVector := win.Bounds().Center()
|
|
||||||
|
|
||||||
bg, _ := loadSprite("sky.png")
|
|
||||||
|
|
||||||
c := pixelgl.NewCanvas(b)
|
|
||||||
|
|
||||||
var mouse mgl32.Vec2
|
|
||||||
var resolution mgl32.Vec2
|
|
||||||
var t float32
|
|
||||||
c.BindUniform("mouse", &mouse)
|
|
||||||
c.BindUniform("resolution", &resolution)
|
|
||||||
c.BindUniform("time", &t)
|
|
||||||
c.SetFragmentShader(fragmentShader)
|
|
||||||
c.UpdateShader()
|
|
||||||
|
|
||||||
// Tutorial Text
|
|
||||||
txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200))
|
|
||||||
fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!")
|
|
||||||
|
|
||||||
// Game Loop
|
|
||||||
for !win.Closed() {
|
|
||||||
win.Update()
|
|
||||||
win.Clear(colornames.Green)
|
|
||||||
|
|
||||||
// Jetpack - Controls
|
|
||||||
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = -1
|
|
||||||
radians -= tilt
|
|
||||||
velX += tilt * 30
|
|
||||||
} else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = 1
|
|
||||||
radians += tilt
|
|
||||||
velX -= tilt * 30
|
|
||||||
} else {
|
|
||||||
if velX < 0 {
|
|
||||||
radians -= tilt / 3
|
|
||||||
velX += tilt * 10
|
|
||||||
} else if velX > 0 {
|
|
||||||
radians += tilt / 3
|
|
||||||
velX -= tilt * 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if jetY < 0 {
|
|
||||||
jetY = 0
|
|
||||||
velY = -0.3 * velY
|
|
||||||
}
|
|
||||||
|
|
||||||
if jetpackOn {
|
|
||||||
velY += jetAcc
|
|
||||||
whichOn = !whichOn
|
|
||||||
onNumber += 1
|
|
||||||
if onNumber == 5 { // every 5 frames, toggle anijetMation
|
|
||||||
onNumber = 0
|
|
||||||
if whichOn {
|
|
||||||
jetpackName = "jetpack-on.png"
|
|
||||||
} else {
|
|
||||||
jetpackName = "jetpack-on2.png"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
jetpackName = "jetpack.png"
|
|
||||||
velY -= gravity
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jetpack - Rendering
|
|
||||||
jetpack, err := loadSprite(jetpackName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
|
||||||
jetMat := pixel.IM
|
|
||||||
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
|
||||||
jetMat = jetMat.Moved(positionVector)
|
|
||||||
jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1))
|
|
||||||
jetMat = jetMat.Rotated(positionVector, radians)
|
|
||||||
|
|
||||||
jetX += velX
|
|
||||||
jetY += velY
|
|
||||||
|
|
||||||
// Camera
|
|
||||||
camVector.X += (positionVector.X - camVector.X) * 0.2
|
|
||||||
camVector.Y += (positionVector.Y - camVector.Y) * 0.2
|
|
||||||
|
|
||||||
if camVector.X > 25085 {
|
|
||||||
camVector.X = 25085
|
|
||||||
} else if camVector.X < -14843 {
|
|
||||||
camVector.X = -14843
|
|
||||||
}
|
|
||||||
|
|
||||||
if camVector.Y > 22500 {
|
|
||||||
camVector.Y = 22500
|
|
||||||
}
|
|
||||||
|
|
||||||
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
|
||||||
|
|
||||||
win.SetMatrix(cam)
|
|
||||||
|
|
||||||
// Drawing to the screen
|
|
||||||
win.SetSmooth(true)
|
|
||||||
bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10))
|
|
||||||
txt.Draw(win, pixel.IM)
|
|
||||||
win.SetSmooth(false)
|
|
||||||
c.Draw(win, pixel.IM)
|
|
||||||
jetpack.Draw(win, jetMat)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pixelgl.Run(run)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 243 B |
Before Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 2.7 MiB |
|
@ -1,7 +1 @@
|
||||||
# Go Jetpack
|
A pixelating shader on top of the Jetpack demo. Use the -/+ keys to change the strength!
|
||||||
by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel)
|
|
||||||
|
|
||||||
Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys.
|
|
||||||
This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki)
|
|
||||||
|
|
||||||

|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/go-gl/mathgl/mgl32"
|
||||||
|
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
"github.com/faiface/pixel"
|
||||||
|
@ -16,8 +18,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// InstallShader ...
|
// InstallShader ...
|
||||||
func InstallShader(w *pixelgl.Window) {
|
func InstallShader(w *pixelgl.Window, uAmount *float32, uResolution, uMouse *mgl32.Vec2) {
|
||||||
wc := w.GetCanvas()
|
wc := w.GetCanvas()
|
||||||
|
wc.BindUniform("u_resolution", uResolution)
|
||||||
|
wc.BindUniform("u_mouse", uMouse)
|
||||||
|
wc.BindUniform("u_amount", uAmount)
|
||||||
wc.SetFragmentShader(pixelateFragShader)
|
wc.SetFragmentShader(pixelateFragShader)
|
||||||
wc.UpdateShader()
|
wc.UpdateShader()
|
||||||
}
|
}
|
||||||
|
@ -100,7 +105,10 @@ func run() {
|
||||||
jetpackOn2Name := "jetpack-on2.png"
|
jetpackOn2Name := "jetpack-on2.png"
|
||||||
camVector := win.Bounds().Center()
|
camVector := win.Bounds().Center()
|
||||||
|
|
||||||
InstallShader(win)
|
var uAmount float32
|
||||||
|
var uMouse, uResolution mgl32.Vec2
|
||||||
|
|
||||||
|
InstallShader(win, &uAmount, &uResolution, &uMouse)
|
||||||
|
|
||||||
bg, _ := loadSprite("sky.png")
|
bg, _ := loadSprite("sky.png")
|
||||||
|
|
||||||
|
@ -124,10 +132,19 @@ func run() {
|
||||||
|
|
||||||
currentSprite := jetpackOff
|
currentSprite := jetpackOff
|
||||||
|
|
||||||
|
canvas := pixelgl.NewCanvas(win.Bounds())
|
||||||
|
uResolution[0] = float32(win.Bounds().W())
|
||||||
|
uResolution[1] = float32(win.Bounds().H())
|
||||||
|
uAmount = 300.0
|
||||||
// Game Loop
|
// Game Loop
|
||||||
for !win.Closed() {
|
for !win.Closed() {
|
||||||
win.Update()
|
|
||||||
win.Clear(colornames.Green)
|
mpos := win.MousePosition()
|
||||||
|
uMouse[0] = float32(mpos.X)
|
||||||
|
uMouse[1] = float32(mpos.Y)
|
||||||
|
win.SetTitle(fmt.Sprint(uAmount))
|
||||||
|
win.Clear(colornames.Blue)
|
||||||
|
canvas.Clear(colornames.Green)
|
||||||
|
|
||||||
// Jetpack - Controls
|
// Jetpack - Controls
|
||||||
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
||||||
|
@ -173,6 +190,13 @@ func run() {
|
||||||
velY -= gravity
|
velY -= gravity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if win.Pressed(pixelgl.KeyEqual) {
|
||||||
|
uAmount += 10
|
||||||
|
}
|
||||||
|
if win.Pressed(pixelgl.KeyMinus) {
|
||||||
|
uAmount -= 10
|
||||||
|
}
|
||||||
|
|
||||||
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
||||||
jetMat := pixel.IM
|
jetMat := pixel.IM
|
||||||
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
||||||
|
@ -199,15 +223,16 @@ func run() {
|
||||||
|
|
||||||
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
||||||
|
|
||||||
win.SetMatrix(cam)
|
canvas.SetMatrix(cam)
|
||||||
|
|
||||||
// Drawing to the screen
|
// Drawing to the screen
|
||||||
win.SetSmooth(true)
|
win.SetSmooth(true)
|
||||||
bg.Draw(win, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10))
|
bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10))
|
||||||
txt.Draw(win, pixel.IM)
|
txt.Draw(canvas, pixel.IM)
|
||||||
win.SetSmooth(false)
|
win.SetSmooth(false)
|
||||||
currentSprite.Draw(win, jetMat)
|
currentSprite.Draw(canvas, jetMat)
|
||||||
|
canvas.Draw(win, pixel.IM.Moved(win.Bounds().Center()))
|
||||||
|
win.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -222,28 +247,60 @@ var pixelateFragShader = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
precision mediump int;
|
precision mediump int;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
in vec4 Color;
|
in vec4 Color;
|
||||||
in vec2 texcoords;
|
in vec2 texcoords;
|
||||||
in float Intensity;
|
in vec2 glpos;
|
||||||
|
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform vec4 u_colormask;
|
uniform vec4 u_colormask;
|
||||||
uniform vec4 u_texbounds;
|
uniform vec4 u_texbounds;
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D u_texture;
|
||||||
// varying vec4 vertTexCoord;
|
uniform float u_amount;
|
||||||
// uniform sampler2D texture;
|
uniform vec2 u_mouse;
|
||||||
// uniform vec2 pixels;
|
uniform vec2 u_resolution;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
fragColor = vec4(0, 0, 0, 0);
|
|
||||||
fragColor += (1 - Intensity) * Color;
|
|
||||||
vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw;
|
vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw;
|
||||||
fragColor += Intensity * Color * texture(u_texture, t);
|
|
||||||
fragColor *= u_colormask;
|
|
||||||
vec2 p = t.st;
|
|
||||||
p.x -= mod(texcoords.x, 1.0 / gl_FragCoord.x);
|
|
||||||
p.y -= mod(texcoords.y, 1.0 / gl_FragCoord.y);
|
|
||||||
|
|
||||||
fragColor = texture(u_texture, p).rgba;
|
|
||||||
|
|
||||||
|
float d = 1.0 / u_amount;
|
||||||
|
float ar = u_resolution.x / u_resolution.y;
|
||||||
|
float u = floor( t.x / d ) * d;
|
||||||
|
d = ar / u_amount;
|
||||||
|
float v = floor( t.y / d ) * d;
|
||||||
|
fragColor = texture( u_texture, vec2( u, v ) );
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
/*
|
||||||
|
//fragColor = vec4(1.0,0.0,0.0,1.0);
|
||||||
|
// float d = 1.0 / u_amount;
|
||||||
|
// float ar = u_resolution.x / u_resolution.y;
|
||||||
|
// float u = floor( texcoords.x / d ) * d;
|
||||||
|
// d = ar / u_amount;
|
||||||
|
// float v = floor( texcoords.y / d ) * d;
|
||||||
|
// fragColor = texture( u_texture, vec2( u, v ) );
|
||||||
|
|
||||||
|
// vec2 p = t.st;
|
||||||
|
// p.x -= mod(t.x / glpos.x, t.x / glpos.x + 0.1);
|
||||||
|
// p.y -= mod(t.y / glpos.y, t.y / glpos.y + 0.1);
|
||||||
|
|
||||||
|
// fragColor = texture(u_texture, p).rgba;
|
||||||
|
*/
|
||||||
|
// varying vec2 vUv;
|
||||||
|
// uniform sampler2D tInput;
|
||||||
|
// uniform vec2 resolution;
|
||||||
|
// uniform float amount;
|
||||||
|
|
||||||
|
// void main() {
|
||||||
|
|
||||||
|
// float d = 1.0 / amount;
|
||||||
|
// float ar = resolution.x / resolution.y;
|
||||||
|
// float u = floor( vUv.x / d ) * d;
|
||||||
|
// d = ar / amount;
|
||||||
|
// float v = floor( vUv.y / d ) * d;
|
||||||
|
// gl_FragColor = texture2D( tInput, vec2( u, v ) );
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 30 KiB |
|
@ -1,7 +0,0 @@
|
||||||
# Go Jetpack
|
|
||||||
by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel)
|
|
||||||
|
|
||||||
Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys.
|
|
||||||
This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki)
|
|
||||||
|
|
||||||

|
|
Before Width: | Height: | Size: 295 B |
Before Width: | Height: | Size: 314 B |
|
@ -1,306 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/go-gl/mathgl/mgl32"
|
|
||||||
|
|
||||||
_ "image/png"
|
|
||||||
|
|
||||||
"github.com/faiface/pixel"
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
|
||||||
"github.com/faiface/pixel/text"
|
|
||||||
"github.com/golang/freetype/truetype"
|
|
||||||
"golang.org/x/image/colornames"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InstallShader ...
|
|
||||||
func InstallShader(w *pixelgl.Window, uAmount *float32, uResolution, uMouse *mgl32.Vec2) {
|
|
||||||
wc := w.GetCanvas()
|
|
||||||
wc.BindUniform("u_resolution", uResolution)
|
|
||||||
wc.BindUniform("u_mouse", uMouse)
|
|
||||||
wc.BindUniform("u_amount", uAmount)
|
|
||||||
wc.SetFragmentShader(pixelateFragShader)
|
|
||||||
wc.UpdateShader()
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadPicture(path string) (pixel.Picture, error) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
img, _, err := image.Decode(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return pixel.PictureDataFromImage(img), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadSprite(path string) (pixel.Sprite, error) {
|
|
||||||
pic, err := loadPicture(path)
|
|
||||||
if err != nil {
|
|
||||||
return *pixel.NewSprite(pic, pic.Bounds()), err
|
|
||||||
}
|
|
||||||
sprite := pixel.NewSprite(pic, pic.Bounds())
|
|
||||||
return *sprite, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadTTF(path string, size float64, origin pixel.Vec) *text.Text {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
font, err := truetype.Parse(bytes)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
face := truetype.NewFace(font, &truetype.Options{
|
|
||||||
Size: size,
|
|
||||||
GlyphCacheEntries: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
atlas := text.NewAtlas(face, text.ASCII)
|
|
||||||
|
|
||||||
txt := text.New(origin, atlas)
|
|
||||||
|
|
||||||
return txt
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() {
|
|
||||||
// Set up window configs
|
|
||||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
|
||||||
Title: "Golang Jetpack!",
|
|
||||||
Bounds: pixel.R(0, 0, 1024, 768),
|
|
||||||
VSync: true,
|
|
||||||
}
|
|
||||||
win, err := pixelgl.NewWindow(cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Importantr variables
|
|
||||||
var jetX, jetY, velX, velY, radians float64
|
|
||||||
flipped := 1.0
|
|
||||||
jetpackOn := false
|
|
||||||
gravity := 0.6 // Default: 0.004
|
|
||||||
jetAcc := 0.9 // Default: 0.008
|
|
||||||
tilt := 0.01 // Default: 0.001
|
|
||||||
whichOn := false
|
|
||||||
onNumber := 0
|
|
||||||
jetpackOffName := "jetpack.png"
|
|
||||||
jetpackOn1Name := "jetpack-on.png"
|
|
||||||
jetpackOn2Name := "jetpack-on2.png"
|
|
||||||
camVector := win.Bounds().Center()
|
|
||||||
|
|
||||||
var uAmount float32
|
|
||||||
var uMouse, uResolution mgl32.Vec2
|
|
||||||
|
|
||||||
InstallShader(win, &uAmount, &uResolution, &uMouse)
|
|
||||||
|
|
||||||
bg, _ := loadSprite("sky.png")
|
|
||||||
|
|
||||||
// Jetpack - Rendering
|
|
||||||
jetpackOff, err := loadSprite(jetpackOffName)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
jetpackOn1, err := loadSprite(jetpackOn1Name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
jetpackOn2, err := loadSprite(jetpackOn2Name)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tutorial Text
|
|
||||||
txt := loadTTF("intuitive.ttf", 50, pixel.V(win.Bounds().Center().X-450, win.Bounds().Center().Y-200))
|
|
||||||
fmt.Fprintf(txt, "Explore the Skies with WASD or Arrow Keys!")
|
|
||||||
|
|
||||||
currentSprite := jetpackOff
|
|
||||||
|
|
||||||
canvas := pixelgl.NewCanvas(win.Bounds())
|
|
||||||
uResolution[0] = float32(win.Bounds().W())
|
|
||||||
uResolution[1] = float32(win.Bounds().H())
|
|
||||||
uAmount = 300.0
|
|
||||||
// Game Loop
|
|
||||||
for !win.Closed() {
|
|
||||||
|
|
||||||
mpos := win.MousePosition()
|
|
||||||
uMouse[0] = float32(mpos.X)
|
|
||||||
uMouse[1] = float32(mpos.Y)
|
|
||||||
win.SetTitle(fmt.Sprint(uAmount))
|
|
||||||
win.Clear(colornames.Blue)
|
|
||||||
canvas.Clear(colornames.Green)
|
|
||||||
|
|
||||||
// Jetpack - Controls
|
|
||||||
jetpackOn = win.Pressed(pixelgl.KeyUp) || win.Pressed(pixelgl.KeyW)
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyRight) || win.Pressed(pixelgl.KeyD) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = -1
|
|
||||||
radians -= tilt
|
|
||||||
velX += tilt * 30
|
|
||||||
} else if win.Pressed(pixelgl.KeyLeft) || win.Pressed(pixelgl.KeyA) {
|
|
||||||
jetpackOn = true
|
|
||||||
flipped = 1
|
|
||||||
radians += tilt
|
|
||||||
velX -= tilt * 30
|
|
||||||
} else {
|
|
||||||
if velX < 0 {
|
|
||||||
radians -= tilt / 3
|
|
||||||
velX += tilt * 10
|
|
||||||
} else if velX > 0 {
|
|
||||||
radians += tilt / 3
|
|
||||||
velX -= tilt * 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if jetY < 0 {
|
|
||||||
jetY = 0
|
|
||||||
velY = -0.3 * velY
|
|
||||||
}
|
|
||||||
|
|
||||||
if jetpackOn {
|
|
||||||
velY += jetAcc
|
|
||||||
whichOn = !whichOn
|
|
||||||
onNumber++
|
|
||||||
if onNumber == 5 { // every 5 frames, toggle anijetMation
|
|
||||||
onNumber = 0
|
|
||||||
if whichOn {
|
|
||||||
currentSprite = jetpackOn1
|
|
||||||
} else {
|
|
||||||
currentSprite = jetpackOn2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentSprite = jetpackOff
|
|
||||||
velY -= gravity
|
|
||||||
}
|
|
||||||
|
|
||||||
if win.Pressed(pixelgl.KeyEqual) {
|
|
||||||
uAmount += 10
|
|
||||||
}
|
|
||||||
if win.Pressed(pixelgl.KeyMinus) {
|
|
||||||
uAmount -= 10
|
|
||||||
}
|
|
||||||
|
|
||||||
positionVector := pixel.V(win.Bounds().Center().X+jetX, win.Bounds().Center().Y+jetY-372)
|
|
||||||
jetMat := pixel.IM
|
|
||||||
jetMat = jetMat.Scaled(pixel.ZV, 4)
|
|
||||||
jetMat = jetMat.Moved(positionVector)
|
|
||||||
jetMat = jetMat.ScaledXY(positionVector, pixel.V(flipped, 1))
|
|
||||||
jetMat = jetMat.Rotated(positionVector, radians)
|
|
||||||
|
|
||||||
jetX += velX
|
|
||||||
jetY += velY
|
|
||||||
|
|
||||||
// Camera
|
|
||||||
camVector.X += (positionVector.X - camVector.X) * 0.2
|
|
||||||
camVector.Y += (positionVector.Y - camVector.Y) * 0.2
|
|
||||||
|
|
||||||
if camVector.X > 25085 {
|
|
||||||
camVector.X = 25085
|
|
||||||
} else if camVector.X < -14843 {
|
|
||||||
camVector.X = -14843
|
|
||||||
}
|
|
||||||
|
|
||||||
if camVector.Y > 22500 {
|
|
||||||
camVector.Y = 22500
|
|
||||||
}
|
|
||||||
|
|
||||||
cam := pixel.IM.Moved(win.Bounds().Center().Sub(camVector))
|
|
||||||
|
|
||||||
canvas.SetMatrix(cam)
|
|
||||||
|
|
||||||
// Drawing to the screen
|
|
||||||
win.SetSmooth(true)
|
|
||||||
bg.Draw(canvas, pixel.IM.Moved(pixel.V(win.Bounds().Center().X, win.Bounds().Center().Y+766)).Scaled(pixel.ZV, 10))
|
|
||||||
txt.Draw(canvas, pixel.IM)
|
|
||||||
win.SetSmooth(false)
|
|
||||||
currentSprite.Draw(canvas, jetMat)
|
|
||||||
canvas.Draw(win, pixel.IM.Moved(win.Bounds().Center()))
|
|
||||||
win.Update()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pixelgl.Run(run)
|
|
||||||
}
|
|
||||||
|
|
||||||
var pixelateFragShader = `
|
|
||||||
#version 330 core
|
|
||||||
#ifdef GL_ES
|
|
||||||
precision mediump float;
|
|
||||||
precision mediump int;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
in vec4 Color;
|
|
||||||
in vec2 texcoords;
|
|
||||||
in vec2 glpos;
|
|
||||||
|
|
||||||
out vec4 fragColor;
|
|
||||||
|
|
||||||
uniform vec4 u_colormask;
|
|
||||||
uniform vec4 u_texbounds;
|
|
||||||
uniform sampler2D u_texture;
|
|
||||||
uniform float u_amount;
|
|
||||||
uniform vec2 u_mouse;
|
|
||||||
uniform vec2 u_resolution;
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
vec2 t = (texcoords - u_texbounds.xy) / u_texbounds.zw;
|
|
||||||
|
|
||||||
float d = 1.0 / u_amount;
|
|
||||||
float ar = u_resolution.x / u_resolution.y;
|
|
||||||
float u = floor( t.x / d ) * d;
|
|
||||||
d = ar / u_amount;
|
|
||||||
float v = floor( t.y / d ) * d;
|
|
||||||
fragColor = texture( u_texture, vec2( u, v ) );
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
/*
|
|
||||||
//fragColor = vec4(1.0,0.0,0.0,1.0);
|
|
||||||
// float d = 1.0 / u_amount;
|
|
||||||
// float ar = u_resolution.x / u_resolution.y;
|
|
||||||
// float u = floor( texcoords.x / d ) * d;
|
|
||||||
// d = ar / u_amount;
|
|
||||||
// float v = floor( texcoords.y / d ) * d;
|
|
||||||
// fragColor = texture( u_texture, vec2( u, v ) );
|
|
||||||
|
|
||||||
// vec2 p = t.st;
|
|
||||||
// p.x -= mod(t.x / glpos.x, t.x / glpos.x + 0.1);
|
|
||||||
// p.y -= mod(t.y / glpos.y, t.y / glpos.y + 0.1);
|
|
||||||
|
|
||||||
// fragColor = texture(u_texture, p).rgba;
|
|
||||||
*/
|
|
||||||
// varying vec2 vUv;
|
|
||||||
// uniform sampler2D tInput;
|
|
||||||
// uniform vec2 resolution;
|
|
||||||
// uniform float amount;
|
|
||||||
|
|
||||||
// void main() {
|
|
||||||
|
|
||||||
// float d = 1.0 / amount;
|
|
||||||
// float ar = resolution.x / resolution.y;
|
|
||||||
// float u = floor( vUv.x / d ) * d;
|
|
||||||
// d = ar / amount;
|
|
||||||
// float v = floor( vUv.y / d ) * d;
|
|
||||||
// gl_FragColor = texture2D( tInput, vec2( u, v ) );
|
|
||||||
|
|
||||||
// }
|
|
Before Width: | Height: | Size: 243 B |
Before Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 2.7 MiB |
|
@ -1,7 +1 @@
|
||||||
# Go Jetpack
|
A cartoon-izing shader added to the Jetpack demo!
|
||||||
by [Branson Camp](https://github.com/bcamp1) using [Pixel](https://github.com/faiface/pixel)
|
|
||||||
|
|
||||||
Welcome to Go-Jetpack, where you explore the skies using WASD or Arrow Keys.
|
|
||||||
This example showcases most of the fundamental pixel elements described in the [Pixel Wiki](https://github.com/faiface/pixel/wiki)
|
|
||||||
|
|
||||||

|
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 12 KiB |
|
@ -1,13 +1 @@
|
||||||
# Isometric view basics
|
A realtime embossing shader on the isometric demo!
|
||||||
|
|
||||||
Created by [Sergio Vera](https://github.com/svera).
|
|
||||||
|
|
||||||
Isometric view is a display method used to create an illusion of 3D for an otherwise 2D game - sometimes referred to as pseudo 3D or 2.5D.
|
|
||||||
|
|
||||||
Implementing an isometric view can be done in many ways, but for the sake of simplicity we'll implement a tile-based approach, which is the most efficient and widely used method.
|
|
||||||
|
|
||||||
In the tile-based approach, each visual element is broken down into smaller pieces, called tiles, of a standard size. These tiles will be arranged to form the game world according to pre-determined level data - usually a 2D array.
|
|
||||||
|
|
||||||
For a detailed explanation about the maths behind this, read [http://clintbellanger.net/articles/isometric_math/](http://clintbellanger.net/articles/isometric_math/).
|
|
||||||
|
|
||||||

|
|
After Width: | Height: | Size: 330 KiB |
|
@ -1,9 +1 @@
|
||||||
# Parallax scrolling demo
|
A terrible "edge-detecting" shader on top of the parallax demo. Adjust with the -/+ keys.
|
||||||
|
|
||||||
Created by [Sergio Vera](https://github.com/svera)
|
|
||||||
|
|
||||||
This example shows how to implement an infinite side scrolling background with a depth effect, using [parallax scrolling](https://en.wikipedia.org/wiki/Parallax_scrolling). Code is based in the [infinite scrolling background](https://github.com/faiface/pixel/tree/master/examples/community/scrolling-background) demo.
|
|
||||||
|
|
||||||
Credits to [Peter Hellberg](https://github.com/peterhellberg) for the improved background images.
|
|
||||||
|
|
||||||

|
|
After Width: | Height: | Size: 20 KiB |
|
@ -1,22 +1 @@
|
||||||
# raycaster
|
FXAA emulating shader on top of the raycaster demo! Use the -/+ key to enable and disable.
|
||||||
|
|
||||||
A raycaster made by [Peter Hellberg](https://github.com/peterhellberg/) as part of his [pixel-experiments](https://github.com/peterhellberg/pixel-experiments).
|
|
||||||
|
|
||||||
Based on Lode’s article on [raycasting](http://lodev.org/cgtutor/raycasting.html).
|
|
||||||
|
|
||||||
## Controls
|
|
||||||
|
|
||||||
WASD for strafing and arrow keys for rotation.
|
|
||||||
|
|
||||||
Place blocks using the number keys.
|
|
||||||
|
|
||||||
## Screenshots
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Links
|
|
||||||
|
|
||||||
- https://github.com/peterhellberg/pixel-experiments/tree/master/raycaster
|
|
||||||
- https://gist.github.com/peterhellberg/835eccabf95800555120cc8f0c9e16c2
|
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 223 KiB |