Skip to content
Permalink
Browse files

Quiz Game Doom mod code

  • Loading branch information...
yourWaifu committed Sep 9, 2019
1 parent 44f4984 commit 130f90faac1871c4dd9d47a8f9264ede5fed4bca
@@ -0,0 +1,178 @@
#include <stdint.h>
#include <math.h>
#include "math_question.h"
#include "doomstat.h"
#include "m_controls.h"
#include "sounds.h"

//note to self
//images are structed. or maybe the whole game is streched
//from 59 to 141.??
//just muiltply the height by 5/6 (.833333333)
//max width is 320
//max height is 168
//max line length is 43

char questionString[256];
uint8_t questionNum;

typedef struct {
const char * question;
const char * answers[4];
const char answer;
const char image[8];
} MultipleChoiceQuestion;

const MultipleChoiceQuestion questions[] = {
{ "What are supplementary angles?",
{ "an angle whose sum is greater than 180\ndegrees",
"either of two angles whose sum is 180\ndegrees",
"Angles that add up to 180 degrees",
"two angles that add up to be 360 degrees" },
KEY_ANSWERC, "AMMNUM0" },

{ "What are the corresponding angles in this\npicture?",
{ "1&2, 3&4, 5&6, 7&8", "1&4, 2&3, 5&8, 6&7", "1&3, 2&4, 5&7, 6&8", "1&5, 3&7, 2&6, 4&8" },
KEY_ANSWERD, "MATH_Q3" },

{ "What are the alternate interior angles in\nthis picture?",
{ "3&4, 5&6", "3&6, 4&5", "4&6, 3&5", "7&2, 8&1" },
KEY_ANSWERB, "MATH_Q3" },

{ "What other angles measure 110?",
{ "<1, <4, <8", "<7, <8, <6", "<3, <4, <6", "<7, <3, <1" },
KEY_ANSWERA, "MATH_Q3" },

{ "find x and y",
{ "x= 75 y= 55", "x= 55 y= 70", "x= 70 y= 55", "x= 55 y= 75"},
KEY_ANSWERA, "MATH_Q5" },

{ "find x and y",
{ "x= 80, y= 80", "x= 100, y= 80", "x= 80, y= 100", "x= 100, y= 100" },
KEY_ANSWERA, "MATH_Q6" },

{ "Which of these are corresponding angles\n\n\n\n",
{ "<1 and <7, <2 and <3", "<8 and <3, <1 and <7\n\n\n\n\n", "<5 and <6, <4 and <3", "<5 and <9, <4 and <7\n\n\n" },
KEY_ANSWERB, "MATH_Q7" },

{ "Which of these are alternate interior angles\n\n\n\n",
{ "<1 and <4, <2 and <6", "<9 and <8, <4 and <7\n\n\n\n\n", "<4 and <7, <5 and <8", "<8 and <9, <4 and <1\n\n\n" },
KEY_ANSWERC, "MATH_Q7" },

{ "Which of these are Same-side interior angles\n\n\n\n",
{ "<6 and <8", "<4 and <7\n\n\n\n\n", "<5 and <9", "<8 and <9\n\n\n" },
KEY_ANSWERA, "MATH_Q7" },

{ "what is the slope of line b?",
{ "4/5", "-4/-5", "-4/5", "5/-4" },
KEY_ANSWERC, "MATH_Q10" },

{ "Determine the value of x for which a II b",
{ "35", "56", "112", "53" },
KEY_ANSWERD, "MATH_Q11" },

{ "Find each missing angle measure.",
{ "3y= -120, (y-15)= -25", "3y = 120, (y-15) = 25", "3y= 120, (y-15)= -25", "3y= -120, (y-15)= 25" },
KEY_ANSWERB, "MATH_Q12" },

{ "determine whether statement is\nalways, sometimes, or never.\nPerpendicular lines meet at the right angle.",
{ "sometimes", "never", "always", "I don't know" },
KEY_ANSWERC, "AMMNUM0" },

{ "Which theorem or postulate is this?\nIf a transversal intersects two parallel\nlines, then the same-side interior angles are\nsupplementary.",
{ "alternate interior angles theorem",
"corresponding angle theorem",
"same-side interior angles postulate",
"alternate exterior angles theorem" },
KEY_ANSWERC, "AMMNUM0" },

{ "Which theorem or postulate is this?\nif a transversal intersects two parallel\nlines, then corresponding angles are\ncongruent.",
{ "alternate interior angles theorem",
"corresponding angle theorem",
"same-side interior angles postulate",
"alternate exterior angles theorem" },
KEY_ANSWERB, "AMMNUM0" },

{ "Which theorem or postulate is this?\nif a transversal intersects two parallel\nlines, then alternate interior angle are\ncongruent",
{ "alternate interior angles theorem",
"corresponding angle theorem",
"same-side interior angles postulate",
"alternate exterior angles theorem" },
KEY_ANSWERA, "AMMNUM0" },
};

const unsigned int numOfQuestion = sizeof(questions) / sizeof(MultipleChoiceQuestion);

mobj_t* storedTarget;
mobj_t* storedInflictor;
mobj_t* storedSource;
int storedDamage;

void
AnswerQuestion
(int key) {
static int numOfRightAnswers = 0;
int* keybind;
switch (key) {
case KEY_ANSWERA: keybind = &key_math_answerA; break;
case KEY_ANSWERB: keybind = &key_math_answerB; break;
case KEY_ANSWERC: keybind = &key_math_answerC; break;
case KEY_ANSWERD: keybind = &key_math_answerD; break;
default: return;
}
if (questions[questionNum].answer == *keybind) {
//reset controls
key_math_answerA = KEY_ANSWERA;
key_math_answerB = KEY_ANSWERB;
key_math_answerC = KEY_ANSWERC;
key_math_answerD = KEY_ANSWERD;
players[0].message = "good";
if (numOfQuestion <= ++questionNum) {
players[0].message = "You've answered all questions. good job";
S_StartSound(players[0].mo, sfx_perf);
}
players[0].didAnswerQuestion = true;
P_GiveBody(players, storedDamage);
numOfRightAnswers = numOfRightAnswers < 0 ? 1 : numOfRightAnswers + 1;
if (numOfRightAnswers == 5) S_StartSound(players[0].mo, sfx_hanzo);
} else {
*keybind = -1;
players[0].message = "wrong";

players[0].didAnswerQuestion = true;
numOfRightAnswers = 0 < numOfRightAnswers ? -1 : numOfRightAnswers - 1;
P_DamageMobj(storedTarget, storedInflictor, storedSource, (int)(storedDamage*pow(2.8, (numOfRightAnswers * -1) - 1)));
}
players[0].didAnswerQuestion = false;
}

void
askQuestion
( mobj_t* target,
mobj_t* inflictor,
mobj_t* source,
int damage)
{
storedTarget = target;
storedInflictor = inflictor;
storedSource = source;
storedDamage = damage;
if (numOfQuestion <= questionNum) return;
DEH_snprintf(questionString, sizeof(questionString), "%s\n\nQ. %s\nW. %s\nR. %s\nT. %s",
questions[questionNum].question, questions[questionNum].answers[0],
questions[questionNum].answers[1], questions[questionNum].answers[2],
questions[questionNum].answers[3]);
M_StartMessage(questionString, AnswerQuestion, true);
}

const char * getQuestionImage
( const uint8_t quesitonNumber)
{
return questionNum < numOfQuestion ? questions[questionNum].image : "AMMNUM0";
}

const uint8_t
getQuestionNum()
{
return questionNum;
}
@@ -0,0 +1,33 @@
#pragma once
#include "p_mobj.h"
#define KEY_ANSWERA 'q'
#define KEY_ANSWERB 'w'
#define KEY_ANSWERC 'r'
#define KEY_ANSWERD 't'

//
//answer question
//
void
AnswerQuestion(
int key
);

void
askQuestion
( mobj_t* target,
mobj_t* inflictor,
mobj_t* source,
int damage
);

const char *
getQuestionImage
(
const uint8_t questionNumber
);

const uint8_t
getQuestionNum
(
);
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -157,7 +157,9 @@ typedef struct player_s

// True if secret level has been done.
boolean didsecret;


//doing math
boolean didAnswerQuestion;
} player_t;


@@ -1091,6 +1091,7 @@ void G_PlayerReborn (int player)
players[player].killcount = killcount;
players[player].itemcount = itemcount;
players[player].secretcount = secretcount;
players[player].didAnswerQuestion = false;

p->usedown = p->attackdown = true; // don't do anything immediately
p->playerstate = PST_LIVE;
@@ -59,7 +59,6 @@

#include "m_menu.h"


extern patch_t* hu_font[HU_FONTSIZE];
extern boolean message_dontfuckwithme;

@@ -1620,8 +1619,9 @@ boolean M_Responder (event_t* ev)
{
if (messageNeedsInput)
{
if (key != ' ' && key != KEY_ESCAPE
&& key != key_menu_confirm && key != key_menu_abort)
if (key != KEY_ESCAPE
&& key != key_menu_confirm && key != key_menu_abort
&& key != key_math_answerA && key != key_math_answerB && key != key_math_answerC && key != key_math_answerD)
{
return false;
}
@@ -1955,6 +1955,10 @@ void M_Drawer (void)
// Horiz. & Vertically center string and print it.
if (messageToPrint)
{

V_DrawPatchDirect(0, 0,
W_CacheLumpName(DEH_String(getQuestionImage(getQuestionNum())), PU_CACHE));

start = 0;
y = SCREENHEIGHT/2 - M_StringHeight(messageString) / 2;
while (messageString[start] != '\0')
@@ -836,6 +836,13 @@ P_DamageMobj
target->momy += FixedMul (thrust, finesine[ang]);
}

//pause when hit
const boolean didAnswerQuestion = player ? player->didAnswerQuestion : true;
if (!didAnswerQuestion) {
askQuestion(target, inflictor, source, damage);
return;
}

// player specific
if (player)
{
@@ -920,4 +927,3 @@ P_DamageMobj
}

}

@@ -287,7 +287,6 @@ P_DamageMobj
mobj_t* source,
int damage );


//
// P_SPEC
//
@@ -764,6 +764,8 @@ static void saveg_read_player_t(player_t *str)

// boolean didsecret;
str->didsecret = saveg_read32();

str->didAnswerQuestion = false;
}

static void saveg_write_player_t(player_t *str)
@@ -766,7 +766,7 @@ P_SetupLevel
for (i=0 ; i<MAXPLAYERS ; i++)
{
players[i].killcount = players[i].secretcount
= players[i].itemcount = 0;
= players[i].itemcount = players[i].didAnswerQuestion = 0;
}

// Initial height of PointOfView
@@ -225,5 +225,7 @@ sfxinfo_t S_sfx[] =
SOUND("skesit", 70),
SOUND("skeatk", 70),
SOUND("radio", 60),
SOUND("hanzo", 200),
SOUND("perf", 200),
};

@@ -221,6 +221,8 @@ typedef enum
sfx_skesit,
sfx_skeatk,
sfx_radio,
sfx_hanzo,
sfx_perf,
NUMSFX
} sfxenum_t;

@@ -22,6 +22,8 @@
#include "m_config.h"
#include "m_misc.h"

#include "math_question.h"

//
// Keyboard controls
//
@@ -158,6 +160,13 @@ int key_menu_forward = KEY_ENTER;
int key_menu_confirm = 'y';
int key_menu_abort = 'n';


//math
int key_math_answerA = KEY_ANSWERA;
int key_math_answerB = KEY_ANSWERB;
int key_math_answerC = KEY_ANSWERC;
int key_math_answerD = KEY_ANSWERD;

int key_menu_help = KEY_F1;
int key_menu_save = KEY_F2;
int key_menu_load = KEY_F3;
@@ -106,6 +106,12 @@ extern int key_menu_forward;
extern int key_menu_confirm;
extern int key_menu_abort;

//math
int key_math_answerA;
int key_math_answerB;
int key_math_answerC;
int key_math_answerD;

extern int key_menu_help;
extern int key_menu_save;
extern int key_menu_load;

0 comments on commit 130f90f

Please sign in to comment.
You can’t perform that action at this time.