flat assembler
Message board for the users of flat assembler.

 Index > High Level Languages > simple physics game
Author
 Thread
me239

Joined: 06 Jan 2011
Posts: 200
me239 17 Oct 2011, 05:55
So I know this isn't assembly (that's why I'm putting it in heap), but I thought I might just share this little physics based game I wrote in qbasic 4.5. Basically the objective of the game is to destroy the 20 meter long enemy tank (big ass tank!) at a certain distance. You are given a choice between a short, medium, and long range shell and you are told their speed and max distance. All that is left for you to do is decide on a launch angle. You only get one shot, so make a wise choice! BTW, there are no graphics, just text.
Code:
RANDOMIZE TIMER
r = INT(RND * 2050) + 1
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 50 m/s and 255 meter max"
PRINT "Medium range: 100 m/s 1,020 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c\$
IF c\$ = "s" OR c\$ = "S" THEN v = 50
IF c\$ = "m" OR c\$ = "M" THEN v = 100
IF c\$ = "l" OR c\$ = "L" THEN v = 200
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
ha = COS(a) * v
va = SIN(a) * v
t = (va / 9.8) * 2
d = ha * t
'd = d + (ha * .494)
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t

 Description: Filesize: 11.72 KB Viewed: 10289 Time(s)

 Description: Filesize: 13.47 KB Viewed: 10289 Time(s)

17 Oct 2011, 05:55
Akujin

Joined: 11 Oct 2011
Posts: 26
Location: Exile
Akujin 17 Oct 2011, 09:41
Lets make an asm port...

_________________
CLI
HLT
17 Oct 2011, 09:41
me239

Joined: 06 Jan 2011
Posts: 200
me239 17 Oct 2011, 20:45
Akujin wrote:
Lets make an asm port...
I would, but I don't know how exactly to use floating point in assembly.
17 Oct 2011, 20:45
Akujin

Joined: 11 Oct 2011
Posts: 26
Location: Exile
Akujin 17 Oct 2011, 20:55

_________________
CLI
HLT
17 Oct 2011, 20:55
me239

Joined: 06 Jan 2011
Posts: 200
me239 22 Oct 2011, 21:32
Hey! So I made some quick hack job graphics for my QB game. The tank is now a blue box and it graphs the parabolic path of the projectile.
Code:
SCREEN 9
WINDOW (-30, -200)-(2200, 1000)
LINE (0, -200)-(0, 1000)
LINE (-30, 0)-(2200, 0)
RANDOMIZE TIMER
r = INT(RND * 2050) + 1
PSET ((r / 2), 1), 3
DRAW "l5 u5 r15 d5 l15"
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 50 m/s and 255 meter max"
PRINT "Medium range: 100 m/s 1,020 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c\$
IF c\$ = "s" OR c\$ = "S" THEN v = 50
IF c\$ = "m" OR c\$ = "M" THEN v = 100
IF c\$ = "l" OR c\$ = "L" THEN v = 200
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
ha = COS(a) * v
va = SIN(a) * v
FOR x = 0 TO 60 STEP .0002
y = (va - (9.8 * x)) * x
h = (ha * x)
IF y < 0 THEN GOTO done
PSET (h, y), 4
NEXT x
done:
t = (va / 9.8) * 2
d = ha * t
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY\$ = ""
WEND
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY\$ = ""
WEND

 Description: Filesize: 11.6 KB Viewed: 10109 Time(s)

 Description: Filesize: 13.79 KB Viewed: 10109 Time(s)

22 Oct 2011, 21:32
me239

Joined: 06 Jan 2011
Posts: 200
me239 23 Oct 2011, 01:29
Yet another update. I've changed the range so it's more realistic (1 - 4 Km), changed the speeds to 100, 150, and 200 m/s, and also two little secret options. "G" automatically finds the fastest route and "GA" finds the longest path.
Code:
SCREEN 9
WINDOW (-30, -200)-(2200, 1000)
LINE (0, -200)-(0, 1000)
LINE (-30, 0)-(2200, 0)
RANDOMIZE TIMER
r = INT((RND + .25) * 3250)
PSET ((r / 2), 1), 3
DRAW "l5 u5 r15 d5 l15"
PRINT "ALERT! Tank spotted"; r; "meters away"
PRINT "You have 3 shell types: "
PRINT "Short range: 100 m/s and 1,020 meter max"
PRINT "Medium range: 150 m/s 2,296 meter max"
PRINT "Long range: 200 m/s 4,081 meter max"
INPUT "(S)hort range, (M)edium range, or (L)ong range"; c\$
IF c\$ = "s" OR c\$ = "S" THEN v = 100
IF c\$ = "m" OR c\$ = "M" THEN v = 150
IF c\$ = "l" OR c\$ = "L" THEN v = 200
IF c\$ = "g" OR c\$ = "G" THEN GOTO calc
IF c\$ = "ga" OR c\$ = "GA" OR c\$ = "Ga" OR c\$ = "gA" THEN GOTO calc
INPUT "Launch angle: "; a
a = a / (180 / (22 / 7))
game:
ha = COS(a) * v
va = SIN(a) * v
FOR x = 0 TO 60 STEP .0002
y = (va - (9.8 * x)) * x
h = (ha * x)
IF y < 0 THEN GOTO done
PSET (h, y), 4
NEXT x
done:
t = (va / 9.8) * 2
d = ha * t
'd = d + (ha * .494)
IF d > r + 10 THEN GOTO miss
IF d < r - 10 THEN GOTO miss
PRINT "HIT! Enemy tank has been destroyed!"
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY\$ = ""
WEND
END
miss:
PRINT "MISS! The enemy tank has shot AND killed you "
PRINT "Distance: "; d
PRINT "Time: "; t
WHILE INKEY\$ = ""
WEND
END
calc:
IF r <= 1020 THEN v = 100
IF r <= 2296 THEN v = 150
IF r <= 4081 THEN v = 200
a = (r * 9.8)
a = a / v ^ 2
a = ATN(a / SQR(-a * a + 1)) / 2
IF c\$ = "ga" OR c\$ = "GA" OR c\$ = "Ga" OR c\$ = "gA" THEN a = 1.5707963267# - a
GOTO game

23 Oct 2011, 01:29
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.