made attempt_move move the entity
This commit is contained in:
parent
97aac29626
commit
35ff2debdb
3 changed files with 80 additions and 46 deletions
|
@ -5,5 +5,6 @@ project('playergame', 'c',
|
|||
]
|
||||
)
|
||||
cursesdep = dependency('curses')
|
||||
#pdcursesdep = [dependency('pdcurses'), dependency('SDL')]
|
||||
executable('playergame', 'src/main.c', dependencies: cursesdep)
|
||||
|
||||
|
|
100
src/main.c
100
src/main.c
|
@ -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...
|
||||
|
@ -140,21 +159,24 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
|
|||
*/
|
||||
|
||||
//anti go off screen
|
||||
|
||||
if (player.x < 0) {
|
||||
player.x = 0;
|
||||
}
|
||||
|
||||
if (player.x > 80) {
|
||||
player.x = 80;
|
||||
if (player.x > (scrwidth - 1)) {
|
||||
player.x = scrwidth - 1;
|
||||
}
|
||||
if (player.y < 0) {
|
||||
player.y = 0;
|
||||
}
|
||||
|
||||
if (player.y > 40) {
|
||||
player.y = 40;
|
||||
if (player.y > (scrheight - 1)) {
|
||||
player.y = scrheight - 1;
|
||||
}
|
||||
|
||||
|
||||
//scrwidth - 1 bc zero indexed moment
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue