|
Post by johnno56 on Mar 14, 2021 13:29:37 GMT -6
Ok. Let me see if I am reading this correctly....
Most of the code I can follow. There are a couple of things I am guessing...
"hWparam wp" appears to have something to do with maybe a keyboard scan and "wp" compares the key pressed with the key code. "wmMOUSEMOVE" seems to only draw a black rectangle that is used to "erase" a small area then displays the variable "my" but I do not see where the value of "my" changes.
Other than that, I can probably see where you are going with this... I will experiment with RC and try to convert it to MicroA. I am going to assume that you will want to shoot at an "alien" as it either crosses the screen or drops down the screen.
Quick question: Do you want this game to be "text-based" or "graphics-based"? Performance is usually the difference. But, in either case, we will need "collision detection"... Moo Ha Ha....
Another quick question: How does MicroA produce random numbers and is there a command like "wait" or "delay"?
* never mind... I found a sample program: rand()... should have looked before asking... Doh!
|
|
|
Post by johnno56 on Mar 14, 2021 15:24:24 GMT -6
This what I have so far.... (in RCBasic) Tried to imitate your layout. Ignore the font file. RC looks like it will not display text in the graphics window without a font file... Any way. The player moves left to right (limited to screen 'border') Player can shoot. One bullet at a time... lol I cannot figure out why "my" is being displayed. Not critical. Created separated functions to update display, player, bullet and enemy (work in progress). This way "updateScreen" only needs to be called once. Is this what you are kind of working towards? J shooter2.zip (188 KB)
|
|
|
Post by aurel on Mar 14, 2021 16:29:00 GMT -6
thank you John ..i will see....now is very late at my side of planet so i must go sleep yes you are on right track i will explain
|
|
|
Post by johnno56 on Mar 15, 2021 7:03:25 GMT -6
I have been working on the "enemy" and have almost got that figured out. Quick question: Do you want the enemy to shoot at the player?
At the moment, I can generate an enemy and move it across the screen. The placement of the enemy can change after the enemy exits the screen. eg: May move quicker; or change its height from the ground.
Collision detection and scoring are also "in the works". Possible life system and maybe a highscore. If you can think of anything you may want, assuming of course I can do it, just let me know...
Bed-time...
J
|
|
|
Post by johnno56 on Mar 15, 2021 13:39:30 GMT -6
Cool... So it looks like you use 'swap' as a type of 'screen refresh'?
|
|
|
Post by johnno56 on Mar 15, 2021 14:42:08 GMT -6
Aurel,
I have added collision detection and a scoring system. Scoring: 100 points per hit. Subtract 50 points if missed. If score drops below zero - end of game.
Spawning the enemy is based on a random number... Still fine tuning... I will begin on allowing the enemy to shoot at the player - I hope... lol
If the player can be shot then a "life" system needs to be added... Looks like we may need a "heads up display" to keep track of lives and scores....
Of course, adding more stuff, will no longer classify the game as 'simple'... lol Eventually, if arrays can be added, then we can look at multiple bullets, enemies and even a star-field...
Another quick question. I realize that the default screen resolution is 640x480 but I am curious to know why you chose a "view" of 256x192?
|
|
|
Post by johnno56 on Mar 15, 2021 14:44:55 GMT -6
Yes. RC's update() functions much the same way as your swap.
|
|
|
Post by johnno56 on Mar 15, 2021 17:03:22 GMT -6
I used a standard "box" collision - AABB - Axis Aligned Bounding Box function collide(box1left, box1right, box1top, box1bottom, box2left, box2right, box2top, box2bottom) if (box1bottom < box2top) or (box1top > box2bottom) or (box1left > box2right) or (box1right < box2left) then collision = 0 else collision = 1 end if return collision end function Let's assume that "Box1" is the enemy and "Box2" is the bullet. used like this: collide(ex, ex+40, ey, ey+20, bx, bx+6, by, by+6) if collision = 1 then bullet has hit enemy note: ex+40 is the x position of the enemy plus the width of the enemy etc ey+20 is the y position of the enemy + the height of the enemy. The same applies for the bullet. bx and by. You may have to initialize 'collision' before the function? eg collision=0 It looks a bit complicated but, in short, the function checks to see if the boxes are overlapping. If they do... collision. I hope this helps. ps: There is probably a simpler method but at least this one works. Also. I have a function for detecting collisions between circles and a function for detecting collisions between circles and rectangles. Best start with AABB.... shooter3.zip (188.49 KB) This where I am up to.... Collision, Lives and Scoring I was toying with the idea that the speed of the enemy would start off slowly and as the score increases so will the speed of the enemy. What do you think? Just an idea. I don't want to add too much... lol
|
|
|
Post by n00b on Mar 16, 2021 12:11:59 GMT -6
Does Micro(A) support recursive function calls? If so, are you pushing your program's state onto a stack?
|
|
|
Post by johnno56 on Mar 16, 2021 13:04:00 GMT -6
I am glad that you two know what you are talking about... It's all Greek to me... lol Have a great day!
|
|
|
Post by n00b on Mar 17, 2021 9:13:48 GMT -6
aurel I tried this out. It works pretty well. I thought I would point out that most programming languages would implement a stack for the program state. I modified your example to demonstrate what I am talking about. 'func test recurs var a , b : a = 1 : b = 600 print 10,50,"function recursive" fnRecursive() ' this function recursively call himself if ' condition inside func(subroutine) is TRUE func fnRecursive() b = b - 1 var c : c = c + 1
'recursive call If b > 10 fcolor 80,80,100 rect 90,90,68,24 fcolor 100,160,100 print 90, 90, c fnRecursive() endif var cy : cy = 70 + (c-590)*14 fcolor 100,160,100 print 90, cy, c 'This should print 590 times 'By the time the last print is done c should be 0 endfn I made a quick test with a variable c which should be local to the function. First time the function is called c will be set to 1. By the time b <= 10, c will be 590. But if all these functions existed on a stack, then the previous functions state would be popped off the stack on return. Which means by the time it was all done, c would be 1. The way your interpreter currently works, something like a fill routine or any other algorithm requiring recursion would not be possible because the previous function state is never restored and it doesn't seem to return from previous function calls inside the recursive loop.
|
|
|
Post by n00b on Mar 18, 2021 2:09:36 GMT -6
Here is a simpler example I found in python and converted to RCBasic and Micro(A).
RCBasic and Python both return 6 but Micro(A) returns 2.
Note: I tried to keep it as close to line by line conversion as possible but if there was a mistake in the Micro(A) code just let me know.
Python:
def factorial(x): """This is a recursive function to find the factorial of an integer"""
if x == 1: return 1 else: return (x * factorial(x-1))
print("The factorial of 3 is ", factorial(3))
RCBasic:
function factorial(x) '"""This is a recursive function 'to find the factorial of an integer"""
if x = 1 then return 1 else return (x * factorial(x-1)) end if end function
print "The factorial of 3 is "; factorial(3)
Micro(A)
var x : x = 3 var return
func factorial() '"""This is a recursive function 'to find the factorial of an integer"""
if x = 1 return=1 else return=(x * factorial(x-1)) endif endfn
factorial(3) print 10, 10, " The factorial of 3 is " print 200, 10, return
|
|
|
Post by n00b on Mar 18, 2021 11:37:34 GMT -6
I just tested this and its getting the right result for 3. But it still isn't working properly. Try changing 3 to 7 and run it. 7 has a factorial of 5040. RCBasic, Python, and the Google Calculator will all return 5040 but your example will return 42.
I am not saying that a internal stack implementation is the right way to go either. There are examples of Macro languages that don't implement a stack for functions. But this is problem that should be solvable in the interpreter in my opinion.
|
|
|
Post by johnno56 on Mar 18, 2021 13:13:14 GMT -6
Hey! According to "The Hitchhiker's Guide to the Galaxy" you have found the "meaning of everything". "42" is the meaning of everything... Cool...
|
|
|
Post by aurel on Mar 18, 2021 16:11:40 GMT -6
yes this way work but i need to add stack or macro function(maybe better)
'factorial micro(A)
var value ,res 'value
var number : number = 7
var fact : fact = 1
value = 1
print 10, 10, "The factorial of -> " :
print 180,10,number
factorial()
func factorial()
if value < number
value = value + 1
fact = fact * value
rect 8,190,100,32 :fcolor 220,220,100: print 10,200,fact : res = fact
factorial()
endif
endfn
|
|