Created
December 10, 2018 15:57
-
-
Save rdeioris/6aecef8a95138f6a86a6a1699827d93b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Aiv.Draw; | |
| namespace Filesystem1B | |
| { | |
| class Program | |
| { | |
| static void PutPixel(Window window, int x, int y, byte r, byte g, byte b, byte a) | |
| { | |
| if (x < 0 || x >= window.width || y < 0 || y >= window.height) | |
| { | |
| return; | |
| } | |
| // converto to 0..1 domain | |
| float alpha = a / 255.0f; | |
| float invAlpha = 1 - alpha; | |
| int index = (y * window.width + x) * 3; | |
| // alpha blending | |
| window.bitmap[index] = (byte)((r * alpha) + (window.bitmap[index] * invAlpha)); | |
| window.bitmap[index + 1] = (byte)((g * alpha) + (window.bitmap[index + 1] * invAlpha)); | |
| window.bitmap[index + 2] = (byte)((b * alpha) + (window.bitmap[index + 2] * invAlpha)); | |
| } | |
| static void ClearScreen(Window window) | |
| { | |
| for (int i = 0; i < window.bitmap.Length; i++) | |
| { | |
| window.bitmap[i] = 0; | |
| } | |
| } | |
| static void DrawSprite(Window window, Sprite sprite, int x, int y) | |
| { | |
| for (int spriteY = 0; spriteY < sprite.height; spriteY++) | |
| { | |
| for (int spriteX = 0; spriteX < sprite.width; spriteX++) | |
| { | |
| int index = (spriteY * sprite.width + spriteX) * 4; | |
| byte r = sprite.bitmap[index]; | |
| byte g = sprite.bitmap[index + 1]; | |
| byte b = sprite.bitmap[index + 2]; | |
| byte a = sprite.bitmap[index + 3]; | |
| PutPixel(window, x + spriteX, y + spriteY, r, g, b, a); | |
| } | |
| } | |
| } | |
| static void Main(string[] args) | |
| { | |
| Window window = new Window(1024, 768, "Sprite", PixelFormat.RGB); | |
| Sprite sprite001 = new Sprite("C:/Users/rober/Desktop/spyke_green.png"); | |
| Sprite sprite002 = new Sprite("C:/Users/rober/Desktop/Spaceship-Transparent-PNG.png"); | |
| DrawSprite(window, sprite001, 150, 150); | |
| DrawSprite(window, sprite002, 100, 100); | |
| while (window.opened) | |
| { | |
| window.Blit(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment