Jump to content

Newb to a programmer


bartekkru99

Recommended Posts

I've started to learn programming in C# an now I know how to use if, else and switch and I'm practically a newb. I want to ask you how much time it takes to master programming, so I can write simple apps and games (at least mods)? Few months? years?

Link to comment
Share on other sites

I've started to learn programming in C# an now I know how to use if, else and switch and I'm practically a newb. I want to ask you how much time it takes to master programming, so I can write simple apps and games (at least mods)? Few months? years?

How long it takes depends on your dedication level, prior education, how quickly you learn, etc. I've been trying to learn programming off and on for about a year.

Link to comment
Share on other sites

I've started to learn programming in C# an now I know how to use if, else and switch and I'm practically a newb. I want to ask you how much time it takes to master programming, so I can write simple apps and games (at least mods)? Few months? years?

"master programming" is an incredibly vague term, very few programmers would consider themselves as having mastered programming (and the ones that do consider themselves to, most people would disagree)

Depends what you mean by "simple apps". You can make incredibly simple ones within a few days of learning to program, e.g. a version of the countdown number game could easily be made within a few days of starting to learn programming.

Link to comment
Share on other sites

You'll never stop learning. People develop new inventions, algorithms and concepts all the time. You'll most likely have to concentrate on a few fields to be able to keep up.

Let me guess a bit so you have some numbers:

- intermediate level after about 1-2 years (knows basic concepts and design patterns, uses one programming language)

- advanced level after about 5 years (knows most concepts and patterns used in his specialization, knows about 2-3 programming languages)

- veteran level after about 10 years (knows a lot of stuff outside his specialization, develops new techniques, chooses programming language according to the problem to solve)

These are only guesses. I'm into programming for ~15 years and even studied computer science and I don't consider myself a veteran.

Extra cookies for people who understand what this does and why it is probably the most efficient way (I wrote that during classes):

double mysterious(unsigned int k)
{
unsigned long long int value = (1023LL - k) << 52
return 2.0 - *((double*)&value);
}

;-)

Link to comment
Share on other sites

Give yourself a good month or two to learn the basics of C#, following a book or set of tutorials: Syntax, variables, scope, arrays, functions, classes, modules. When you feel comfortable, dive right into a project (a reasonable, small-in-scope, personal project). You'll learn a lot more when you are searching for something you NEED to make your project work. After a few small projects, you'll know what you're capable of on your own.

Check out these videos. They're not tutorials or anything, but they should get you in the right mindset for starting an early project:

At any point, feel free to use this forum and others as a resource. Programmers are very forthcoming with solutions to problems they have dealt with before!

Link to comment
Share on other sites

Extra cookies for people who understand what this does and why it is probably the most efficient way (I wrote that during classes):

double mysterious(unsigned int k)
{
unsigned long long int value = (1023LL - k) << 52
return 2.0 - *((double*)&value);
}

;-)

Bah! Humbug. Shifting bits to do math... It's a readability nightmare! (Dat efficiency, tho)

Sadly, I'm not dedicated enough to sit and figure what math function this is (brain is busy doing work things), so no cookie for me.

Link to comment
Share on other sites

Bah! Humbug. Shifting bits to do math... It's a readability nightmare! (Dat efficiency, tho)

I generally despise the common meme that everything should be coded to the least skilled programmer that might come across it. That attitude is a race to the bottom, and its the reason modern languages don't let us have nice things anymore. (like proper switch statements with correct case fall-throughs).

However, there is a second reason that the example code snippet is poor practice. It's got nothing to do with the skill involved in understanding it. It's because it's dependent on presuming to know the exact underlying hardware implementation of the double float. Sure, that solution will work *IF* you are guaranteed to know exactly which IEEE floating-point standard is in use for that implementation, and thus exactly which bits are stored where, how many bits are mantissa, how many are exponent, etc. That sort of hardware-locked thinking only belongs in very tight narrow applications where you really *are* guaranteed to know the hardware involved forever and ever for the future life of the software - certain integrated burned-in software for example.

Link to comment
Share on other sites

You'll encounter this whenever googling a programming related problem, but I'm just gonna throw it out here - stackoverflow.com. You will learn to love it.

Extra cookies for people who understand what this does and why it is probably the most efficient way (I wrote that during classes):

double mysterious(unsigned int k)
{
unsigned long long int value = (1023LL - k) << 52
return 2.0 - *((double*)&value);
}

Oh, oh! I do! It'll throw out an error during compilation, because you are missing a semicolon after "<< 52" :D I can has cookie?

I think it does a sum of 0.5n from n = 0 to k

2.0 is the maximum value of the sum, and the bit before that is just generating higher powers of 0.5 to subtract from it. Efficient because there is no need to actually calculate the whole sum, just one power, and you can do that by bit shifting. Pretty neat, albeit highly unreadable. As others have pointed out, it's probably not the best practice, but it makes for an interesting puzzle.

Edited by Deutherius
Link to comment
Share on other sites

@Deutherius

Correct! Here's your cookie:

cookie.png

I accidentally deleted the ; when removing the comments.

My lecturer wanted us students to find an efficient way to calculate Σ 1/2k and this was my idea. He was quite surprised. ^^

---

You guys are right. It is almost unreadable. That's the reason why I don't like C++. It's just too easy to make a mess of a code nobody comprehends. And you have to be cautious to not accidentally do something wrong. That's also one of the reasons I don't count myself as a veteran programmer: My code can get pretty messy if a language allows it. That's why I like to stick to Java and C#. In particular Java forces you to stick to design patterns and write good code.

Link to comment
Share on other sites

Coding is a process of figuring out want you want to do, and then either knowing how to do it or looking it up online, as you get more experienced, you move away from the latter more and more, but you never stop having to look stuff up.

Link to comment
Share on other sites

I've started to learn programming in C# an now I know how to use if, else and switch and I'm practically a newb. I want to ask you how much time it takes to master programming, so I can write simple apps and games (at least mods)? Few months? years?

I think it's better expressed in hours of actually doing it.

After a couple dozen hours of coding, you can probably do things that look like magic to 99% of the population. You can also start to appreciate how far you still have to go. Or if you even want to.

Link to comment
Share on other sites

While we're on the subject of readability, I do love Python's interface and language. Nice and simple for beginners, yet has the higher-level operations that experienced programmers use.

However, if you are not careful, you can easily turn any program into a mess.


import pygame,random,time,sys
from pygame.locals import*

pygame.init()
mainClock=pygame.time.Clock()

FPS=100

def drawText(text,font,surface,x,y):
textobj=font.render(text,1,TEXTCOLOR)
textrect=textobj.get_rect()
textrect.topleft=(x,y)
surface.blit(textobj,textrect)

font=pygame.font.SysFont(None,30)

WHITE=(255,255,255)
GREEN=(0,255,0)
BLUE=(0,0,225)
RED=(255,0,0)
BLACK=(0,0,0)
YELLOW=(255,255,0)

TEXTCOLOR=(WHITE)

WINDOWHIGHT=768
WINDOWWIDTH=1366

SCORE=0

BADDIEMINSPEED=3
BADDIEMAXSPEED=10

ADDNEWBADDIERATE=20

ADDSUPERBADDIERATE=150

BADDIEMINSIZE=10
BADDIEMAXSIZE=50

ROCKETSPEED=7
ADDNEWROCKETRATE=8
ROCKETSIZE=7

PULSESPEED=10
ADDNEWPULSERATE=25
PULSESIZE=30

MINESIZE=25
ADDNEWMINERATE=20

SUPERSIZE=50

NEWPOINTSQUARE=50

POINTSQUARESIZE=20

SPECIALPOINTSQUARE=500

DIFFCOUNTER = 0

def terminate():
pygame.quit()
sys.exit()

def playerhitbaddie(playerRect,baddies):
global player1Health
for b in baddies:
if doRectsOverlap(b['rect'],playerRect):
baddies.remove(
player1Health-=1
return player1Health

def playerhitsuperbaddie(playerRect,superbaddies):
global player1Health
for s in superbaddies:
if doRectsOverlap(s['rect'],playerRect):
superbaddies.remove(s)
player1Health-=1
return player1Health

def player2hitbaddie(player2Rect,baddies):
global player2Health
for b in baddies:
if doRectsOverlap(b['rect'],player2Rect):
baddies.remove(
player2Health-=1
return player2Health


def player2hitsuperbaddie(player2Rect,superbaddies):
global player2Health
for s in superbaddies:
if doRectsOverlap(s['rect'],player2Rect):
superbaddies.remove(s)
player2Health-=1
return player2Health



def rocket2hitbaddie(rockets2,baddies):
global SCORE
for r in rockets2:
for t in baddies:
if doRectsOverlap(r['rect'],t['rect']):
rockets2.remove(r)
baddies.remove(t)
SCORE+=1
return SCORE

def pulse2hitbaddie(pulses2,baddies):
global SCORE
for p in pulses2:
for t in baddies:
if doRectsOverlap(p['rect'],t['rect']):
baddies.remove(t)
SCORE+=1
return SCORE

def pulse2hitsuperbaddie(pulses2,superbaddies):
global SCORE
for p in pulses2:
for t in superbaddies:
if doRectsOverlap(p['rect'],t['rect']):
superbaddies.remove(t)
SCORE+=10
return SCORE

def rockethitbaddie(rockets,baddies):
global SCORE
for r in rockets:
for t in baddies:
if doRectsOverlap(r['rect'],t['rect']):
rockets.remove(r)
baddies.remove(t)
SCORE+=1
return SCORE

def pulsehitbaddie(pulses,baddies):
global SCORE
for p in pulses:
for t in baddies:
if doRectsOverlap(p['rect'],t['rect']):
baddies.remove(t)
SCORE+=1
return SCORE

def minehitsuperbaddie(mines,superbaddies):
for m in mines:
for t in superbaddies:
if doRectsOverlap(m['rect'],t['rect']):
mineImage=pygame.image.load("C:/Python31/python images/mineExp1.png")

def pulsehitsuperbaddie(pulses,superbaddies):
global SCORE
for p in pulses:
for t in superbaddies:
if doRectsOverlap(p['rect'],t['rect']):
superbaddies.remove(t)
SCORE+=10
return SCORE

def waitForPlayerToPressKey():
while True:
for event in pygame.event.get():
if event.type==MOUSEBUTTONDOWN:
return
if event.type==QUIT:
terminate()
if event.type==KEYDOWN:
if event.key==K_ESCAPE:
terminate()
return

def doRectsOverlap(rect1,rect2):
for a,b in [(rect1,rect2),(rect2,rect1)]:
#check if a's corners are inside b
if ((isPointInsideRect(a.left,a.top,)or
(isPointInsideRect(a.left,a.bottom,)or
(isPointInsideRect(a.right,a.top,)or
(isPointInsideRect(a.right,a.bottom,)):
return True
return False



def isPointInsideRect(x,y,rect):
if(x > rect.left) and (x < rect.right) and (y > rect.top) and (y < rect.bottom):
return True
else:
return False

window1=pygame.display.set_mode((WINDOWWIDTH,WINDOWHIGHT),pygame.FULLSCREEN)
window1.fill(BLACK)

pygame.mouse.set_visible(False)

pygame.display.update()

playerImage=pygame.image.load("C:/Python31/python images/ShipImage.png")
playerRect=playerImage.get_rect()

player1Sign=pygame.image.load("C:/Python31/python images/ShipImage.png")
player1Rect=playerImage.get_rect()


player2Image=pygame.image.load("C:/Python31/python images/ShipImage2.png")
player2Rect=playerImage.get_rect()

player2Sign=pygame.image.load("C:/Python31/python images/ShipImage2.png")
player2SignRect=player2Sign.get_rect()

baddieImage=pygame.image.load("C:/Python31/python images/asteroid.png")
superBaddieImage=pygame.image.load("C:/Python31/python images/super asteroid.png")

pulseImage=pygame.image.load("C:/Python31/python images/pulse image.png")
pulseSign=pygame.image.load("C:/Python31/python images/pulse image.png")
pulseRect=pulseSign.get_rect()

rocketSign=pygame.image.load("C:/Python31/python images/rocket.png")
rocketRect=rocketSign.get_rect()
rocketImage=pygame.image.load("C:/Python31/python images/rocket.png")

pulse2Image=pygame.image.load("C:/Python31/python images/pulse image.png")
pulse2Sign=pygame.image.load("C:/Python31/python images/pulse image.png")
pulse2Rect=pulseSign.get_rect()

rocket2Sign=pygame.image.load("C:/Python31/python images/rocket.png")
rocket2Rect=rocketSign.get_rect()
rocket2Image=pygame.image.load("C:/Python31/python images/rocket.png")

mineExpImage=pygame.image.load("C:/Python31/python images/mineExp1.png")
mineImage=pygame.image.load("C:/Python31/python images/mineImage.png")

pointSquareImage=pygame.image.load("C:/Python31/python images/pointSquareImage.png")
pointSquareImage2=pygame.image.load("C:/Python31/python images/pointSquareImage2.png")

StartUpScreen=pygame.image.load("C:/Python31/python images/dodgerStartupScreen.png")
StartUpRect=StartUpScreen.get_rect()

pygame.display.update()

MOVESPEED=4

startUpMusic=pygame.mixer.Sound("C:/Python31/python/FSX06.wav")

backgroundMusic=pygame.mixer.Sound("C:/Python31/python/FSX02.wav")
backgroundMusic2=pygame.mixer.Sound("C:/Python31/python/FSX08.wav")

explosionSound=pygame.mixer.Sound("C:/Python31/python/Exp_OilRig02.wav")

pickUpSound=pygame.mixer.Sound("C:/Python31/python/sbitmsel.wav")

startUpMusic.play()
StartUpRect.topleft=(300,WINDOWHIGHT/2)
window1.blit(StartUpScreen,StartUpRect)

drawText('Asteroid Frontier',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3))
pygame.display.update()
time.sleep(.5)
drawText('Press any key to start',font,window1,(WINDOWWIDTH/3)-30,(WINDOWHIGHT/3)+50)
pygame.display.update()
waitForPlayerToPressKey()
startUpMusic.stop()
window1.fill(BLACK)

def Intro():
startUpMusic.play()
drawText('The Red Squares are ammunition. Collect to replenish rockets and pulses',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3)-50)
pygame.display.update()
time.sleep(.2)
drawText('The blue Squares are worth points',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3))
pygame.display.update()
time.sleep(.2)
drawText('The asteroids will destroy your Ship, avoid them at all costs',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3)+50)
pygame.display.update()
time.sleep(.2)
drawText('The flaming asteroids are unaffected by rockets',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3)+100)
pygame.display.update()
time.sleep(.2)
drawText('P1: use arrow keys to move, n to fire rockets and SPACEBAR to fire pulses',font,window1,(WINDOWWIDTH/3)-50,(WINDOWHIGHT/3)+150)
drawText('P2: use WASD keys to move, q to fire rockets and Tab to fire pulses',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3)+170)
pygame.display.update()
time.sleep(.2)
drawText('Good Luck!',font,window1,(WINDOWWIDTH/3),(WINDOWHIGHT/3)+220)

pygame.display.update()
waitForPlayerToPressKey()
startUpMusic.stop()

topScore=0

pointSquarecounter=0

specialFoodCounter=0

while True:

file_path='C:\\Python31\\python\\dodger high scores.txt'
file=open(file_path,"r")
for line in file:
topScore=line
topScore=float(topScore)
file.close()

rocketlimit=20

pulselimit=10

rocketlimit2=20

pulselimit2=10

minelimit=1000

mines=[]

mineaddcounter=5

pointSquares=[]

specialFoods=[]

baddies=[]

superbaddies=[]

DriftA = 0

rockets=[]

pulses=[]

pulseaddcounter=0

rocketaddcounter=0

Drift = 0

rockets2=[]

pulses2=[]

pulseaddcounter2=0

rocketaddcounter2=0

baddieaddcounter=0

superbaddiecounter=0

playerRect.topleft=((WINDOWWIDTH/2)-50,WINDOWHIGHT-50)

player2Rect.topleft=((WINDOWWIDTH/2)+50,WINDOWHIGHT-50)

player1Rect.topleft=(WINDOWWIDTH-70,WINDOWHIGHT-190)

player2SignRect.topleft=(0,WINDOWHIGHT-190)

rocketRect.topleft=(10,WINDOWHIGHT-90)

pulseRect.topleft=(0,WINDOWHIGHT-40)

rocket2Rect.topleft=(WINDOWWIDTH-120,WINDOWHIGHT-90)

pulse2Rect.topleft=(WINDOWWIDTH-130,WINDOWHIGHT-40)

moveLeft=moveLeft2=moveRight=moveRight2=moveUp=moveUp2=moveDown=moveDown2=False

reverseCheat=slowCheat=invincibleCheat=pauseCheat=rocketFiring=pulseFiring=mineFiring=rocketFiring2=pulseFiring2=player1IsDead=player2IsDead=False

intro=True

player1Health=5

player2Health=5

SCORE=0

ADDSUPERBADDIERATE=200
ADDNEWBADDIERATE = 30

DIFFCOUNTER = 0

while True:
SCORE+=.01


if intro==True:
Intro()
intro=False

backgroundMusic.play()
for event in pygame.event.get():
if event.type==QUIT:
terminate()
if event.type==KEYDOWN:
if event.key==K_RALT:
mineFiring=True

if event.key==ord('['):
rocketFiring=True

if event.key==ord(']'):
pulseFiring=True

if event.key==ord('q'):
rocketFiring2=True

if event.key==K_TAB:
pulseFiring2=True

if event.key==ord('z'):
reverseCheat=True

if event.key==ord('x'):
slowCheat=True

if event.key==ord('c'):
invincibleCheat=True

if event.key==ord('v'):
pauseCheat=True

if event.key==K_LEFT:
moveRight=False
moveLeft=True

if event.key==K_RIGHT:
moveRight=True
moveLeft=False

if event.key==K_UP:
moveDown=False
moveUp=True

if event.key==K_DOWN:
moveDown=True
moveUp=False

if event.key==ord('d'):
moveRight2=True
moveLeft2=False

if event.key==ord('a'):
moveRight2=False
moveLeft2=True

if event.key==ord('w'):
moveDown2=False
moveUp2=True

if event.key==ord('s'):
moveDown2=True
moveUp2=False

if event.type==KEYUP:
if event.key==K_RALT:
mineFiring=False

if event.key==ord('q'):
rocketFiring2=False

if event.key==K_TAB:
pulseFiring2=False

if event.key==ord('['):
rocketFiring=False

if event.key==ord(']'):
pulseFiring=False

if event.key==ord('z'):
reverseCheat=False

if event.key==ord('c'):
invincibleCheat=False

if event.key==ord('x'):
slowCheat=False

if event.key==ord('v'):
pauseCheat=False

if event.key==K_ESCAPE:
pygame.quit()
sys.exit()

if event.key==K_LEFT:
moveLeft=False

if event.key==K_RIGHT:
moveRight=False

if event.key==K_UP:
moveUp=False

if event.key==K_DOWN:
moveDown=False

if event.key==ord('d'):
moveRight2=False

if event.key==ord('a'):
moveLeft2=False

if event.key==ord('w'):
moveUp2=False

if event.key==ord('s'):
moveDown2=False


#adds new rockets
if player1IsDead==False:
if rocketlimit>=1:
if rocketFiring==True:
rocketaddcounter+=1
if rocketaddcounter==ADDNEWROCKETRATE:
rocketlimit-=1
rocketaddcounter=0
rocketSize=ROCKETSIZE
newRocket={'rect': pygame.Rect(playerRect.centerx-4,playerRect.centery,rocketSize,rocketSize),
'speed': ROCKETSPEED,
'surface': pygame.transform.scale(rocketImage,(rocketSize,rocketSize)),
'drift':random.randint(-1,1),}
rockets.append(newRocket)


if pulselimit>=1:
if pulseFiring==True:
pulseaddcounter+=1
if pulseaddcounter==ADDNEWPULSERATE:
pulselimit-=1
pulseaddcounter=0
pulseSize=PULSESIZE
newPulse={'rect': pygame.Rect(playerRect.centerx-15,playerRect.centery,pulseSize,pulseSize),
'speed': PULSESPEED,
'surface': pygame.transform.scale(pulseImage,(pulseSize,pulseSize)),}
pulses.append(newPulse)
if player2IsDead==False:
if rocketlimit2>=1:
if rocketFiring2==True:
rocketaddcounter2+=1
if rocketaddcounter2==ADDNEWROCKETRATE:
rocketlimit2-=1
rocketaddcounter2=0
rocketSize=ROCKETSIZE
newRocket2={'rect': pygame.Rect(player2Rect.centerx-4,player2Rect.centery,rocketSize,rocketSize),
'speed': ROCKETSPEED,
'surface': pygame.transform.scale(rocketImage,(rocketSize,rocketSize)),
'drift':random.uniform(-2,2),}
rockets2.append(newRocket2)


if pulselimit2>=0:
if pulseFiring2==True:
pulseaddcounter2+=1
if pulseaddcounter2==ADDNEWPULSERATE:
pulselimit2-=1
pulseaddcounter2=0
pulseSize=PULSESIZE
newPulse2={'rect': pygame.Rect(player2Rect.centerx-15,player2Rect.centery,pulseSize,pulseSize),
'speed': PULSESPEED,
'surface': pygame.transform.scale(pulseImage,(pulseSize,pulseSize)),}
pulses2.append(newPulse2)

if mineFiring==True:
mineaddcounter+=1
if minelimit>0:
if mineaddcounter==ADDNEWMINERATE:
minelimit-=1
mineaddcounter=0
mineSize=MINESIZE
newMine={'rect': pygame.Rect(playerRect.centerx-150,playerRect.centery-150,mineSize,mineSize),
'surface': pygame.transform.scale(mineImage,(mineSize,mineSize)),}
mines.append(newMine)

if not pauseCheat:
#adds new asteroids at the top of screen
baddieaddcounter+=1

if baddieaddcounter==ADDNEWBADDIERATE:
baddieaddcounter=0
baddieSize=random.randint(BADDIEMINSIZE,BADDIEMAXSIZE)
newBaddie={'rect': pygame.Rect(random.randint(0,WINDOWWIDTH-baddieSize),0-baddieSize,baddieSize,baddieSize),
'speed': random.randint(BADDIEMINSPEED,BADDIEMAXSPEED),
'surface':pygame.transform.scale(baddieImage,(baddieSize,baddieSize)),}
baddies.append(newBaddie)

superbaddiecounter+=1

if superbaddiecounter==ADDSUPERBADDIERATE:
superbaddiecounter=0
superBaddieSize=SUPERSIZE
newSuperBaddie={'rect': pygame.Rect(random.randint(0,WINDOWWIDTH-superBaddieSize),0-superBaddieSize,superBaddieSize,superBaddieSize*2),
'speed': random.randint(BADDIEMINSPEED,BADDIEMAXSPEED),
'surface': pygame.transform.scale(superBaddieImage,(superBaddieSize,superBaddieSize*2)),}
superbaddies.append(newSuperBaddie)
for r in rockets:
#moves the rockets up
r['rect'].move_ip(r['drift'],r['speed']*-1)
r['speed'] += .05

#removes rockets a the top of the screen
if r['rect'].top<0:
rockets.remove(r)

for p in pulses:
#moves the pulses up
p['rect'].move_ip(0,p['speed']*-1)

#removes pulses at the top of the screen
if p['rect'].top<0:
pulses.remove(p)

for r in rockets2:
DriftIncrement = random.randint(-2,2)
Drift += DriftIncrement
if Drift < 2:
Drift = 2
if Drift < -2:
Drift = -2
#moves the rockets up
r['rect'].move_ip(r['drift'],r['speed']*-1)
r['speed'] += .05

#removes rockets a the top of the screen
if r['rect'].top<0:
rockets2.remove(r)

for p in pulses2:
#moves the pulses up
p['rect'].move_ip(0,p['speed']*-1)

#removes pulses at the top of the screen
if p['rect'].top<0:
pulses2.remove(p)

for b in baddies:
if not reverseCheat and not slowCheat and not pauseCheat:
b['rect'].move_ip(DriftA,b['speed'])

elif reverseCheat:
b['rect'].move_ip(0,-5)

elif slowCheat:
b['rect'].move_ip(0,1)

elif pauseCheat:
b['rect'].move_ip(0,b['speed']-b['speed'])

for b in baddies[:]:
#removes asteroids at the botom of the screen
if b['rect'].top>WINDOWHIGHT:
baddies.remove(

for b in superbaddies:
if not slowCheat and not pauseCheat:
b['rect'].move_ip(0,b['speed'])

elif pauseCheat:
b['rect'].move_ip(0,b['speed']-b['speed'])

elif slowCheat:
b['rect'].move_ip(0,2)

for b in superbaddies[:]:
if b['rect'].top>WINDOWHIGHT:
superbaddies.remove(

#creates point squares
pointSquarecounter+=1
if pointSquarecounter>=NEWPOINTSQUARE:
pointSquarecounter=0
newFood={'rect': pygame.Rect(random.randint(0,WINDOWWIDTH-POINTSQUARESIZE),0-POINTSQUARESIZE,POINTSQUARESIZE,POINTSQUARESIZE),
'surface':pygame.transform.scale(pointSquareImage,(POINTSQUARESIZE,POINTSQUARESIZE))}
pointSquares.append(newFood)

specialFoodCounter+=1
if specialFoodCounter>=SPECIALPOINTSQUARE:
specialFoodCounter=0
newFood={'rect': pygame.Rect(random.randint(0,WINDOWWIDTH-POINTSQUARESIZE),0-POINTSQUARESIZE,POINTSQUARESIZE,POINTSQUARESIZE),
'surface':pygame.transform.scale(pointSquareImage2,(POINTSQUARESIZE,POINTSQUARESIZE))}
specialFoods.append(newFood)

#moves the point squares

window1.fill(BLACK)

for pointSquare in pointSquares[:]:
if pointSquare['rect'].top>WINDOWHIGHT:
pointSquares.remove(pointSquare)

for pointSquare in specialFoods[:]:
if pointSquare['rect'].top>WINDOWHIGHT:
specialFoods.remove(pointSquare)

for pointSquare in pointSquares[:]:
pointSquare['rect'].move_ip(0,random.randint(1,5))

for pointSquare in specialFoods[:]:
pointSquare['rect'].move_ip(0,random.randint(2,6))

if player1IsDead==False:
if moveDown and playerRect.bottom<WINDOWHIGHT:
playerRect.top+=MOVESPEED

if moveUp and playerRect.top>0:
playerRect.top-=MOVESPEED

if moveLeft and playerRect.left>0:
playerRect.left-=MOVESPEED

if moveRight and playerRect.right<WINDOWWIDTH:
playerRect.right+=MOVESPEED

if player2IsDead==False:
if moveDown2 and player2Rect.bottom<WINDOWHIGHT:
player2Rect.top+=MOVESPEED

if moveUp2 and player2Rect.top>0:
player2Rect.top-=MOVESPEED

if moveLeft2 and player2Rect.left>0:
player2Rect.left-=MOVESPEED

if moveRight2 and player2Rect.right<WINDOWWIDTH:
player2Rect.right+=MOVESPEED

#checks if player has collided with point square
if player1IsDead==False:

for pointSquare in pointSquares[:]:
if doRectsOverlap(pointSquare['rect'],playerRect):
pickUpSound.play()
pointSquares.remove(pointSquare)
SCORE+=1

for special in specialFoods[:]:
if doRectsOverlap(special['rect'],playerRect):
pickUpSound.play()
specialFoods.remove(special)
rocketlimit+=25
pulselimit+=10
if player1Health < 5:
player1Health += 1
if player2IsDead==False:

for pointSquare in pointSquares[:]:
if doRectsOverlap(pointSquare['rect'],player2Rect):
pickUpSound.play()
pointSquares.remove(pointSquare)
SCORE+=1

for special in specialFoods[:]:
if doRectsOverlap(special['rect'],player2Rect):
pickUpSound.play()
specialFoods.remove(special)
rocketlimit2+=25
pulselimit2+=10
if player2Health < 5:
player2Health += 1

rockethitbaddie(rockets,baddies)

pulsehitbaddie(pulses,baddies)

pulsehitsuperbaddie(pulses,superbaddies)

rocket2hitbaddie(rockets2,baddies)

pulse2hitbaddie(pulses2,baddies)

pulse2hitsuperbaddie(pulses2,superbaddies)

#draws objects onto the screen
for pointSquare in pointSquares:
window1.blit(pointSquare['surface'],pointSquare['rect'])

for special in specialFoods:
window1.blit(special['surface'],special['rect'])

for p in pulses:
window1.blit(p['surface'],p['rect'],)

for p in pulses2:
window1.blit(p['surface'],p['rect'],)

for b in baddies:
window1.blit(b['surface'],b['rect'],)

for b in superbaddies:
window1.blit(b['surface'],b['rect'],)

for r in rockets:
window1.blit(r['surface'],r['rect'],)

for r in rockets2:
window1.blit(r['surface'],r['rect'],)

for m in mines:
window1.blit(m['surface'],m['rect'],)

window1.blit(playerImage,playerRect)

window1.blit(player2Image,player2Rect)

window1.blit(rocketSign,rocketRect)

window1.blit(pulseSign,pulseRect)

window1.blit(player1Sign,player1Rect)

window1.blit(player2Sign,player2SignRect)

window1.blit(rocket2Sign,rocket2Rect)

window1.blit(pulse2Sign,pulse2Rect)
if player1IsDead==False:
playerHealthCheck1=playerhitbaddie(playerRect,baddies)
if playerHealthCheck1==0:

if invincibleCheat==False:
player1IsDead=True
backgroundMusic.stop()
explosionSound.play()
playerImage=pygame.image.load("C:/Python31/python images/ShipExp1.png")
window1.blit(playerImage,playerRect)

pygame.display.update()
time.sleep(0.5)

playerImage=pygame.image.load("C:/Python31/python images/ShipExp2.png")
window1.blit(playerImage,playerRect)

pygame.display.update()
time.sleep(0.5)

playerImage=pygame.image.load("C:/Python31/python images/ShipExp3.png")
window1.blit(playerImage,playerRect)

pygame.display.update()
time.sleep(0.5)

pygame.display.update()
explosionSound.stop()

if player2IsDead==True:
if SCORE>topScore:
topScore=SCORE
topScore=str(topScore)
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
file_path='C:\\Python31\\python\\dodger high scores.txt'
file=open(file_path,"w")
file.write(topScore)

file.close()

time.sleep(2)
SCORE=0
break
backgroundMusic.play()

if player1IsDead==False:
playerHealthCheck1=playerhitsuperbaddie(playerRect,superbaddies)
if playerHealthCheck1==0:
player1IsDead=True
backgroundMusic.stop()
explosionSound.play()

playerImage=pygame.image.load("C:/Python31/python images/ShipExp1.png")
window1.blit(playerImage,playerRect)

pygame.display.update()
time.sleep(0.5)

playerImage=pygame.image.load("C:/Python31/python images/ShipExp2.png")
window1.blit(playerImage,playerRect)

pygame.display.update()
time.sleep(0.5)

playerImage=pygame.image.load("C:/Python31/python images/ShipExp3.png")
window1.blit(playerImage,playerRect)
time.sleep(0.5)
explosionSound.stop()
if player2IsDead==True:
if SCORE>topScore:
topScore=SCORE
topScore=str(topScore)
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
file_path='C:\\Python31\\python\\dodger high scores.txt'
file=open(file_path,"w")
file.write(topScore)

file.close()
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
time.sleep(2)
SCORE=0
break
backgroundMusic.play()

if player2IsDead==False:
playerHealthCheck2=player2hitbaddie(player2Rect,baddies)
if playerHealthCheck2==0:
if invincibleCheat==False:
player2IsDead=True
backgroundMusic.stop()
explosionSound.play()
player2Image=pygame.image.load("C:/Python31/python images/ShipExp1.png")
window1.blit(player2Image,player2Rect)

pygame.display.update()
time.sleep(0.5)

player2Image=pygame.image.load("C:/Python31/python images/ShipExp2.png")
window1.blit(player2Image,player2Rect)

pygame.display.update()
time.sleep(0.5)

player2Image=pygame.image.load("C:/Python31/python images/ShipExp3.png")
window1.blit(player2Image,player2Rect)

pygame.display.update()
time.sleep(0.5)

pygame.display.update()
explosionSound.stop()
if player1IsDead==True:
if SCORE>topScore:
topScore=SCORE
topScore=str(topScore)
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
file_path='C:\\Python31\\python\\dodger high scores.txt'
file=open(file_path,"w")
file.write(topScore)

file.close()
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
time.sleep(2)
SCORE=0
break
backgroundMusic.play()

if player2IsDead==False:
playerHealthCheck2=player2hitsuperbaddie(player2Rect,superbaddies)
if playerHealthCheck2==0:
player2IsDead=True
backgroundMusic.stop()
explosionSound.play()
player2Image=pygame.image.load("C:/Python31/python images/ShipExp1.png")
window1.blit(player2Image,player2Rect)

pygame.display.update()
time.sleep(0.5)

player2Image=pygame.image.load("C:/Python31/python images/ShipExp2.png")
window1.blit(player2Image,player2Rect)

pygame.display.update()
time.sleep(0.5)

player2Image=pygame.image.load("C:/Python31/python images/ShipExp3.png")
window1.blit(player2Image,player2Rect)
time.sleep(0.5)

explosionSound.stop()
if player1IsDead==True:
if SCORE>topScore:
topScore=SCORE
topScore=str(topScore)
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
file_path='C:\\Python31\\python\\dodger high scores.txt'
file=open(file_path,"w")
file.write(topScore)

file.close()
drawText('Score: %s' %(SCORE),font,window1,500,500)
drawText('New high score!', font, window1, (WINDOWWIDTH/2),(WINDOWHIGHT/2))
pygame.display.update()
time.sleep(2)
SCORE=0
break
backgroundMusic.play()

drawText('Score: %s' %(SCORE),font,window1,10,0)

drawText('Top Score: %s' %(topScore),font,window1,10,40)

drawText('X%s' %(rocketlimit2),font,window1,40,WINDOWHIGHT-80)

drawText('X%s' %(pulselimit2),font,window1,40,WINDOWHIGHT-40)

drawText('Health: %s/5' %(player2Health),font,window1,0,WINDOWHIGHT-120)

drawText('Health: %s/5' %(player1Health),font,window1,WINDOWWIDTH-120,WINDOWHIGHT-120)

drawText('X%s' %(rocketlimit),font,window1,WINDOWWIDTH-80,WINDOWHIGHT-80)

drawText('X%s' %(pulselimit),font,window1,WINDOWWIDTH-80,WINDOWHIGHT-40)

if pauseCheat==True:
drawText('Freeze!',font,window1,(WINDOWWIDTH/3)-80,(WINDOWHIGHT/3)+50)

if slowCheat==True:
drawText('MATRIX!!!',font,window1,(WINDOWWIDTH/2)-80,(WINDOWHIGHT/2)+50)

pygame.display.update()
mainClock.tick(FPS)

TEXTCOLOR=(RED)

drawText('GAME OVER', font, window1, (WINDOWWIDTH/3),(WINDOWHIGHT/3))

pygame.display.update()
time.sleep(1)

TEXTCOLOR=(GREEN)

drawText('Press any key to play again.',font,window1,(WINDOWWIDTH/3)-80,(WINDOWHIGHT/3)+50)

pygame.display.update()
time.sleep(1)
waitForPlayerToPressKey()
backgroundMusic2.stop()

TEXTCOLOR=(WHITE)

playerImage=pygame.image.load("C:/Python31/python images/ShipImage.png")

player2Image=pygame.image.load("C:/Python31/python images/ShipImage2.png")

window1.fill(BLACK)

This was my first Python / PyGame "game". It was a heavily modified version of the example "Dodger" program that was included in a learning manual I got.

And it's about twice as long as it needs to be. Many things were hardcoded that could become modular.

So: Learning to do basics? Maybe a few months. Competency? A year or two. Mastering? Never. Though you'll get pretty darn good in a few more years.

Link to comment
Share on other sites

Coding is a process of figuring out want you want to do, and then either knowing how to do it or looking it up online, as you get more experienced, you move away from the latter more and more, but you never stop having to look stuff up.

This, I'm an programmer with 20 years of experience, I use google and some other sites all the time. Last problem, how to fix metadata on images taken on smart phones so their thumbnails shows correctly orientation on all platforms. Google let me solve the issue in two days.

Looking back 20 years Google and other search engines is probably one of the most powerful tools created. Use it, other has had the same problem before.

- - - Updated - - -

While we're on the subject of readability, I do love Python's interface and language. Nice and simple for beginners, yet has the higher-level operations that experienced programmers use.

However, if you are not careful, you can easily turn any program into a mess.

This was my first Python / PyGame "game". It was a heavily modified version of the example "Dodger" program that was included in a learning manual I got.

And it's about twice as long as it needs to be. Many things were hardcoded that could become modular.

So: Learning to do basics? Maybe a few months. Competency? A year or two. Mastering? Never. Though you'll get pretty darn good in a few more years.

Yes programs into mess, I have some old legacy customers I also has old programs, some programs has had so many modifications I kind of have to apply pressure: this has to be rebuild.

Its simply 20 layers of changes on top of each others so I can not read my own code.

Remember my only real game it was on C64, It was an car driving down the screen who was modified text objects getting written to screen, you could move left and right and jump.

Never made another game but tried, problem is that the minimum quality demands increases to fast for an single guy to make something in his spare time is hard.

Link to comment
Share on other sites

I've started to learn programming in C# an now I know how to use if, else and switch and I'm practically a newb. I want to ask you how much time it takes to master programming, so I can write simple apps and games (at least mods)? Few months? years?
Extra cookies for people who understand what this does and why it is probably the most efficient way (I wrote that during classes):

double mysterious(unsigned int k)
{
unsigned long long int value = (1023LL - k) << 52
return 2.0 - *((double*)&value);
}

;-)

I didn't see it until pointed out, but this is exactly what a master of programming should know, and know well.

The base equation is:

sum(r^n,n=0,k) = (r^(k+1) - 1) / (r - 1)

where r = 0.5

simplified

(0.5^(k + 1) - 1 ) / (0.5 - 1)

(1 - 0.5^(k+1)) / 0.5

2 - 0.5^k

bitshift (a << B) is a simple O(1) operation (it has an opcode representation) that represents (a * 2^B). Power functions are often heavy weight and called in the silliest cases; (I don't believe there's native a exp opcode but...) where multiplication would result in fewer cycles... however, it will only be O(1) if the architecture supports operations on the size at which it is implemented. Since "long long int" isn't actually defined as a fixed data type, it could be 512bit or 8bit for all C++ cares (re: compiler specific). long int just has to be equal to or greater than an int.

Now, an unsigned double is something akin to sum(s(n)*0.5^n,n=0,52) (well... sometimes) while an unsigned int_64 is akin to sum(s(n)*2^n,n=0,64)

There is a major difference between knowing something will work and knowing WHY it works and what its limitations are. If you can improve efficiency by using an O(1) goto, don't say "the compiler will optimize better than I can" because it cannot and won't. Compiler optimization depends strongly on the master programmers programming the compiler and depends 100% on you making your code in a manner that the compiler can best optimize.

If you don't know what the hardware is capable of, what the OS libraries contain, or what your compiler is actually doing; how can you take advantage of the latest hardware, or use optimizing routines, without adding in dead weight like unity or C#.

I will say that anyone who complains this is too "ugly" to be used... really shouldn't...It isn't stable, yes; but you know all those libraries you call, they're filled with extern asm, bitshifts, memory hacks, compiler directives with variances on architecture. You'll even see macros still in use to do things that inline functions cannot (though, I'm not fond of that use). "Portable code" is a complete misnomer anyways; it usually means "I use a library so I don't have to test my code on any system but Windows! I l33t programmer!" Now, libs may or may not be slower than native functions, they may be faster, they may cause problems on certain systems, they may fix problems on other systems; but libs are not a replacement for experience... and they certainly don't mean you do not test your code cross platform *-__-

So can you program? Yeah... programming is easy. But realizing that properties are simply functions and that C# "may or may not" (I tend to feel may not) inline them... or pushing a for loop in a property and repeatedly calling it despite the data not changing -__-;. Heck, using object oriented programming because it is the "in thing" when linear programming, or even simple data containers (OOP is really about polymorphism. If you don't need polymorphism you don't need OOP.)

See, the difference between the programmer and the master programmer isn't what you can program; it is how you manage once you run out of resources and can no longer say "we'll just require our users to have x ram/cpu/gpu" The master programmer does truly amazing things, such as writing a GUI based OS in assembly that still fits on a 1.44mb disk (http://menuetos.net/).

I'm not a master programmer... I don't really consider myself intermediate given my level of knowledge on algorithms and optimizations is zilch. I know some aspects of cpu architecture, but not a lot. Some algorithms and how they work, but not a lot... but getting to a level of programming which you can consider yourself a master requires understanding far more than most people are willing to learn.

Edited by Fel
Link to comment
Share on other sites

Thanks for complementing my code :) but I'm not a master programmer. Yes, I try to do "little" optimizations like the one in my example. I even tend to "over-optimize" things which slows me down a lot.

IMHO that isn't enough.

A good programmer doesn't just write efficient code he also writes it in a way others can read. Because usually you forget what you did there and usually you work in a team. So code should be easy to understand. Optimizations should only be applied to things which slows down a critical part of a software. It's not easy to follow that rules (at least for me).

Ah I remember that one! :D That's where I learned how a boot loader works. Ok it was at least 10 years ago and I forgot what I did there but man, it's so nostalgic!

It's also the the reason why I switched to a high-level programming language. In assembler you have to write pages and pages of code for the simplest things. :confused:

@bartekkru99

C# is a good start, especially if you want to create mods for KSP. If you think it's too much for you try Java which feels like C# but is a bit more strict. A more strict language offers less possible ways to do something which in turn is more clear and easier to understand.

Link to comment
Share on other sites

You guys are right. It is almost unreadable. That's the reason why I don't like C++. It's just too easy to make a mess of a code nobody comprehends. And you have to be cautious to not accidentally do something wrong.

Nobody force you to do monkey coding in C++ ^^, C++ is perfectly readable and easy to understand done right, like any language.

@bartekkru99 If you want to start by something easy, when you can learn about the different basic concepts of programming ( recursion, loop, function, object-oriented, design pattern), try Python as language. It is a language that allow you to get result fast and appreciate what you do :)

Second language, try C. which will allow you to understand the low level aspect of programming: manual memory management, memory protection, pointers, etc, etc.

Link to comment
Share on other sites

Extra cookies for people who understand what this does and why it is probably the most efficient way (I wrote that during classes):

double mysterious(unsigned int k)
{
unsigned long long int value = (1023LL - k) << 52
return 2.0 - *((double*)&value);
}

;-)

Challenge accepted. A faster version.

double mysterious2(unsigned int k)
{
unsigned long long int value = 0x4000000000000000LL - (0x0010000000000000LL >> k);
return *((double*)&value);
}

Also, it works correctly for k > 1023. :P

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...