Skip to content

Commit

Permalink
*: remove stdio.h file operation dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Lewiński <filip.lewinski@3mdeb.com>
  • Loading branch information
filipleple committed Jul 24, 2024
1 parent 6cb3e10 commit cc6c1b4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
override CC := ../../libpayload/bin/lpgcc
override LD := ../../libpayload/bin/lpgcc

#CFLAGS = -Wall -D_DEBUG -g
#CFLAGS = -Wall
LDFLAGS = -lcurses
LDFLAGS = -lcurses -nostdlib

pacman: pacman.o player.o ghosts.o pills.o render.o board.o gameloop.o
pacman.o: pacman.h render.h gameloop.h
Expand Down
1 change: 0 additions & 1 deletion src/gameloop.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
Expand Down
82 changes: 60 additions & 22 deletions src/pacman.c
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
/*
** Pacman - In curses
*/
#include <stdio.h>
#include <ctype.h>
#include "pacman.h"
#include "render.h"
#include "gameloop.h"
#include "libpayload.h"

void GetMarqueeText(GAME_STATE *ptr) {
FILE *fp = fopen("pactext", "r");
int i;
char *pc;

ptr->pMarquee = 0;
if (fp) {
fseek(fp, 0, SEEK_END);
ptr->iMarqueeSize = ftell(fp);
if ((ptr->pMarquee = malloc(ptr->iMarqueeSize))){
fseek(fp,0,SEEK_SET);
fread(ptr->pMarquee, 1, ptr->iMarqueeSize, fp);
pc = ptr->pMarquee;
for(i=0;i<ptr->iMarqueeSize;i++,pc++)
if (isalnum(*pc) || ispunct(*pc))
;/*empty*/
else
*pc = ' ';
}
fclose(fp);
}
// void GetMarqueeText(GAME_STATE *ptr) {
// FILE *fp = fopen("pactext", "r");
// int i;
// char *pc;

// ptr->pMarquee = 0;
// if (fp) {
// fseek(fp, 0, SEEK_END);
// ptr->iMarqueeSize = ftell(fp);
// if ((ptr->pMarquee = malloc(ptr->iMarqueeSize))){
// fseek(fp,0,SEEK_SET);
// fread(ptr->pMarquee, 1, ptr->iMarqueeSize, fp);
// pc = ptr->pMarquee;
// for(i=0;i<ptr->iMarqueeSize;i++,pc++)
// if (isalnum(*pc) || ispunct(*pc))
// ;/*empty*/
// else
// *pc = ' ';
// }
// fclose(fp);
// }
// }







void GetMarqueeText(GAME_STATE *ptr)
{
// Hardcoded marquee text (replace this with the actual text if known)
const char *marqueeText = "Pac-Man: Insert Coin to Start! Use Arrow Keys to Move. Eat All Dots to Win!";

ptr->iMarqueeSize = strlen(marqueeText);
ptr->pMarquee = (char *)malloc(ptr->iMarqueeSize + 1); // Allocate memory for the text plus null terminator

if (ptr->pMarquee) {
strcpy(ptr->pMarquee, marqueeText); // Copy the hardcoded text to the allocated memory

// Process the text
char *pc = ptr->pMarquee;
for (int i = 0; i < ptr->iMarqueeSize; i++, pc++) {
if (isalnum(*pc) || ispunct(*pc)) {
; // Keep alphanumeric and punctuation characters as they are
} else {
*pc = ' '; // Replace other characters with a space
}
}
}
}











int main(int argc, char **argv) {
GAME_STATE game;
void *pRender;
Expand Down
5 changes: 2 additions & 3 deletions src/pills.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <stdio.h>
#include "pacman.h"
#include "pills.h"
#include "board.h"
Expand All @@ -13,7 +12,7 @@ char c;
ptr->iSpecialChar = ptr->iLevel;
ptr->SpecialPos.x = ptr->SpecialPos.y = 14;
Pac_RespawnSpecial(ptr);

i=0;
for(y=0;y<ptr->iMapHeight;y++)
for(x=0;x<ptr->iMapWidth;x++)
Expand All @@ -37,7 +36,7 @@ char c;
void Pac_UpdatePills(GAME_STATE *ptr, float telaps)
{
ptr->iPP_Timecum += telaps;
if (ptr->iPP_Timecum > 0.5f)
if (ptr->iPP_Timecum > 0.5f)
{
ptr->iPP_Timecum = 0;
ptr->iPP_Flash ^= 1;
Expand Down
4 changes: 4 additions & 0 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#define PC_EDIBLE_GHOST 6
#define PC_GHOST 20

void fwrite(){

}

void *Pac_InitRender(void)
{
int gcol[] = { COLOR_RED, COLOR_GREEN, COLOR_MAGENTA, COLOR_CYAN, };
Expand Down

0 comments on commit cc6c1b4

Please # to comment.