Compare commits

...

2 commits

5 changed files with 88 additions and 68 deletions

View file

@ -5,5 +5,6 @@ project('playergame', 'c',
] ]
) )
cursesdep = dependency('curses') cursesdep = dependency('curses')
#pdcursesdep = [dependency('pdcurses'), dependency('SDL')]
executable('playergame', 'src/main.c', dependencies: cursesdep) executable('playergame', 'src/main.c', dependencies: cursesdep)

View file

@ -3,25 +3,68 @@
#include "linux.h" //TODO make this detect and change depending on os #include "linux.h" //TODO make this detect and change depending on os
#include "maptest.h" #include "maptest.h"
#include "map.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" #include "movement.h"
int scrwidth = 80; int scrwidth = 80;
int scrheight = 40; int scrheight = 40;
int render_border (int width, int height) { int render_border (int width, int height) {
width++; // width++;
height++; // height--;
// int widthold = width; // int widthold = width;
int heightold = height; int heightold = height;
while(height > 0){ while(height >= 0){
zom_putcharat(width, height, '&'); zom_putcharat(width, height, '&');
height--; height--;
} }
height = heightold; height = heightold;
while(width > 0){ while(width >= 0){
zom_putcharat(width, height, '&'); zom_putcharat(width, height, '&');
width--; width--;
} }
@ -39,19 +82,6 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
//here it js being stolen from curses //here it js being stolen from curses
bool gamerun = true; bool gamerun = true;
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, ' ', ' '};
zom_scrinit(); zom_scrinit();
@ -77,31 +107,19 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
switch (zom_getch()) { switch (zom_getch()) {
case 'a': case 'a':
if (attempt_move(player.x, player.y, 1, 2) == 1) { attempt_move(&player, 1, 2);
player.x--;
player.under_char = readmap(player.x, player.y);
}
break; break;
case 'w': case 'w':
if (attempt_move(player.x, player.y, 1, 1) == 1) { attempt_move(&player, 1, 1);
player.y--;
player.under_char = readmap(player.x, player.y);
}
break; break;
case 'd': case 'd':
if (attempt_move(player.x, player.y, 1, 0) == 1) { attempt_move(&player, 1, 0);
player.x++;
player.under_char = readmap(player.x, player.y);
}
break; break;
case 's': case 's':
if (attempt_move(player.x, player.y, 1, 3) == 1) { attempt_move(&player, 1, 3);
player.y++;
player.under_char = readmap(player.x, player.y);
}
break; break;
case 'q': case 'q':
@ -113,12 +131,13 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
break; break;
//debug case //debug case
case 'l': case 'l':
debugent_x.x++; // debugent_x.x++;
debugent_y.y++; debugent_y.y++;
all_entity(&debugent_x);
break; break;
} }
//game logic not kb dependent //game logic not kb dependent
if ((enemy.x == player.x) && (enemy.y == player.y)){ if ((enemy.x == player.x) && (enemy.y == player.y)) {
zom_screxit(); zom_screxit();
puts("you lose :("); puts("you lose :(");
return 0; //TODO fix this this should not be here... return 0; //TODO fix this this should not be here...
@ -133,31 +152,6 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
} else {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 > 80) {
player.x = 80;
}
if (player.y < 0) {
player.y = 0;
}
if (player.y > 40) {
player.y = 40;
}
prevtime = currenttime; prevtime = currenttime;
} }

View file

@ -1,10 +1,22 @@
char readmap(int x, int y) { char readmap(int x, int y) {
if (x > (mapwidth - 1)) {
return '&';
}
if (y > (mapheight - 1)) {
return '&';
}
if (x < 0) {
return '&';
}
if (y < 0) {
return '&';
}
return maptest[y][x]; //TODO make it be able to rrad feom multiple maps but idk how to do that return maptest[y][x]; //TODO make it be able to rrad feom multiple maps but idk how to do that
} }
int render_map(void) { int render_map(void) {
int x; int x;
int y; int y;
//I think this is broken but maybe with with the border code idk TODO fix
for(y = 0; y < 40; y++) { for(y = 0; y < 40; y++) {
for(x = 0; x < 80; x++) { for(x = 0; x < 80; x++) {
zom_putcharat(x, y, readmap(x, y)); zom_putcharat(x, y, readmap(x, y));

View file

@ -1,4 +1,6 @@
//TODO make this read from a file instead of from this array pile //TODO make this read from a file instead of from this array pile
int mapwidth = 80;
int mapheight = 40;
char maptest[40][80] = { char maptest[40][80] = {
{'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'}, {'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
{'2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'}, {'2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},

View file

@ -1,42 +1,53 @@
//TODO fix this bug //TODO fix this bug
//there is a bug with the units arg //there is a bug with the units arg
//it doesnt check weather EVERY spot in its path is vaiid so it allows the possibity of going thru walls if units is more than 1 //it doesnt check weather EVERY spot in its path is vaiid so it allows the possibity of going thru walls if units is more than 1
int attempt_move(int x, int y, int units, int direction) { int attempt_move(struct entity *fuck, int units, int direction) {
int xfuture = x; int xfuture = fuck->x;
int yfuture = y; int yfuture = fuck->y;
switch (direction) { switch (direction) {
case 0: // right case 0: // right
xfuture = xfuture + units; xfuture = xfuture + units;
if (readmap(xfuture, y) == '&') { if (readmap(xfuture, fuck->y) == '&') {
return 0; return 0;
} }
else { else {
fuck->x++;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1; return 1;
} }
case 1: // up case 1: // up
yfuture = yfuture - units; // we subtract because moving up yfuture = yfuture - units; // we subtract because moving up
if (readmap(x, yfuture) == '&') { if (readmap(fuck->x, yfuture) == '&') {
return 0; return 0;
} }
else { else {
fuck->y--;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1; return 1;
} }
case 2: // left case 2: // left
xfuture = xfuture - units; xfuture = xfuture - units;
if (readmap(xfuture, y) == '&') { if (readmap(xfuture, fuck->y) == '&') {
return 0; return 0;
} }
else { else {
fuck->x--;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1; return 1;
} }
case 3: // down case 3: // down
yfuture = yfuture + units; yfuture = yfuture + units;
if (readmap(x, yfuture) == '&') { if (readmap(fuck->x, yfuture) == '&') {
return 0; return 0;
} }
else { else {
fuck->y++;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1; return 1;
} }
} }
return 0; return 0;
} }
void all_entity(struct entity *fuck) {
fuck->x++;
}