Not entirely sure what you were after, but here are couple of codes from head, which means that i might remember some commands bit wrong.
First brush that moves with mouse pointer:
Code: Select all
loadbrush 1, "filename.png"
begindoublebuffer
repeat
x = mousex()
y = mousey()
displaybrush(1, x, y)
flip
CLS #BLACK
forever
This code will display a brush always at position where mouse pointer is.
What happens in code. First loads brush number 1, then starts double buffer (notice that you have to start double buffer before loop, or it wil lstart it again and again, and hence crashing. So first start doublebuffer, then go to loop).
at start of loop it takes mousepoitners x and y cordinates, then uses those cordinatres to display brush number 1 to same place.
However, at this point it doesnt really draw anything yet, since double buffer is activated.
But command "Flip" means that it will draw all the stuff so far drawn, and at that point you will see what is actually happening.
Right after flip comes CLS #BLACK, which clears screen to black color. Once again, you wont see this, since it wont show this until next flip comes.
To see difference without double buffer, you can remove both double buffer and flip command from code, and notice how brush keeps blinking. that is because everytime something is drawn, it will show it. In this case it will first clear screen black and show it, then draw that brush to its place, and then again clear the screen and show it...
next code:
Code: Select all
player_x = 100
player_y = 200
loadbrush 1, "filename.png"
begindoublebuffer
repeat
down = iskeydown("DOWN")
up = iskeydown("UP")
if up = 1 then player_y = player_y - 1
if down = 1 then player_y = player_y + 1
displaybrush(1, player_x, player_y)
flip
CLS #BLACK
forever
Very similar to previous code, except instead of drawing brush to where ever the mouse is, it will now be moved by arrows.
At start we first tell where player starts from, which are x-coord 100 and y-coord 200.
When we reach the loop (repeat - forever) it wil lat first check if UP or DOWN arrows are pushed down. If they are, they will report 1 (true), if not, then they will report 0 (not true). Hnece we can use this in following way.
variable "up", will get value of werher UP-arrow key is pushed down or not, same happens to variable "down" with DOWN-arrow.
After that we can simply check that if "up" is 1 (true) then y = y - 1. Notice that when you move up, y value gets smaller, and when down, y value gets bigger.
after this we simply display brush to current player_x and player_y coords.
In practice you now have player character that keeps moving up and down, but stays still on left-right movement.
then simple bullet code added to previous code: (new lines marked with arrows)
Code: Select all
player_x = 100
player_y = 200
loadbrush 1, "filename.png"
---> loadbrush 2, "bullet.png" <---
begindoublebuffer
repeat
down = iskeydown("DOWN")
up = iskeydown("UP")
--->fire = iskeydown("SPACE")<---
if up = 1 then player_y = player_y - 1
if down = 1 then player_y = player_y + 1
--->if fire = 1 and bullet=0
bullet=1<---
bullet_x = player_x
bullet_y = player_y
endif
if bullet=1
bullet_x = bullet_x + 10
if bullet_x > 1000 then bullet=0
endif<---
displaybrush(1, player_x, player_y)
--->if bullet=1 then displaybrush(2, bullet_x, bullet_y)<---
flip
CLS #BLACK
forever
What happens here now is that first of all it is checking if SPACE-button is down and record this to variable "fire"
Next it will check if "fire" is 1 (true) and in additio to this, it will also check that bullet is 0. this is our own variable, 0 meaning bullet can be fired, 1 that bullet is already on its way. With this system, we can make sure there is only one bullet flying on screen at once.
If bullet was 0 (ready to be fired) and space was pressed down, then we will move to actual laucnhing of bullet.
At this point Bullet_x and Bullet_y will be given to be same as players, making it that way seem like player is shooting that bullet. At that same we are also going to change bullet to 1, meaning that next bullet cant be shot until this bullet have ran its course.
After this, it will check if bullet is 1 (currently on its way), and if it is, then it will execute these two lines.
First adds 10 to its current x (making it move towards right) and after that checking if x is already higher than 1000, which could mean that depending upon your resolution, it have already flew out of screen. In situation like this, bullet variable is changed back to 0. Which means that next bullet can be shot again.
As last, piece of code about collision detection:
Code: Select all
col = collision(#BRUSH, 2, bullet_x, bullet_y, 3, enemy_x, enemy_y)
if col = 1
bullet = 0
enemystatus = 0
endif
This how it at its simplest goes.
Idea is that variable "col" gets the result of collision. In this case it is collision between brush number 2 (bullet) and brush number 3 (supposedly enemy brush)
if col is then 1, then that means that collision happened and following things happen:
bullet is changed to 0, so new bullet can be shot
and variable "enemystatus" is changed to 0, meaning that it is dead (this is once again similar to our "bullet" variable, that we have ourselves decided that 0 represents dead and other numbers something else, like 1 could be that it is alive)
Notice one thing here. When you do collision check, Hollywood doesnt actually look at screen wether these two collide or not. But it is doing virtual check on collision. That if brush 2 would be diplayed to this x and y, and brush 3 would be placed to this x and y, then would they collide.
That is also the reason why you need to tell the coordinates of those bruhses, instead of just the names/numbers of brushes to be checked, since Hollywood never checks collisions based upon how they are on screen, but does virtual check so to say.
Hope this helps you at least something.