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')
#pdcursesdep = [dependency('pdcurses'), dependency('SDL')]
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 "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++;
// width++;
// height--;
// int widthold = width;
int heightold = height;
while(height > 0){
while(height >= 0){
zom_putcharat(width, height, '&');
height--;
}
height = heightold;
while(width > 0){
while(width >= 0){
zom_putcharat(width, height, '&');
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
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();
@ -77,31 +107,19 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
switch (zom_getch()) {
case 'a':
if (attempt_move(player.x, player.y, 1, 2) == 1) {
player.x--;
player.under_char = readmap(player.x, player.y);
}
attempt_move(&player, 1, 2);
break;
case 'w':
if (attempt_move(player.x, player.y, 1, 1) == 1) {
player.y--;
player.under_char = readmap(player.x, player.y);
}
attempt_move(&player, 1, 1);
break;
case 'd':
if (attempt_move(player.x, player.y, 1, 0) == 1) {
player.x++;
player.under_char = readmap(player.x, player.y);
}
attempt_move(&player, 1, 0);
break;
case 's':
if (attempt_move(player.x, player.y, 1, 3) == 1) {
player.y++;
player.under_char = readmap(player.x, player.y);
}
attempt_move(&player, 1, 3);
break;
case 'q':
@ -113,12 +131,13 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
break;
//debug case
case 'l':
debugent_x.x++;
// 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)){
if ((enemy.x == player.x) && (enemy.y == player.y)) {
zom_screxit();
puts("you lose :(");
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++;}
}
/*
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;
}

View file

@ -1,10 +1,22 @@
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
}
int render_map(void) {
int x;
int y;
//I think this is broken but maybe with with the border code idk TODO fix
for(y = 0; y < 40; y++) {
for(x = 0; x < 80; x++) {
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
int mapwidth = 80;
int mapheight = 40;
char maptest[40][80] = {
{'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
{'2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},

View file

@ -1,42 +1,53 @@
//TODO fix this bug
//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
int attempt_move(int x, int y, int units, int direction) {
int xfuture = x;
int yfuture = y;
int attempt_move(struct entity *fuck, int units, int direction) {
int xfuture = fuck->x;
int yfuture = fuck->y;
switch (direction) {
case 0: // right
xfuture = xfuture + units;
if (readmap(xfuture, y) == '&') {
if (readmap(xfuture, fuck->y) == '&') {
return 0;
}
else {
fuck->x++;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1;
}
case 1: // up
yfuture = yfuture - units; // we subtract because moving up
if (readmap(x, yfuture) == '&') {
if (readmap(fuck->x, yfuture) == '&') {
return 0;
}
else {
fuck->y--;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1;
}
case 2: // left
xfuture = xfuture - units;
if (readmap(xfuture, y) == '&') {
if (readmap(xfuture, fuck->y) == '&') {
return 0;
}
else {
fuck->x--;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1;
}
case 3: // down
yfuture = yfuture + units;
if (readmap(x, yfuture) == '&') {
if (readmap(fuck->x, yfuture) == '&') {
return 0;
}
else {
fuck->y++;
fuck->under_char = readmap(fuck->x, fuck->y);
return 1;
}
}
return 0;
}
void all_entity(struct entity *fuck) {
fuck->x++;
}