playergame/src/main.c

228 lines
6.4 KiB
C

#include <stdio.h> //printf and shit
#include <time.h>
#include "linux.h" //TODO make this detect and change depending on os
#include "maptest.h"
#include "map.h"
//######################################################
//######################################################
//######################################################
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
struct entity {
int x;
int y;
int xold; //i kinda dont like tbid xold yold shit
int yold;
char under_char; //the char that is under the entity so when it moves off of it it wont be erased
char under_charold;
}
player = {0, 0, 0, 0, ' ', ' '},
enemy = {24, 16, 0, 0, ' ', ' '},
debugent_x = {0, 0, 0, 0, ' ', ' '},
debugent_y = {0, 0, 0, 0, ' ', ' '};
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//HOLY FUCK MOVE THIS NOW!!! TODO
//######################################################
//######################################################
//######################################################
//######################################################
#include "movement.h"
int scrwidth = 80;
int scrheight = 40;
int render_border (int width, int height) {
// width++;
// height--;
// int widthold = width;
int heightold = height;
while(height >= 0){
zom_putcharat(width, height, '&');
height--;
}
height = heightold;
while(width >= 0){
zom_putcharat(width, height, '&');
width--;
}
return 0;
}
int main( int argc, char *argv[] ) { //yoinked from the internet argc is number of args and argv is a "array of arguments"
clock_t prevtime, currenttime;
prevtime = clock();
int delay = 1000;
int dosspin = 0;
//TODO nuke bools they arnt part of the c99 standard
//here it js being stolen from curses
bool gamerun = true;
zom_scrinit();
render_border(scrwidth, scrheight);
render_map();
while(gamerun) {
currenttime = clock();
dosspin = clock() % 4;
//TODO fix the timing cancer
// if ((currenttime - prevtime) > delay) {
if ((currenttime % 5000)==0) {
player.xold = player.x;
player.yold = player.y;
player.under_charold = player.under_char;
enemy.xold = enemy.x;
enemy.yold = enemy.y;
debugent_x.xold = debugent_x.x;
debugent_x.yold = debugent_x.y;
debugent_y.xold = debugent_y.x;
debugent_y.yold = debugent_y.y;
switch (zom_getch()) {
case 'a':
attempt_move(&player, 1, 2);
break;
case 'w':
attempt_move(&player, 1, 1);
break;
case 'd':
attempt_move(&player, 1, 0);
break;
case 's':
attempt_move(&player, 1, 3);
break;
case 'q':
gamerun = false;
break;
case 't':
player.x = 9;
player.y = 9;
break;
//debug case
case 'l':
// debugent_x.x++;
debugent_y.y++;
all_entity(&debugent_x);
break;
}
//game logic not kb dependent
if ((enemy.x == player.x) && (enemy.y == player.y)) {
zom_screxit();
puts("you lose :(");
return 0; //TODO fix this this should not be here...
}
//TODO fix enemy movement (it works but its kinda broken)
if ((clock() % 100) == 1) {
if (enemy.x > player.x) {
enemy.x--;
} else {enemy.x++;}
if (enemy.y > player.y) {
enemy.y--;
} else {enemy.y++;}
}
/*
TODO clean this shit up
this should apply to everything not just the player
it should also be generalized to all entitys using a for loop or somthing
*/
//anti go off screen
if (player.x < 0) {
player.x = 0;
}
if (player.x > (scrwidth - 1)) {
player.x = scrwidth - 1;
}
if (player.y < 0) {
player.y = 0;
}
if (player.y > (scrheight - 1)) {
player.y = scrheight - 1;
}
//scrwidth - 1 bc zero indexed moment
prevtime = currenttime;
}
//entity rendering
zom_putcharat(enemy.xold, enemy.yold, ' ');
switch (dosspin) {
case 0:
zom_putcharat(enemy.x, enemy.y, '-');
break;
case 1:
zom_putcharat(enemy.x, enemy.y, '/');
break;
case 2:
zom_putcharat(enemy.x, enemy.y, '|');
break;
case 3:
zom_putcharat(enemy.x, enemy.y, '\\');
break;
}
zom_putcharat(player.xold, player.yold, player.under_charold);
zom_putcharat(player.x, player.y, '#');
zom_putcharat(debugent_x.xold, debugent_x.yold, ' ');
zom_putcharat(debugent_x.x, debugent_x.y, 'X');
zom_putcharat(debugent_y.xold, debugent_y.yold, ' ');
zom_putcharat(debugent_y.x, debugent_y.y, 'Y');
}
//cleanup
zom_screxit();
printf("Args %d",argc); //anti Wall Werror Wextra
puts(argv[0]);//anti Wall Werror Wextra
printf("%d", delay);
printf("%ld", prevtime);
printf("Player X: %d", player.x);
printf("Player Y: %d", player.y);
printf("scrwidth: %d", scrwidth);
printf("scrheight: %d", scrheight);
return 0;
}