Commit 8dd14bb4 authored by Luke Tan's avatar Luke Tan

Initial commit

parents
CC=gcc
\ No newline at end of file
File added
#include <simple2d.h>
#include <unistd.h>
// To compile: gcc main.c `simple2d --libs` -o main
// 0: draw
// 1: animation
int currAnim = 0;
int animCounter = 0;
int second = 1000000;
void update() {
switch(currAnim){
case 0:
currAnim++;
animCounter = 0;
break;
default:
if(animCounter == 2){
currAnim++;
animCounter = 0;
} else {
animCounter++;
}
break;
}
}
void render() {
switch(currAnim){
case 0:
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5 ; j++){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 1, 1, 1, 1,
100 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 100 + j * 75, 1, 1, 1, 1
);
}
}
usleep(second);
break;
default:
switch(animCounter){
case 0:
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5 ; j++){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 1, 1, 1, 1,
100 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 100 + j * 75, 1, 1, 1, 1
);
}
}
S2D_DrawQuad(
100 + 2 * 75, 100 + 2 * 75, 0, 0, 1, 1,
100 + 2 * 75, 150 + 2 * 75, 0, 0, 1, 1,
150 + 2 * 75, 150 + 2 * 75, 0, 0, 1, 1,
150 + 2 * 75, 100 + 2 * 75, 0, 0, 1, 1
);
usleep(0.25 * second);
break;
case 1:
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5 ; j++){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 1, 1, 1, 1,
100 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 100 + j * 75, 1, 1, 1, 1
);
}
}
for(int i = 1; i < 4; i++){
for(int j = 1; j < 4 ; j++){
if(!(i == 2 && j == 2)){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 0, 0, 1, 1,
100 + i * 75, 150 + j * 75, 0, 0, 1, 1,
150 + i * 75, 150 + j * 75, 0, 0, 1, 1,
150 + i * 75, 100 + j * 75, 0, 0, 1, 1
);
}
}
}
usleep(0.25 * second);
break;
case 2:
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5 ; j++){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 0, 0, 1, 1,
100 + i * 75, 150 + j * 75, 0, 0, 1, 1,
150 + i * 75, 150 + j * 75, 0, 0, 1, 1,
150 + i * 75, 100 + j * 75, 0, 0, 1, 1
);
}
}
for(int i = 1; i < 4; i++){
for(int j = 1; j < 4 ; j++){
S2D_DrawQuad(
100 + i * 75, 100 + j * 75, 1, 1, 1, 1,
100 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 150 + j * 75, 1, 1, 1, 1,
150 + i * 75, 100 + j * 75, 1, 1, 1, 1
);
}
}
usleep(0.25 * second);
break;
}
}
}
int main() {
S2D_Window *window = S2D_CreateWindow(
"Hello Triangle", 640, 480, update, render, 0
);
S2D_Show(window);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment