init
This commit is contained in:
parent
8dcaded5e8
commit
ba34360e1b
1
.vscode/configurationCache.log
vendored
Normal file
1
.vscode/configurationCache.log
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"buildTargets":[],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}}
|
7
.vscode/dryrun.log
vendored
Normal file
7
.vscode/dryrun.log
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
make --dry-run --always-make --keep-going --print-directory
|
||||
make: Entering directory '/home/bruno/Documents/programming/projects/mazegame'
|
||||
|
||||
make: *** No targets specified and no makefile found. Stop.
|
||||
|
||||
make: Leaving directory '/home/bruno/Documents/programming/projects/mazegame'
|
||||
|
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"preLaunchTask": "Builder",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
]
|
||||
}
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"unistd.h": "c",
|
||||
"main.h": "c"
|
||||
}
|
||||
}
|
368
.vscode/targets.log
vendored
Normal file
368
.vscode/targets.log
vendored
Normal file
@ -0,0 +1,368 @@
|
||||
make all --print-data-base --no-builtin-variables --no-builtin-rules --question
|
||||
make: *** No rule to make target 'all'. Stop.
|
||||
|
||||
# GNU Make 4.3
|
||||
|
||||
# Built for x86_64-pc-linux-gnu
|
||||
|
||||
# Copyright (C) 1988-2020 Free Software Foundation, Inc.
|
||||
|
||||
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
||||
|
||||
# This is free software: you are free to change and redistribute it.
|
||||
|
||||
# There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
|
||||
|
||||
# Make data base, printed on Sun May 29 07:50:20 2022
|
||||
|
||||
|
||||
# Variables
|
||||
|
||||
|
||||
|
||||
# environment
|
||||
|
||||
GDK_BACKEND = x11
|
||||
|
||||
# environment
|
||||
|
||||
LC_ALL = C
|
||||
|
||||
# environment
|
||||
|
||||
GTK_RC_FILES = /etc/gtk/gtkrc:/home/bruno/.gtkrc:/home/bruno/.config/gtkrc
|
||||
|
||||
# environment
|
||||
|
||||
VSCODE_IPC_HOOK_EXTHOST = /run/user/1000/vscode-ipc-2b05d98b-4ba5-4baf-bada-1bada4dc3354.sock
|
||||
|
||||
# environment
|
||||
|
||||
MANDATORY_PATH = /usr/share/gconf/plasma.mandatory.path
|
||||
|
||||
# environment
|
||||
|
||||
LC_NAME = sk_SK.UTF-8
|
||||
|
||||
# environment
|
||||
|
||||
LC_NUMERIC = sk_SK.UTF-8
|
||||
|
||||
# environment
|
||||
|
||||
VSCODE_CWD = /home/bruno
|
||||
|
||||
# environment
|
||||
|
||||
LESS_TERMCAP_me = [0m
|
||||
|
||||
# environment
|
||||
LC_ADDRESS = sk_SK.UTF-8
|
||||
# default
|
||||
MAKE_COMMAND := make
|
||||
# environment
|
||||
FPATH = /home/bruno/.oh-my-zsh/plugins/golang:/home/bruno/.oh-my-zsh/custom/plugins/aliases:/home/bruno/.oh-my-zsh/plugins/safe-paste:/home/bruno/.oh-my-zsh/plugins/screen:/home/bruno/.oh-my-zsh/plugins/ssh-agent:/home/bruno/.oh-my-zsh/plugins/python:/home/bruno/.oh-my-zsh/plugins/nmap:/home/bruno/.oh-my-zsh/plugins/gnu-utils:/home/bruno/.oh-my-zsh/plugins/git-prompt:/home/bruno/.oh-my-zsh/plugins/github:/home/bruno/.oh-my-zsh/plugins/git-lfs:/home/bruno/.oh-my-zsh/plugins/git-auto-fetch:/home/bruno/.oh-my-zsh/plugins/command-not-found:/home/bruno/.oh-my-zsh/plugins/docker-compose:/home/bruno/.oh-my-zsh/plugins/docker:/home/bruno/.oh-my-zsh/plugins/git:/home/bruno/.oh-my-zsh/functions:/home/bruno/.oh-my-zsh/completions:/home/bruno/.oh-my-zsh/cache/completions:/usr/local/share/zsh/functions:/usr/local/share/zsh/site-functions:/usr/share/zsh/vendor-functions:/usr/share/zsh/vendor-completions:/usr/share/zsh/functions/Calendar:/usr/share/zsh/functions/Chpwd:/usr/share/zsh/functions/Completion:/usr/share/zsh/functions/Completion/AIX:/usr/share/zsh/functions/Completion/BSD:/usr/share/zsh/functions/Completion/Base:/usr/share/zsh/functions/Completion/Cygwin:/usr/share/zsh/functions/Completion/Darwin:/usr/share/zsh/functions/Completion/Debian:/usr/share/zsh/functions/Completion/Linux:/usr/share/zsh/functions/Completion/Mandriva:/usr/share/zsh/functions/Completion/Redhat:/usr/share/zsh/functions/Completion/Solaris:/usr/share/zsh/functions/Completion/Unix:/usr/share/zsh/functions/Completion/X:/usr/share/zsh/functions/Completion/Zsh:/usr/share/zsh/functions/Completion/openSUSE:/usr/share/zsh/functions/Exceptions:/usr/share/zsh/functions/MIME:/usr/share/zsh/functions/Math:/usr/share/zsh/functions/Misc:/usr/share/zsh/functions/Newuser:/usr/share/zsh/functions/Prompts:/usr/share/zsh/functions/TCP:/usr/share/zsh/functions/VCS_Info:/usr/share/zsh/functions/VCS_Info/Backends:/usr/share/zsh/functions/Zftp:/usr/share/zsh/functions/Zle
|
||||
# environment
|
||||
QT_ACCESSIBILITY = 1
|
||||
# environment
|
||||
GOPATH = /home/bruno/golang
|
||||
# automatic
|
||||
@D = $(patsubst %/,%,$(dir $@))
|
||||
# environment
|
||||
VSCODE_HANDLES_UNCAUGHT_ERRORS = true
|
||||
# default
|
||||
.VARIABLES :=
|
||||
# environment
|
||||
PWD = /home/bruno/Documents/programming/projects/mazegame
|
||||
# automatic
|
||||
%D = $(patsubst %/,%,$(dir $%))
|
||||
# environment
|
||||
LSCOLORS = Gxfxcxdxbxegedabagacad
|
||||
# environment
|
||||
XDG_DATA_DIRS = /usr/share/plasma:/home/bruno/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
|
||||
# environment
|
||||
OLDPWD = /home/bruno
|
||||
# automatic
|
||||
^D = $(patsubst %/,%,$(dir $^))
|
||||
# environment
|
||||
VSCODE_LOG_STACK = true
|
||||
# automatic
|
||||
%F = $(notdir $%)
|
||||
# environment
|
||||
VSCODE_CODE_CACHE_PATH = /home/bruno/.config/Code - Insiders/CachedData/6428d0fc7dae5801cdaf2d160ac39a3dfc8f0c06
|
||||
# environment
|
||||
XDG_SESSION_PATH = /org/freedesktop/DisplayManager/Session1
|
||||
# environment
|
||||
LANG = C
|
||||
# environment
|
||||
XAUTHORITY = /home/bruno/.Xauthority
|
||||
# default
|
||||
.LOADED :=
|
||||
# environment
|
||||
LESS_TERMCAP_md = [1;36m
|
||||
# default
|
||||
.INCLUDE_DIRS = /usr/local/include /usr/include /usr/include
|
||||
# makefile
|
||||
MAKEFLAGS = pqrR
|
||||
# environment
|
||||
LESS_TERMCAP_so = [01;33m
|
||||
# makefile
|
||||
CURDIR := /home/bruno/Documents/programming/projects/mazegame
|
||||
# environment
|
||||
VSCODE_PIPE_LOGGING = true
|
||||
# environment
|
||||
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = true
|
||||
# automatic
|
||||
*D = $(patsubst %/,%,$(dir $*))
|
||||
# environment
|
||||
LESS_TERMCAP_ue = [0m
|
||||
# environment
|
||||
PAM_KWALLET5_LOGIN = /run/user/1000/kwallet5.socket
|
||||
# environment
|
||||
MFLAGS = -pqrR
|
||||
# environment
|
||||
SSH_AUTH_SOCK = /tmp/ssh-XXXXXXpjLt6J/agent.6830
|
||||
# default
|
||||
.SHELLFLAGS := -c
|
||||
# environment
|
||||
XDG_CONFIG_DIRS = /home/bruno/.config/kdedefaults:/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings
|
||||
# automatic
|
||||
+D = $(patsubst %/,%,$(dir $+))
|
||||
# environment
|
||||
XCURSOR_THEME = breeze_cursors
|
||||
# environment
|
||||
XDG_SESSION_DESKTOP = KDE
|
||||
# makefile
|
||||
MAKEFILE_LIST :=
|
||||
# automatic
|
||||
@F = $(notdir $@)
|
||||
# environment
|
||||
ZSH = /home/bruno/.oh-my-zsh
|
||||
# environment
|
||||
VSCODE_VERBOSE_LOGGING = true
|
||||
# environment
|
||||
VSCODE_PID = 6725
|
||||
# environment
|
||||
XDG_SESSION_TYPE = x11
|
||||
# automatic
|
||||
?D = $(patsubst %/,%,$(dir $?))
|
||||
# environment
|
||||
SESSION_MANAGER = local/bruno-ThinkPad-T460s:@/tmp/.ICE-unix/3297,unix/bruno-ThinkPad-T460s:/tmp/.ICE-unix/3297
|
||||
# environment
|
||||
PROMPT_EOL_MARK =
|
||||
# automatic
|
||||
*F = $(notdir $*)
|
||||
# environment
|
||||
CHROME_DESKTOP = code-insiders-url-handler.desktop
|
||||
# environment
|
||||
DBUS_SESSION_BUS_ADDRESS = unix:path=/run/user/1000/bus
|
||||
# automatic
|
||||
<D = $(patsubst %/,%,$(dir $<))
|
||||
# environment
|
||||
VSCODE_NLS_CONFIG = {"locale":"en-us","availableLanguages":{},"_languagePackSupport":true}
|
||||
# default
|
||||
MAKE_HOST := x86_64-pc-linux-gnu
|
||||
# makefile
|
||||
SHELL = /bin/sh
|
||||
# environment
|
||||
LESS_TERMCAP_us = [1;32m
|
||||
# default
|
||||
MAKECMDGOALS := all
|
||||
# environment
|
||||
XMODIFIERS = @im=ibus
|
||||
# environment
|
||||
SHLVL = 0
|
||||
# environment
|
||||
MAKELEVEL := 0
|
||||
# default
|
||||
MAKE = $(MAKE_COMMAND)
|
||||
# environment
|
||||
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bruno/golang:/home/bruno/golang/bin:/usr/local/opt/go/libexec/bin
|
||||
# environment
|
||||
LESS_TERMCAP_se = [0m
|
||||
# default
|
||||
MAKEFILES :=
|
||||
# environment
|
||||
LC_MONETARY = sk_SK.UTF-8
|
||||
# automatic
|
||||
^F = $(notdir $^)
|
||||
# environment
|
||||
LC_TIME = sk_SK.UTF-8
|
||||
# environment
|
||||
LESS_TERMCAP_mb = [1;31m
|
||||
# environment
|
||||
GOBIN = /home/bruno/golang/bin
|
||||
# environment
|
||||
GOROOT = /usr/local/opt/go/libexec
|
||||
# environment
|
||||
VSCODE_LOG_NATIVE = false
|
||||
# environment
|
||||
LC_TELEPHONE = sk_SK.UTF-8
|
||||
# automatic
|
||||
?F = $(notdir $?)
|
||||
# environment
|
||||
KDE_APPLICATIONS_AS_SCOPE = 1
|
||||
# environment
|
||||
XDG_SEAT = seat0
|
||||
# environment
|
||||
GTK_IM_MODULE = ibus
|
||||
# environment
|
||||
XDG_CURRENT_DESKTOP = KDE
|
||||
# environment
|
||||
LS_COLORS =
|
||||
# automatic
|
||||
+F = $(notdir $+)
|
||||
# environment
|
||||
XDG_SEAT_PATH = /org/freedesktop/DisplayManager/Seat0
|
||||
# environment
|
||||
LESS = -R
|
||||
# environment
|
||||
DESKTOP_SESSION = plasma
|
||||
# environment
|
||||
ORIGINAL_XDG_CURRENT_DESKTOP = KDE
|
||||
# 'override' directive
|
||||
GNUMAKEFLAGS :=
|
||||
# environment
|
||||
CLUTTER_IM_MODULE = ibus
|
||||
# environment
|
||||
LOGNAME = bruno
|
||||
# environment
|
||||
XDG_VTNR = 1
|
||||
# makefile
|
||||
.DEFAULT_GOAL :=
|
||||
# environment
|
||||
SYSTEMD_EXEC_PID = 3009
|
||||
# environment
|
||||
DISPLAY = :0
|
||||
# environment
|
||||
USER = bruno
|
||||
# environment
|
||||
DEFAULTS_PATH = /usr/share/gconf/plasma.default.path
|
||||
# environment
|
||||
KDE_SESSION_UID = 1000
|
||||
# default
|
||||
MAKE_VERSION := 4.3
|
||||
# environment
|
||||
LC_MEASUREMENT = sk_SK.UTF-8
|
||||
# environment
|
||||
SSH_AGENT_PID = 6832
|
||||
# environment
|
||||
PAGER = less
|
||||
# environment
|
||||
_ = /usr/share/code-insiders/code-insiders
|
||||
# environment
|
||||
LC_PAPER = sk_SK.UTF-8
|
||||
# environment
|
||||
XDG_RUNTIME_DIR = /run/user/1000
|
||||
# environment
|
||||
GPG_AGENT_INFO = /run/user/1000/gnupg/S.gpg-agent:0:1
|
||||
# environment
|
||||
XDG_SESSION_CLASS = user
|
||||
# environment
|
||||
VSCODE_AMD_ENTRYPOINT = vs/workbench/api/node/extensionHostProcess
|
||||
# environment
|
||||
GTK2_RC_FILES = /etc/gtk-2.0/gtkrc:/home/bruno/.gtkrc-2.0:/home/bruno/.config/gtkrc-2.0
|
||||
# environment
|
||||
HOME = /home/bruno
|
||||
# environment
|
||||
QT_IM_MODULE = ibus
|
||||
# environment
|
||||
ELECTRON_RUN_AS_NODE = 1
|
||||
# environment
|
||||
VSCODE_IPC_HOOK = /run/user/1000/vscode-a4ae162a-1.68.0-insider-main.sock
|
||||
# environment
|
||||
XDG_SESSION_ID = 4
|
||||
# environment
|
||||
XCURSOR_SIZE = 24
|
||||
# environment
|
||||
IM_CONFIG_PHASE = 1
|
||||
# default
|
||||
.RECIPEPREFIX :=
|
||||
# automatic
|
||||
<F = $(notdir $<)
|
||||
# default
|
||||
SUFFIXES :=
|
||||
# environment
|
||||
QT_AUTO_SCREEN_SCALE_FACTOR = 0
|
||||
# environment
|
||||
KDE_SESSION_VERSION = 5
|
||||
# default
|
||||
.FEATURES := target-specific order-only second-expansion else-if shortest-stem undefine oneshell nocomment grouped-target extra-prereqs archives jobserver output-sync check-symlink load
|
||||
# environment
|
||||
KDE_FULL_SESSION = true
|
||||
# environment
|
||||
LC_IDENTIFICATION = sk_SK.UTF-8
|
||||
# variable set hash-table stats:
|
||||
# Load=127/1024=12%, Rehash=0, Collisions=14/154=9%
|
||||
|
||||
# Pattern-specific Variable Values
|
||||
|
||||
# No pattern-specific variable values.
|
||||
|
||||
# Directories
|
||||
|
||||
# . (device 66311, inode 19668957): 8 files, no impossibilities.
|
||||
|
||||
# 8 files, no impossibilities in 1 directories.
|
||||
|
||||
# Implicit Rules
|
||||
|
||||
# No implicit rules.
|
||||
|
||||
# Files
|
||||
|
||||
# Not a target:
|
||||
Makefile:
|
||||
# Implicit rule search has been done.
|
||||
# File does not exist.
|
||||
# File has been updated.
|
||||
# Failed to be updated.
|
||||
|
||||
# Not a target:
|
||||
.DEFAULT:
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
|
||||
# Not a target:
|
||||
all:
|
||||
# Command line target.
|
||||
# Implicit rule search has been done.
|
||||
# File does not exist.
|
||||
# File has not been updated.
|
||||
|
||||
|
||||
|
||||
# Not a target:
|
||||
makefile:
|
||||
# Implicit rule search has been done.
|
||||
# File does not exist.
|
||||
# File has been updated.
|
||||
# Failed to be updated.
|
||||
|
||||
# Not a target:
|
||||
GNUmakefile:
|
||||
# Implicit rule search has been done.
|
||||
# File does not exist.
|
||||
# File has been updated.
|
||||
# Failed to be updated.
|
||||
|
||||
# files hash-table stats:
|
||||
# Load=6/1024=1%, Rehash=0, Collisions=0/15=0%
|
||||
# VPATH Search Paths
|
||||
|
||||
# No 'vpath' search paths.
|
||||
|
||||
# No general ('VPATH' variable) search path.
|
||||
|
||||
# strcache buffers: 1 (0) / strings = 16 / storage = 134 B / avg = 8 B
|
||||
# current buf: size = 8162 B / used = 134 B / count = 16 / avg = 8 B
|
||||
|
||||
# strcache performance: lookups = 19 / hit rate = 15%
|
||||
# hash-table stats:
|
||||
# Load=16/8192=0%, Rehash=0, Collisions=0/19=0%
|
||||
# Finished Make data base on Sun May 29 07:50:20 2022
|
||||
|
||||
|
BIN
.vscode/tasks
vendored
Executable file
BIN
.vscode/tasks
vendored
Executable file
Binary file not shown.
38
.vscode/tasks.json
vendored
Normal file
38
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "Clean",
|
||||
"command": "rm -f ${fileDirname}/out"
|
||||
},
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "Builder",
|
||||
"dependsOn": [
|
||||
"Clean"
|
||||
],
|
||||
"command": "/usr/bin/gcc",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${workspaceFolder}/main.c",
|
||||
"-o",
|
||||
//include ncurses
|
||||
"${fileDirname}/${fileBasenameNoExtension}",
|
||||
"-lncurses"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
BIN
main
Executable file
BIN
main
Executable file
Binary file not shown.
317
main.c
Normal file
317
main.c
Normal file
@ -0,0 +1,317 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <ncurses.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
uint16_t Hole_Div = 40;
|
||||
uint16_t SCR_X;
|
||||
uint16_t SCR_Y;
|
||||
#define FPS (60)
|
||||
char blank_char = 32;
|
||||
char wall_char = 35;
|
||||
char goal_char = 71;
|
||||
char player_char = 80;
|
||||
char bullet_char = 120;
|
||||
char inchar = ' ';
|
||||
uint16_t blank_color = 0;
|
||||
uint16_t wall_color = 1;
|
||||
uint16_t goal_color = 2;
|
||||
uint16_t player_color = 3;
|
||||
uint16_t border_color = 4;
|
||||
uint16_t bullet1_color = 5;
|
||||
uint16_t bullet2_color = 5;
|
||||
char letter = ' ';
|
||||
struct Object {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
char letter;
|
||||
uint16_t color;
|
||||
uint8_t dir;
|
||||
};
|
||||
struct Bullet {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
uint8_t dir;
|
||||
uint8_t color;
|
||||
};
|
||||
uint16_t bulletptr = 0;
|
||||
uint16_t player_x = 0;
|
||||
uint16_t player_y = 0;
|
||||
uint16_t goal_x = 0;
|
||||
uint16_t goal_y = 0;
|
||||
uint16_t rng_tmp = 0;
|
||||
uint16_t orient = 0;
|
||||
uint16_t inputs_tmp = 0;
|
||||
|
||||
struct Object *rendered;
|
||||
struct Bullet *bullets;
|
||||
char *playfield;
|
||||
|
||||
|
||||
int randomInt(int lower, int upper) {
|
||||
return rand() % (upper - lower + 1) + lower;
|
||||
}
|
||||
|
||||
void generate_maze(){
|
||||
//fill playfield with blank
|
||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||
//playfield[y][x] = blank_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + x] = blank_char;
|
||||
}
|
||||
}
|
||||
//fill every other row with walls
|
||||
for (uint16_t y = 0; y < SCR_Y; y += 2) {
|
||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||
//playfield[y][x] = wall_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + x] = wall_char;
|
||||
}
|
||||
}
|
||||
//punch holes in the walls
|
||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||
//punch holes in the walls depending on the SCR_X
|
||||
for (uint16_t ix = 0; ix < ((SCR_X-(SCR_X%Hole_Div))/Hole_Div); ix += 1) {
|
||||
rng_tmp = randomInt(1, SCR_X);
|
||||
//playfield[y][rng_tmp] = blank_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + rng_tmp] = blank_char;
|
||||
}
|
||||
if (orient == 0) {
|
||||
if(y == 0){
|
||||
//playfield[y][rng_tmp] = goal_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + rng_tmp] = goal_char;
|
||||
goal_x = rng_tmp;
|
||||
goal_y = y;
|
||||
}
|
||||
if (y == SCR_Y -1){
|
||||
//playfield[y][rng_tmp] = player_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + rng_tmp] = player_char;
|
||||
player_x = rng_tmp;
|
||||
player_y = y;
|
||||
}
|
||||
} else {
|
||||
if(y == SCR_Y -1){
|
||||
//playfield[y][rng_tmp] = goal_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + rng_tmp] = goal_char;
|
||||
goal_x = rng_tmp;
|
||||
goal_y = y;
|
||||
}
|
||||
if (y == 0){
|
||||
//playfield[y][rng_tmp] = player_char;
|
||||
//do it in one dimension
|
||||
playfield[y*SCR_X + rng_tmp] = player_char;
|
||||
player_x = rng_tmp;
|
||||
player_y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void render_maze(){
|
||||
//fill rendered with blank
|
||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||
//rendered[y][x] = blank_char;
|
||||
//do it in one dimension
|
||||
rendered[y*SCR_X + x].letter = blank_char;
|
||||
rendered[y*SCR_X + x].color = blank_color;
|
||||
rendered[y*SCR_X + x].x = x;
|
||||
rendered[y*SCR_X + x].y = y;
|
||||
}
|
||||
}
|
||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||
//letter = playfield[y - 1][x- 1];
|
||||
//do it in one dimension
|
||||
letter = playfield[(y)*SCR_X + (x)];
|
||||
//rendered[x][y].letter = letter;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].letter = letter;
|
||||
//rendered[x][y].x = x;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].x = x;
|
||||
//rendered[x][y].y = y;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].y = y;
|
||||
if (letter == goal_char){
|
||||
//rendered[x][y].color = goal_color;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].color = goal_color;
|
||||
}
|
||||
else if (letter == player_char){
|
||||
//rendered[x][y].color = player_color;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].color = player_color;
|
||||
}
|
||||
else if (letter == blank_char){
|
||||
//rendered[x][y].color = blank_color;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].color = blank_color;
|
||||
}
|
||||
else if (letter == wall_char){
|
||||
//rendered[x][y].color = wall_color;
|
||||
//do it in one dimension
|
||||
rendered[(y)*SCR_X + (x)].color = wall_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_maze(){
|
||||
//FILE *fp;
|
||||
//fp = fopen("logx", "w");
|
||||
for (uint16_t y = 0; y < SCR_Y; y++) {
|
||||
for (uint16_t x = 0; x < SCR_X; x++) {
|
||||
//attron(COLOR_PAIR(rendered[x][y].color));
|
||||
//do it in one dimension
|
||||
attron(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
||||
//mvaddch(y, x, rendered[x][y].letter);
|
||||
//do it in one dimension
|
||||
mvaddch(y, x, rendered[(y)*SCR_X + (x)].letter);
|
||||
//fprintf(fp, "%c, x:%d y:%d\n", rendered[(y)*SCR_X + (x)].letter, rendered[(y)*SCR_X + (x)].x, rendered[(y)*SCR_X + (x)].y);
|
||||
//attroff(COLOR_PAIR(rendered[x][y].color));
|
||||
//do it in one dimension
|
||||
attroff(COLOR_PAIR(rendered[(y)*SCR_X + (x)].color));
|
||||
}
|
||||
}
|
||||
//fclose(fp);
|
||||
refresh();
|
||||
}
|
||||
|
||||
void init(){
|
||||
initscr();
|
||||
//get screen size
|
||||
getmaxyx(stdscr, SCR_Y, SCR_X);
|
||||
playfield = malloc(sizeof(char) * SCR_Y * SCR_X);
|
||||
rendered = malloc(sizeof(struct Object) * (SCR_X) * (SCR_Y));
|
||||
bullets = malloc(sizeof(struct Bullet) * (SCR_X) * (SCR_Y));
|
||||
noecho();
|
||||
nodelay(stdscr, TRUE);
|
||||
start_color();
|
||||
init_pair(blank_color, COLOR_WHITE, COLOR_WHITE);
|
||||
init_pair(wall_color, COLOR_BLACK, COLOR_RED);
|
||||
init_pair(goal_color, COLOR_BLACK, COLOR_GREEN);
|
||||
init_pair(player_color, COLOR_BLACK, COLOR_YELLOW);
|
||||
init_pair(border_color, COLOR_WHITE, COLOR_BLUE);
|
||||
init_pair(bullet1_color, COLOR_BLACK, COLOR_YELLOW);
|
||||
init_pair(bullet2_color, COLOR_BLACK, COLOR_GREEN);
|
||||
attron(COLOR_PAIR(blank_color));
|
||||
clear();
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
int keyinput(){
|
||||
inchar = getch();
|
||||
if (inchar == 'q'){
|
||||
return 1;
|
||||
}
|
||||
if (inchar == 'w'){
|
||||
//if (playfield[player_y - 1][player_x] == blank_char){
|
||||
if (player_y > 0&&playfield[(player_y-1)*SCR_X + player_x] == blank_char){
|
||||
//playfield[player_y][player_x] = blank_char;
|
||||
//do it in one dimension
|
||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||
player_y--;
|
||||
//playfield[player_y][player_x] = player_char;
|
||||
//do it in one dimension
|
||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||
//}else if (playfield[player_y - 1][player_x] == goal_char){
|
||||
}else if (playfield[(player_y-1)*SCR_X + player_x] == goal_char){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (inchar == 'a'){
|
||||
//if (playfield[player_y][player_x - 1] == blank_char){
|
||||
if (player_x > 0 &&playfield[(player_y)*SCR_X + (player_x-1)] == blank_char){
|
||||
//playfield[player_y][player_x] = blank_char;
|
||||
//do it in one dimension
|
||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||
player_x--;
|
||||
//playfield[player_y][player_x] = player_char;
|
||||
//do it in one dimension
|
||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||
}
|
||||
//else if (playfield[player_y][player_x - 1] == goal_char){
|
||||
else if (playfield[(player_y)*SCR_X + (player_x-1)] == goal_char){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (inchar == 's'){
|
||||
//if (playfield[player_y + 1][player_x] == blank_char){
|
||||
if (player_x < SCR_X - 1 &&playfield[(player_y+1)*SCR_X + player_x] == blank_char){
|
||||
// playfield[player_y][player_x] = blank_char;
|
||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||
player_y++;
|
||||
// playfield[player_y][player_x] = player_char;
|
||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||
// }else if (playfield[player_y + 1][player_x] == goal_char){
|
||||
}else if (playfield[(player_y+1)*SCR_X + player_x] == goal_char){
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
if (inchar == 'd'){
|
||||
// if (playfield[player_y][player_x + 1] == blank_char){
|
||||
if (player_x < SCR_X - 1 &&playfield[(player_y)*SCR_X + (player_x+1)] == blank_char){
|
||||
//playfield[player_y][player_x] = blank_char;
|
||||
playfield[(player_y)*SCR_X + player_x] = blank_char;
|
||||
player_x++;
|
||||
//playfield[player_y][player_x] = player_char;
|
||||
playfield[(player_y)*SCR_X + player_x] = player_char;
|
||||
}
|
||||
//else if (playfield[player_y][player_x + 1] == goal_char){
|
||||
else if (playfield[(player_y)*SCR_X + (player_x+1)] == goal_char){
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
init();
|
||||
//parse the command line arguments for width and height
|
||||
if (argc == 3){
|
||||
SCR_X = atoi(argv[1]);
|
||||
SCR_Y = atoi(argv[2]);
|
||||
}
|
||||
if (argc == 2){
|
||||
Hole_Div = atoi(argv[1]);
|
||||
}
|
||||
if (argc == 4){
|
||||
SCR_X = atoi(argv[1]);
|
||||
SCR_Y = atoi(argv[2]);
|
||||
Hole_Div = atoi(argv[3]);
|
||||
}
|
||||
generate_maze();
|
||||
render_maze();
|
||||
draw_maze();
|
||||
while (1)
|
||||
{
|
||||
inputs_tmp = keyinput();
|
||||
if (inputs_tmp == 1){
|
||||
break;
|
||||
}
|
||||
if (inputs_tmp == 2){
|
||||
if (orient == 0){
|
||||
orient = 1;
|
||||
} else {
|
||||
orient = 0;
|
||||
}
|
||||
generate_maze();
|
||||
}
|
||||
render_maze();
|
||||
draw_maze();
|
||||
usleep(round(1000000/FPS));
|
||||
}
|
||||
endwin();
|
||||
free(playfield);
|
||||
free(rendered);
|
||||
return 0;
|
||||
}
|
211
main.c.old
Normal file
211
main.c.old
Normal file
@ -0,0 +1,211 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#define SCR_X 80
|
||||
#define SCR_Y 80
|
||||
|
||||
char inchar = ' ';
|
||||
char readchar(uint8_t x, uint8_t y);
|
||||
void applybuffer();
|
||||
void cls();
|
||||
void setchar(uint8_t x, uint8_t y, char letter);
|
||||
int rng(int lower, int upper);
|
||||
void generate_maze();
|
||||
int up();
|
||||
void down();
|
||||
void left();
|
||||
void right();
|
||||
void keyinput();
|
||||
void init();
|
||||
|
||||
char scrbuf[SCR_X + 1];
|
||||
|
||||
struct Object {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
char letter;
|
||||
};
|
||||
|
||||
struct Game {
|
||||
uint16_t level;
|
||||
char blank;
|
||||
char wall;
|
||||
uint8_t cols;
|
||||
uint8_t rows;
|
||||
char screen[SCR_X + 1][SCR_Y];
|
||||
};
|
||||
|
||||
struct Game game = {.level = 0, .blank = ' ', .wall = '|'};
|
||||
struct Object player = {.x = 0, .y = 0, .letter = 'P'};
|
||||
struct Object goal = {.x = 0, .y = 0, .letter = 'P'};
|
||||
|
||||
/* void applybuffer(){
|
||||
for (uint8_t y = 0;y<SCR_Y;y+=1){
|
||||
for (uint8_t x = 0;x<SCR_X;x+=1){
|
||||
scrbuf[x] = game.screen[x][y];
|
||||
}
|
||||
printf("%.*s\n", (int)sizeof(scrbuf), scrbuf);
|
||||
}
|
||||
} */
|
||||
|
||||
void applybuffer(){
|
||||
for (uint8_t y = 0;y<SCR_Y;y+=1){
|
||||
for (uint8_t x = 0;x<SCR_X;x+=1){
|
||||
scrbuf[x] = game.screen[x][y];
|
||||
}
|
||||
mvprintw(y, 0, "%.*s", (int)sizeof(scrbuf), scrbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void cls(){
|
||||
for (uint8_t x = 0;x<SCR_X;x+=1){
|
||||
for (uint8_t y = 0;y<SCR_Y;y+=1){
|
||||
game.screen[x][y] = game.blank;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char readchar(uint8_t x, uint8_t y){
|
||||
return game.screen[x][y];
|
||||
}
|
||||
|
||||
void setchar(uint8_t x, uint8_t y, char letter){
|
||||
game.screen[x][y] = letter;
|
||||
}
|
||||
|
||||
int rng(int lower, int upper){
|
||||
int num = (rand() % (upper - lower + 1)) + lower;
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
void generate_maze(){
|
||||
cls();
|
||||
for (int y = 0;y<SCR_Y;y++){
|
||||
if (y%2 == 0){
|
||||
for(int x = 0;x<SCR_X;x++){
|
||||
setchar(x,y,game.wall);
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(int x = 0;x<SCR_X;x++){
|
||||
setchar(x,y,game.blank);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y = 0;y<SCR_Y;y++){
|
||||
int xrnd = rng(0,SCR_X);
|
||||
setchar(xrnd,y,game.blank);
|
||||
}
|
||||
player.y = SCR_Y - 2;
|
||||
if (SCR_Y%2 == 0){
|
||||
for(int x = 0;x<SCR_X;x++){
|
||||
if (readchar(SCR_Y,x) == game.blank){
|
||||
player.x = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
setchar(player.x,player.y,player.letter);
|
||||
|
||||
|
||||
goal.y = 0;
|
||||
int px = 0;
|
||||
for(int x = 0;x<SCR_X;x++){
|
||||
if (readchar(0,x) == game.blank){
|
||||
goal.x = x;
|
||||
}
|
||||
}
|
||||
setchar(goal.x,goal.y,goal.letter);
|
||||
}
|
||||
|
||||
|
||||
int up(){
|
||||
if (player.y != 0){
|
||||
char charat = readchar(player.y-1,player.x);
|
||||
if (charat == game.blank){
|
||||
setchar(player.x,player.y--,game.blank);
|
||||
setchar(player.x,player.y,player.letter);
|
||||
return 0;
|
||||
}
|
||||
if (charat == goal.letter){
|
||||
setchar(player.x,player.y--,game.blank);
|
||||
setchar(player.x,player.y,player.letter);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void down(){
|
||||
if (player.y != SCR_Y){
|
||||
char charat = readchar(player.y+1,player.x);
|
||||
if (charat == game.blank){
|
||||
setchar(player.x,player.y++,game.blank);
|
||||
setchar(player.x,player.y,player.letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void left(){
|
||||
if (player.x != 0){
|
||||
char charat = readchar(player.x,player.y-1);
|
||||
if (charat == game.blank){
|
||||
setchar(player.x,player.y--,game.blank);
|
||||
setchar(player.x,player.y,player.letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void right(){
|
||||
if (player.x != SCR_X){
|
||||
char charat = readchar(player.x,player.y+1);
|
||||
if (charat == game.blank){
|
||||
setchar(player.x,player.y++,game.blank);
|
||||
setchar(player.x,player.y,player.letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyinput(){
|
||||
while (1){
|
||||
inchar = getchar();
|
||||
if (inchar == 'w'){
|
||||
if (up() == 1){
|
||||
generate_maze();
|
||||
game.level += 1;
|
||||
}
|
||||
applybuffer();
|
||||
}
|
||||
else if (inchar == 's'){
|
||||
down();
|
||||
applybuffer();
|
||||
}
|
||||
else if (inchar == 'a'){
|
||||
left();
|
||||
applybuffer();
|
||||
}
|
||||
else if (inchar == 'd'){
|
||||
right();
|
||||
applybuffer();
|
||||
}
|
||||
else if (inchar == 27){
|
||||
printf("Level: %d", game.level);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init(){
|
||||
srand(time(0));
|
||||
initscr();
|
||||
generate_maze();
|
||||
}
|
||||
|
||||
int main(void){
|
||||
init();
|
||||
keyinput();
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user