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')
|
cursesdep = dependency('curses')
|
||||||
|
#pdcursesdep = [dependency('pdcurses'), dependency('SDL')]
|
||||||
executable('playergame', 'src/main.c', dependencies: cursesdep)
|
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 "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...
|
||||||
|
@ -140,22 +159,25 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//anti go off screen
|
//anti go off screen
|
||||||
|
|
||||||
if (player.x < 0) {
|
if (player.x < 0) {
|
||||||
player.x = 0;
|
player.x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.x > 80) {
|
if (player.x > (scrwidth - 1)) {
|
||||||
player.x = 80;
|
player.x = scrwidth - 1;
|
||||||
}
|
}
|
||||||
if (player.y < 0) {
|
if (player.y < 0) {
|
||||||
player.y = 0;
|
player.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.y > 40) {
|
if (player.y > (scrheight - 1)) {
|
||||||
player.y = 40;
|
player.y = scrheight - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//scrwidth - 1 bc zero indexed moment
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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++;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue