Skip to content

Commit

Permalink
Nueva versión con enemigo y jugador que se mueven en una dimensión
Browse files Browse the repository at this point in the history
Dibujamos suelo también!
  • Loading branch information
heclinares authored and lronaldo committed Jul 23, 2019
1 parent b44f2d5 commit 2572444
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 27 deletions.
Binary file modified c/agc01/agc01.cdt
Binary file not shown.
Binary file modified c/agc01/agc01.dsk
Binary file not shown.
Binary file modified c/agc01/agc01.sna
Binary file not shown.
110 changes: 83 additions & 27 deletions c/agc01/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@
#include <cpctelera.h>
#include <stdio.h>

u8 FNr(u8 m) {
return m-3+(cpct_rand()*7/255);
}

void locate(u8 x, u8 y) {
putchar(31);
putchar(x);
putchar(y);
}

void renderString(u8 ch, u8 n) {
while(n--) {
putchar(ch);
}
}

void main(void) {
// Init variables
u8 energy = 100;
u8 attack = 30;
u8 defense = 15;
u8 energyen = 90;
u8 attacken = 20;
u8 defenseen = 10;
u8 e = 100, a = 30, d = 15, x = 4, f = 0;
u8 ee = 90, ea = 20, ed = 10, ex = 7, ei = 0;

i8 em[4] = {-1, 1, 1, -1};

// Let's start!
printf("RPG GAME\r\n");
printf("\r\n");
printf("PRESS ENTER TO START\r\n");
puts("RPG GAME\r\n\r\nPRESS ENTER TO START");

// Is enter pressed?
while (!cpct_isKeyPressed(Key_Enter)) {
Expand All @@ -32,34 +44,78 @@ void main(void) {
putchar(12);

// Print stats
printf("PLAYER [%d] (a%d) (d%d)\r\n", energy, attack, defense);
printf("ENEMY [%d] (a%d) (d%d)\r\n", energyen, attacken, defenseen);
printf("PLAYER [%d] (a%d) (d%d)\r\n", e, a, d);
printf("ENEMY [%d] (a%d) (d%d)\r\n", ee, ea, ed);

// Re scan keyboard
cpct_scanKeyboard();
// RENDER PLAYER
locate(x, 6);
putchar(250);

while (!cpct_isKeyPressed(Key_A) && !cpct_isKeyPressed(Key_D)) {
// RENDER ENEMY
locate(ex, 6);
putchar(224);

// RENDER GROUND
locate(1, 7);
renderString(143, 10);
locate(1, 8);
renderString(216, 10);

// Re scan keyboard
do
cpct_scanKeyboard();
}
while (!cpct_isKeyPressed(Key_O) && !cpct_isKeyPressed(Key_P) && !cpct_isKeyPressed(Key_D));

// PLAYER ATTACKS!
if (cpct_isKeyPressed(Key_A)) {
energyen -= attack;
// PLAYER MOVES LEFT!
if (cpct_isKeyPressed(Key_O)) {
if(x > 1) x--;
} else {
// PLAYER DEFENDS!
if (cpct_isKeyPressed(Key_D)) {
energy += defense;
// PLAYER MOVES RIGHT!
if (cpct_isKeyPressed(Key_P)) {
x++;
// PLAYER ATTACKS!!
if(x == ex) {
x--;
locate(1,10);
f = FNr(a);
ee -= f;
printf("PLAYER ATTACKS WITH FORCE: %d", f);
}
} else {
// PLAYER DEFENDS!
if (cpct_isKeyPressed(Key_D)) {
f = FNr(d);
e += f;
locate(1,10);
printf("PLAYER DEFENDS WITH FORCE: %d", f);
}
}
}

// ENEMY DECIDE
if (cpct_rand() < 64) {
energyen += defenseen;
if (ex == x+1) {
if (cpct_rand() < 64) {
f = FNr(ed);
ee += f;
locate(1,11);
printf("ENEMY DEFENDS WITH FORCE: %d", f);
} else {
// ENEMY ATTACKS!
f = FNr(ea);
e -= f;
locate(1,11);
printf("ENEMY ATTACKS WITH FORCE: %d", f);
}
} else {
energy -= attacken;
// UPDATE ENEMY POSITION
ex += em[ei];
ei++;
if (ei > 3) ei = 0;
}

// Is enter pressed?
while (!cpct_isKeyPressed(Key_Enter)) {
cpct_scanKeyboard();
}
}

// Loop forever
while (1);
}

0 comments on commit 2572444

Please sign in to comment.