Messages - p3lb0x [ switch to compact view ]

Pages: prev1 ... 5 6 7 8 9 [10] 11 12 13 14 15 ... 84next
46
General Software Discussion / Looking back (Some of your first code)
« on: January 20, 2016, 08:02 PM »
So, I recently stumbled on my first real C project, back from high school. It is pretty bad. And I thought it would be fun to share with you guys and maybe get to see some of the first code you guys did in whatever capacity you can find. I also have code from the first major Lua project I did. Both were written around the same time.

C code:
The below code is for a master microcontroller that calculates game of life and sends the "game" field to another microcontroller that had a charlieplexed 8x7 led display that displayed it. A video of it in action can be found here
comments are translated from danish and I have commented on the comments in parentheses (pastebin link)
Spoiler
#include <htc.h> //PIC hardware mapping
#include <delay.c>
#include <I2CMaster.h>
#include <stdlib.h>
//config bits

__CONFIG(HS & PWRTDIS & WDTDIS & LVPDIS);

/////////// Constants ///////////
#define LEDPLADE8PIN 1 // Defines how many light plates with 8pins that's attached (Not ever actually used, was supposed to be able to handle more than one)

/////////// Bit manipulation functions ///////////

void clear_bit(unsigned char *x, char bitNum){
*x &= ~(1 << bitNum);
}
void set_bit(unsigned char *x, char bitNum) {
*x |= (1 << bitNum);
}
unsigned char get_bit(unsigned char x, char bitNum) {
return x & (1 << bitNum);
}

/////////////// Function prototypes for patterns //////////////////

void glider(void);
void lwss(void);
void toad(void);
void kasse(void);
void blinker(void);
void randompat(void);

/////////// Variables ///////////

////////// GAME OF LIFE ///////////

char LifeGameBuf[2][7];
char LiveCount;
char FirstEvol;
char Pattern;
char NewPattern;

///////////////////////////////////

char i; // Indexes
char j;

char I2C_Address; // Defines the i2c address we want to write to
char I2C_i; // Defines what type of byte we want to send (I don't remember what this is, and it is apparently unused)

/////////// Main program ///////////
void main(void){ // Start

srand(70);

/////////// Opsætning ///////////

/////////// Opsætning af SSP modul ///////////

TRISC = 0b00011000; // Sets port C pin 3 and 4 to be inputs
SSPADD = 39; // Defines the baudrate of the i2c communications
SSPCON = 0b00101000; // Configuration and start of SSP module
SSPCON2 = 0b00000000;
SSPSTAT = 0b11000000;
SSPIE = 1; // Enable interrupt on i2c communication start
SSPIF = 0;

/////////// Setup of interrupts ///////////

PEIE = 1;
GIE = 1; // Global interrupt enable

/////////// GAME OF LIFE ///////////

LiveCount = 0;
Pattern = 0;
NewPattern = 0;

glider();

/////////// Runs in a loop from here (Obviously not) ///////////

/////////// Pattern change ///////////
TRISD = 0b00000010; // Set pins on port D as input and output
while(!0){
PORTD = 0b00001000; // Drive current to RD3 pin
if(RD3 == 0){ // I HAVE NO IDEA WHY THIS WORKS (Basically, the code here sets a pin, then checks if it is set. It worked, I still have no idea why)
Pattern = Pattern + 1;
NewPattern = 1;
DelayMs(255);
}
if(NewPattern){
if(Pattern > 5) Pattern = 0;
if(Pattern == 0) glider();
else if(Pattern == 1) lwss();
else if(Pattern == 2) toad();
else if(Pattern == 3) kasse();
else if(Pattern == 4) blinker();
else if(Pattern == 5) randompat();
NewPattern = 0;
}

//////////////// Blink light to indicate when the next generations of game of life is calculated /////////////////
PORTD = 0;
DelayMs(50);
PORTD = 1;

//////////////// Game of Life /////////////////
if(!FirstEvol){
for(i=0; i<7; i++){
for(j=0; j<8; j++){
if(i == 0){
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][6],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
}
else if(i == 6){
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][0],j-1)) LiveCount = LiveCount + 1;
}
}
else{
if(j == 0){
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],7)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],7)) LiveCount = LiveCount + 1;
}
else if (j == 7){
if(get_bit(LifeGameBuf[0][i],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],0)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
else{
if(get_bit(LifeGameBuf[0][i],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i-1],j-1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j+1)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j)) LiveCount = LiveCount + 1;
if(get_bit(LifeGameBuf[0][i+1],j-1)) LiveCount = LiveCount + 1;
}
}

if(LiveCount < 2){clear_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 2 && get_bit(LifeGameBuf[1][i],j) == 1){set_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 2 && get_bit(LifeGameBuf[1][i],j) == 0){clear_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount == 3){set_bit(&LifeGameBuf[1][i],j);}
else if(LiveCount > 3){clear_bit(&LifeGameBuf[1][i],j);}
LiveCount = 0;

}
}
for(i=0; i<7; i++){
LifeGameBuf[0][i] = LifeGameBuf[1][i];
}
}
FirstEvol = 0; // No longer first generation

////////////// SEND TO DISPLAY /////////////////

i2c_Start();
i2c_Address(15,0);
i2c_Write(LifeGameBuf[0][0]);
i2c_Write(LifeGameBuf[0][1]);
i2c_Write(LifeGameBuf[0][2]);
i2c_Write(LifeGameBuf[0][3]);
i2c_Write(LifeGameBuf[0][4]);
i2c_Write(LifeGameBuf[0][5]);
i2c_Write(LifeGameBuf[0][6]);
i2c_Stop();
}
} // End

static void interrupt isr(void)
{

if(SSPIF){ // Was it a i2c interrupt?
SSPIF = 0; // Clear SSP interrupt flag
}
}

/////////// Game of Life pattern funftions ///////////

void glider() {

LifeGameBuf[0][0] = 0b00100000;
LifeGameBuf[0][1] = 0b10100000;
LifeGameBuf[0][2] = 0b01100000;
LifeGameBuf[0][3] = 0b00000000;
LifeGameBuf[0][4] = 0b00000000;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}


void lwss() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00000000;
LifeGameBuf[0][2] = 0b00110000;
LifeGameBuf[0][3] = 0b11011000;
LifeGameBuf[0][4] = 0b11110000;
LifeGameBuf[0][5] = 0b01100000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void toad() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00000000;
LifeGameBuf[0][2] = 0b00000000;
LifeGameBuf[0][3] = 0b00111000;
LifeGameBuf[0][4] = 0b00011100;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void kasse() {

LifeGameBuf[0][0] = 0b00000000;
LifeGameBuf[0][1] = 0b00110000;
LifeGameBuf[0][2] = 0b01001000;
LifeGameBuf[0][3] = 0b01001000;
LifeGameBuf[0][4] = 0b00110000;
LifeGameBuf[0][5] = 0b00000000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void blinker() {

LifeGameBuf[0][0] = 0b01000000;
LifeGameBuf[0][1] = 0b01000000;
LifeGameBuf[0][2] = 0b01000000;
LifeGameBuf[0][3] = 0b00001000;
LifeGameBuf[0][4] = 0b00001000;
LifeGameBuf[0][5] = 0b00001000;
LifeGameBuf[0][6] = 0b00000000;

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

void randompat() {

LifeGameBuf[0][0] = (char)rand();
LifeGameBuf[0][1] = (char)rand();
LifeGameBuf[0][2] = (char)rand();
LifeGameBuf[0][3] = (char)rand();
LifeGameBuf[0][4] = (char)rand();
LifeGameBuf[0][5] = (char)rand();
LifeGameBuf[0][6] = (char)rand();

LifeGameBuf[1][0] = LifeGameBuf[0][0];
LifeGameBuf[1][1] = LifeGameBuf[0][1];
LifeGameBuf[1][2] = LifeGameBuf[0][2];
LifeGameBuf[1][3] = LifeGameBuf[0][3];
LifeGameBuf[1][4] = LifeGameBuf[0][4];
LifeGameBuf[1][5] = LifeGameBuf[0][5];
LifeGameBuf[1][6] = LifeGameBuf[0][6];

FirstEvol = 1;
}

Fun things:
while(!0)
The "I HAVE NO IDEA WHY THIS WORKS" comment

Lua code:
The below code is for a randomized gun generation thing for the game Cortex Command, a video of which can be found here. If I recall correctly, it was also my first NANY.
removed a few new lines, otherwise did nothing (pastebin link)
Spoiler
function Create(self)

-- Initialize variables and timers

self.smgbodylist = {};
self.smgbarrellist = {};
self.smgmaglist = {};
self.smgbulletlist = {};
self.smgsoundlist = {};
self.smgsoundlist["fire"] = {};
self.smgsoundlist["reload"] = {};
self.smgmuzzlelist = {};

self.projectileteam = -1;
self.allmodulesfound = false;
self.ammocounter = 0;
self.reloading = false;

self.Body = {};
self.Mag = {};
self.Barrel = {};
self.Bullet = {};
self.FireSound = nil;
self.ReloadSound = nil;
self.MuzzleFlash = nil;

self.firingtimer = Timer();

-- Initial stats
-- Basic stats
self.rateoffire = 700;
self.ammocapacity = 20;
self.accuracy = 25;

-- Initial modifiers
self.rofmod = 0.8 + math.random()*0.4;
self.magmod = 0.8 + math.random()*0.4;
self.accmod = 0.8 + math.random()*0.4;
self.firevelmod = 0.8 + math.random()*0.4;
self.massmod = 0.8 + math.random()*0.4;
self.sharpnessmod = 0.8 + math.random()*0.4;

-- Load body modules
dofile("Brolands.rte/smg/bodymodules.lua");
BrolandsBodies(self);

-- Load barrel modules
dofile("Brolands.rte/smg/barrelmodules.lua");
BrolandsBarrels(self);

-- Load magazines modules
dofile("Brolands.rte/smg/magazinemodules.lua");
BrolandsMagazines(self);

-- Load bullets
dofile("Brolands.rte/smg/bulletmodules.lua");
BrolandsBullets(self);

-- Load muzzleflashes
dofile("Brolands.rte/smg/muzzleflashmodules.lua");
BrolandsMuzzleflashes(self);

-- Load sounds
dofile("Brolands.rte/smg/soundmodules.lua");
BrolandsSounds(self);

end

function Update(self)

-- Generate gun
if self.allmodulesfound ~= true then
-- Find the attachments
for i=1,MovableMan:GetMOIDCount()-1 do
local mo = MovableMan:GetMOFromID(i);
if mo.PresetName == "SmgBody" and mo.RootID == self.RootID then
self.Body["pointer"] = ToAttachable(mo);
self.Body["pointer"].GetsHitByMOs = false;
elseif mo.PresetName == "SmgMag" and mo.RootID == self.RootID then
self.Mag["pointer"] = ToAttachable(mo);
self.Mag["pointer"].GetsHitByMOs = false;
elseif mo.PresetName == "SmgBarrel" and mo.RootID == self.RootID then
self.Barrel["pointer"] = ToAttachable(mo);
self.Barrel["pointer"].GetsHitByMOs = false;
end
if self.Body["pointer"] and self.Mag["pointer"] and self.Barrel["pointer"] then
self.allmodulesfound = true;
break;
end
end

-- Body
for k,v in pairs(self.smgbodylist[math.random(1,#self.smgbodylist)]) do self.Body[k] = v end
-- for k,v in pairs(self.smgbodylist[15]) do self.Body[k] = v end
self.Body["pointer"].Frame = self.Body["sprite"];

-- Modify stat modifier with module modifier
self.rofmod = self.rofmod * self.Body["rofmod"];
self.magmod = self.magmod * self.Body["magmod"];
self.accmod = self.accmod * self.Body["accmod"];
self.firevelmod = self.firevelmod * self.Body["firevelmod"];
self.massmod = self.massmod * self.Body["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Body["sharpnessmod"];

-- Mag
for k,v in pairs(self.smgmaglist[math.random(1,#self.smgmaglist)]) do self.Mag[k] = v end
-- for k,v in pairs(self.smgmaglist[16]) do self.Mag[k] = v end
self.Mag["pointer"].Frame = self.Mag["sprite"];
self.Mag["offset"] = self.Body["magoffset"];

-- Modify stat modifier with module modifier
self.rofmod = self.rofmod * self.Mag["rofmod"];
self.magmod = self.magmod * self.Mag["magmod"];
self.accmod = self.accmod * self.Mag["accmod"];
self.firevelmod = self.firevelmod * self.Mag["firevelmod"];
self.massmod = self.massmod * self.Mag["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Mag["sharpnessmod"];

-- Barrel
for k,v in pairs(self.smgbarrellist[math.random(1,#self.smgbarrellist)]) do self.Barrel[k] = v end
-- for k,v in pairs(self.smgbarrellist[18]) do self.Barrel[k] = v end
self.Barrel["pointer"].Frame = self.Barrel["sprite"];
self.Barrel["offset"] = self.Body["barreloffset"];

-- Modify gun stat modifier with module modifier
self.rofmod = self.rofmod * self.Barrel["rofmod"];
self.magmod = self.magmod * self.Barrel["magmod"];
self.accmod = self.accmod * self.Barrel["accmod"];
self.firevelmod = self.firevelmod * self.Barrel["firevelmod"];
self.massmod = self.massmod * self.Barrel["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Barrel["sharpnessmod"];

-- Bullet
for k,v in pairs(self.smgbulletlist[math.random(1,#self.smgbulletlist)]) do self.Bullet[k] = v end
-- for k,v in pairs(self.smgbulletlist[3]) do self.Bullet[k] = v end

-- Modify gun stat modifier with module modifier
self.rofmod = self.rofmod * self.Bullet["rofmod"];
self.magmod = self.magmod * self.Bullet["magmod"];
self.accmod = self.accmod * self.Bullet["accmod"];
self.firevelmod = self.firevelmod * self.Bullet["firevelmod"];
self.massmod = self.massmod * self.Bullet["massmod"];
self.sharpnessmod = self.sharpnessmod * self.Bullet["sharpnessmod"];

-- Fire sound

self.FireSound = self.smgsoundlist["fire"][self.Bullet["firesounds"][math.random(1,#self.Bullet["firesounds"])]];

-- Reload sound

self.ReloadSound = self.smgsoundlist["reload"][self.Mag["reloadsounds"][math.random(1,#self.Mag["reloadsounds"])]];

-- Muzzle flash

self.MuzzleFlash = self.smgmuzzlelist[self.Bullet["muzzleflash"][math.random(1,#self.Bullet["muzzleflash"])]];

-- Done generating gun, apply gun stat modifiers
self.rateoffire = Round(self.rateoffire * self.rofmod);
self.ammocapacity = Round(self.ammocapacity * self.magmod);

-- You can't be more precise than 100%
if self.accuracy > 100 then
self.accuracy = 100;
else
self.accuracy = Round(self.accuracy * self.accmod);
end

self.Bullet["firevel"] = Round(self.Bullet["firevel"] * self.firevelmod);
self.Bullet["mass"] = self.Bullet["mass"] * self.massmod;
self.Bullet["sharpness"] = Round(self.Bullet["sharpness"] * self.sharpnessmod);


-- Output gun stats to console
-- print("\nRate of fire: "..self.rateoffire.." Rounds Per Minute\nMagazine capacity: "..self.ammocapacity.." Rounds\nAccuracy: "..self.accuracy.."%\nProjectile type: "..self.Bullet["particle"].."\nProjectile mass: "..self.Bullet["mass"].."\nProjectile speed: "..self.Bullet["firevel"].."\nProjectile sharpness: "..self.Bullet["sharpness"].."\n");

self.ammocounter = self.ammocapacity;

-- Clear unneeded tables and variables
self.smgbodylist = nil;
self.smgbarrellist = nil;
self.smgmaglist = nil;
self.smgbulletlist = nil;
self.smgsoundlist = nil;
self.rofmod = nil;
self.magmod = nil;
self.accmod = nil;
self.firevelmod = nil;
self.massmod = nil;
self.sharpnessmod = nil;
end

-- Figure out what team is currently holding the gun
self.projectileteam = MovableMan:GetMOFromID(self.RootID).Team;

-- Move around attachables
if self.Body["pointer"].ToDelete ~= true and self.Body["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X * -1,self.Body["offset"].Y):RadRotate(self.RotAngle);
else
self.Body["pointer"].Pos = self.Pos + Vector(self.Body["offset"].X,self.Body["offset"].Y):RadRotate(self.RotAngle);
end
self.Body["pointer"].RotAngle = self.RotAngle;
self.Body["pointer"].HFlipped = self.HFlipped;
end

if self.Mag["pointer"].ToDelete ~= true and self.Mag["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X * -1,self.Mag["offset"].Y):RadRotate(self.RotAngle);
else
self.Mag["pointer"].Pos = self.Pos + Vector(self.Mag["offset"].X,self.Mag["offset"].Y):RadRotate(self.RotAngle);
end
self.Mag["pointer"].RotAngle = self.RotAngle;
self.Mag["pointer"].HFlipped = self.HFlipped;
end

if self.Barrel["pointer"].ToDelete ~= true and self.Barrel["pointer"].PresetName ~= "" then
if self.HFlipped then
self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X * -1,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
else
self.Barrel["pointer"].Pos = self.Pos + Vector(self.Barrel["offset"].X,self.Barrel["offset"].Y):RadRotate(self.RotAngle);
end
self.Barrel["pointer"].RotAngle = self.RotAngle;
self.Barrel["pointer"].HFlipped = self.HFlipped;
end

if self:IsActivated() and self.firingtimer:IsPastSimMS(60000 / self.rateoffire) and self.ammocounter > 0 and self.Magazine ~= nil then
self.ammocounter = self.ammocounter - 1;
self.firingtimer:Reset()

-- Decide which kind of particle to create depending on the bullets particle type
if self.Bullet["particletype"] == "MOPixel" then
self.particle = CreateMOPixel(self.Bullet["particle"],"Brolands.rte");
elseif self.Bullet["particletype"] == "MOSRotating" then
self.particle = CreateMOSRotating(self.Bullet["particle"],"Brolands.rte");
elseif self.Bullet["particletype"] == "MOSParticle" then
self.particle = CreateMOSParticle(self.Bullet["particle"],"Brolands.rte");
end

-- Decide which kind of particle to create depending on the muzzleflashs particle type
if self.MuzzleFlash["particletype"] == "MOPixel" then
self.particle2 = CreateMOPixel(self.MuzzleFlash["particle"],"Brolands.rte");
elseif self.MuzzleFlash["particletype"] == "MOSRotating" then
self.particle2 = CreateMOSRotating(self.MuzzleFlash["particle"],"Brolands.rte");
elseif self.MuzzleFlash["particletype"] == "MOSParticle" then
self.particle2 = CreateMOSParticle(self.MuzzleFlash["particle"],"Brolands.rte");
end

-- Figure out if the actor is sharpaiming or not.
local MO = MovableMan:GetMOFromID(self.RootID)
local Aiming = 1;
if MO then
local Actor = ToActor(MO)
if Actor:GetController():IsState(Controller.AIM_SHARP) then
Aiming = 0.5;
else
Aiming = 1;
end
end

-- Create a direction vector for the projectile depending on if the gun is HFlipped or not
if self.HFlipped == true then
self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
if math.random() > 0.5 then
self.firingvector = Vector(-1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
else
self.firingvector = Vector(-1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
end
else
self.particle.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
if math.random() > 0.5 then
self.firingvector = Vector(1,0):RadRotate(self.RotAngle + math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
else
self.firingvector = Vector(1,0):RadRotate(self.RotAngle - math.random() * (math.pi/8) * ((100 - self.accuracy)/100) * Aiming);
end
end
self.particle.Mass = self.Bullet["mass"]
self.particle.Sharpness = self.Bullet["sharpness"];
self.particle.Vel = self.firingvector * self.Bullet["firevel"];
self.particle.LifeTime = 1500;
self.particle.Team = self.projectileteam;
self.particle.IgnoresTeamHits = true;
MovableMan:AddParticle(self.particle);

-- Create firing sound emitter.
self.particle = CreateAEmitter(self.FireSound,"Brolands.rte");
self.particle.Pos = self.Pos;
MovableMan:AddParticle(self.particle);

-- Create muzzleflash
self.particle2.Pos = self.Barrel["pointer"].Pos + Vector(self.Barrel["muzzleoffset"].X * -1,self.Barrel["muzzleoffset"].Y):RadRotate(self.RotAngle);
self.particle2.Vel = self.Vel;
MovableMan:AddParticle(self.particle2);
end

-- Keeps track of the magazine
if self.Magazine == nil then
self.Mag["pointer"].Scale = 0;
self.ammocounter = self.ammocapacity;
self.reloading = true;
else
self.Mag["pointer"].Scale = 1;
self.Magazine.RoundCount = self.ammocounter;
end

if self.reloading == true and self.Magazine ~= nil then
self.reloading = false;
-- When the gun is done reloading, play reload sound
self.particle = CreateAEmitter(self.ReloadSound,"Brolands.rte");
self.particle.Pos = self.Pos;
MovableMan:AddParticle(self.particle);
end

end

function Destroy(self)
end

function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end

Fun things:
"pointers" in lua

47
Developer's Corner / Re: Dice analyzer machine project
« on: January 20, 2016, 08:30 AM »
If anyone comes up  with a good idea for hardware and is willing to put down some money (I'd of course spend some myself), I could probably try building it.

48
DC Gamer Club / Re: Fallout 3 (GOTYE) on Windows 10 Pro.
« on: September 23, 2015, 07:01 PM »
Fallout 3 is a pretty good game, it suffers the same fate as most Bethesda games though, the main story is shoddy and the game is buggy in general. But let yourself cut loose and just wander and there's a good chance you will wander into some interesting content. Just my two cents. Also, for the love of god, be sure to invest into a build (A good tip is to invest into a single weapon skill, a utility skill like lockpicking, science or speech and some more general purpose skills like medicine, sneak or repair). Don't try to be good at everything, you will end up not being able to do anything.

49
Living Room / Re: Recommend some music videos to me!
« on: July 24, 2015, 01:08 AM »
Hey! I am not sure if any of you guys are familiar with the Demoscene, they make some wicked cool stuff if you're into the whole abstract graphics aesthetic. These are just some random ones I grabbed off of Pouet or remembered off the top of my head:
Is That a Demo in Your Pocket?, a Game Boy Demo
Backscatter, a more modern 40k (meaning the executable is 40kilobyte or less) demo
Batman Forever, a Armstrad CPC demo.
8088mph, a demo running on a IBM 5150 PC.

While some of these aren't big in the demoscene , they show off the variety in my opinion while also showing some common traits. I love the aesthetic so much that I convinced my brother to help me produce this last christmas. Even if some of what you see might not look that impressive, thinking about the limitations of hardware or resources really makes me sit there with a sense of awe thinking about the weird stuff they had to pull off to do some of this stuff.

50
Living Room / Re: Your favorite cartoons of yesterday and today?
« on: July 23, 2015, 11:45 PM »
Maaaaaan, don't get me started on cartoons! I goddamn love cartoons, everything from the older Disney to modern french surreal cartoons. I can't get enough of them! Also one thing I learned to throw out the window pretty early is that demographics weren't that important. Something I kind of forgot until quite recently, I'll get into that later.

As some of you know I am a huge sucker for the modern reboot of the My Little Pony cartoons (MLP:Friendship is Magic), and while it might not be understandable from the outside, or hell, even the inside. It's a really good show with nice colors, animations and decent enough story arcs, while also being just generally entertaining. I mostly got into it for the lulz, as they say on the internet back when it was a huge fad. But I actually liked it in the end, it wasn't until later that I found out the some of the people working on it were also on the team that made The PowerPuff Girls, another cartoon I liked a lot as a kid, which is definitely not marketed to dudes.

There's also Sheep in the Big City, something that I only watched younger when it was dubbed in Danish, which made me loathe it. It's slow, looks bad and the story is non-sensical in a very unfunny way. BUT, I watched it YEARS later in English and figured out why some people liked it. It's entire premise is a series of puns and stupid wordplays, while the story can be overanalysed into being EVERYTHING. Something that you can't really enjoy as a kid. It also breaks the fourth wall in ways I find pretty funny, even if shoehorned in.

I don't think I saw anyone mention it either, but there's also Regular Show. A slice of life cartoon about two goofballs trying to do as little work as possible without getting fired from their park maintenance jobs. This doesn't sound very interesting, but every episode completely derails about halfway through into occult crazy stuff or the like. A lot of the time without all that much warning, which in it's absurd formularity makes it goddamn hilarious to me. You could see it as a bit of a stoner cartoon, but it's really good even if you are not intoxicated, at least in my opinion.

Edit:
Speaking of the french, there's Wakfu, which is pretty standard in terms of plot and characters. But it is beautiful for a flash cartoon, at least I think so. It took some time getting into it though and the French dubbing with English subs really put me off for a while. But character design is a breath of fresh air for cartoons in my opinion, because pretty much everyone is exaggerated in ways you wouldn't see in most mainstream cartoons. For example Evangeline who is pretty sexualized, something that may put some off as her and her love interest in the series is supposed around 16-18 or so IIRC.

MOVING ON, anime.
If you haven't seen Cowboy Bebop, DO SO NOW. It's basically Firefly before Firefly, a wild west space thriller/comedy/action thing with a ship and it's motley crew of not entirely good do-gooders. Neon Genesis Evangelion is also pretty good, but I haven't had the chance to watch it since I got older. Never saw it till the end, but it is filled with metaphors, symbolic imagery and entirely mindfuck visuals at some points. From what I read/remember a lot of the story, plot and imagery is purposefully made to mess with peoples expectations.

Edit edit:

Oh man, and I completely forgot about Samurai Jack, which Cartoon Network ran back in the day. It was slow paced as all hell with lots of establishing shots. Which only helped emphasize the fantastically choreographed action scenes. I don't remember that many of the episodes off the top of my head, but one thing ran through them all, it was damn beautiful and filled with subdued humour and lots of quirky character design.

I also bolded all the cartoon names in case anyone wants to just take the TL;DR route. Also I haven't slept today, in case I am rambling too much and that bleeds through into the post.

Pages: prev1 ... 5 6 7 8 9 [10] 11 12 13 14 15 ... 84next
Go to full version