Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Brick Redux

Pages: [1]
1
Tutorials / Surrounded by Zombies
« on: 2013-Aug-20 »
Heres something I knocked up in 2 hours that was inspired from an old CPC type-in game.  The CPC version had you avoiding smily faces that homed in on you in 8x8 pixel steps. 

My code gives you pixel by pixel approaching hordes that rotate to always face you.  The code could be adapted to display a tank or car very easily.

For fun Ive given the player a gun so that you can shoot them all down.  The sprites included have no transparency folks. 

Hope someone finds it useful.


LEFT/RIGHT cursors to rotate the player. UP cursor to move forward & SPACE to fire.

Code: (glbasic) [Select]
////////////////////////
//            //
//       GRUNTS    //
//                        //
///////////////////////

// Avoid the Zombies,their dying to meet you...yawn.

GOSUB setup

WHILE TRUE

move_the_grunts()

move_the_player()

shoot()

SHOWSCREEN

WEND


FUNCTION move_the_player:

IF KEY(203) // Cursor LEFT.

INC angle

ELSEIF KEY(205) // Cursor RIGHT.

DEC angle

ENDIF

IF KEY(200) // Cursor UP

DEC player_x,SIN(angle)
DEC player_y,COS(angle)

ENDIF

IF KEY(57) AND player_shot=0 // Space bar = FIRE

player_shot=1 // New shot initialised.
oldangle=angle // Get vector angle for the new bullet.

sx=player_x+SIN(oldangle) // Assign the above into
sy=player_y+COS(oldangle) // the bullets x & y projectory.

ENDIF
ROTOSPRITE 1,player_x,player_y,angle

ENDFUNCTION



FUNCTION shoot:

IF player_shot=1 // Gun has just fired.

DEC sx,shot_speed*SIN(oldangle) // Move x & y along "oldangle" vector.

DEC sy,shot_speed*COS(oldangle)

INC shot_timer // Check how long the bullets been moving.

IF shot_timer=shot_distance

player_shot=0 // Remove the bullet.

shot_timer=0 // Reset the timer.

ENDIF

PRINT "@",sx,sy // Draw the Shot on screen.

ENDIF

ENDFUNCTION



FUNCTION move_the_grunts:

SMOOTHSHADING 0

FOR a=0 TO 18

IF grunts[a].hit=0 // If not been shot yet.

  LookX = player_x - grunts[a].x // Calc the angle
        LookY = player_y - grunts[a].y // so that each grunt
        LookAtPlayer = -ATAN(LookY, LookX)-90 // faces the player.
       
ROTOSPRITE 0,grunts[a].x,grunts[a].y,LookAtPlayer
     
     INC grunts[a].timer
     
      IF grunts[a].timer=grunts[a].limit // Grunt must move...urgggh!
         
IF grunts[a].x<player_x

INC grunts[a].x,.1

ELSEIF grunts[a].x>player_x

DEC grunts[a].x,.1

ENDIF

IF grunts[a].y<player_y

INC grunts[a].y,.1

ELSEIF grunts[a].y>player_y

DEC grunts[a].y,.1

ENDIF

grunts[a].timer=0

ENDIF

// Check if a grunt has been hit.

IF BOXCOLL(sx,sy,10,10,grunts[a].x,grunts[a].y,10,10)=1
grunts[a].hit=1 // Turn the grunt off.
player_shot=0 // Reset
ENDIF

ENDIF

NEXT


ENDFUNCTION


SUB setup:

GETSCREENSIZE screenx,screeny

TYPE oinks
x
y
timer // Determines when the grunt can move...
limit // ...by reaching a time limit.
hit // Is the grunt dead (erm its already un-dead) or alive.
talk // display a line of text.
ENDTYPE

GLOBAL grunts[] AS oinks ; DIM grunts[20]

FOR a=0 TO 18

grunts[a].x=RND(screenx) ; grunts[a].y=RND(screeny)
grunts[a].timer=0 ; grunts[a].limit=5+RND(5) ; grunts[a].hit=0

NEXT

// Player data.  Not kept inside a TYPE, this is so that readers can better understand how each component works.(if needed.)

player_x=100 // XPOS.
player_y=100 // YPOS
player_speed=1 // INCREASE TO MOVE QUICKER
player_shot=0 // SHOT NOT-FIRED/FIRED FLAG
shot_timer=0 // COUNTS UNTIL IT REACHS "SHOT_DISTANCE"
shot_distance=150 // THE LIMIT A SHOT CAN TRAVEL.
shot_speed=2 //
angle=0 // USED BY THE PLAYER AND BULLET.

// CREATE A SIMPLE PLAYER SPRITE (SEEN FROM ABOVE)

DRAWRECT 0,2,24,10,RGB(0,100,255);DRAWRECT 8,0,8,8,RGB(255,255,100)
GRABSPRITE 1,0,0,24,24

// And a grunt sprite.

DRAWRECT 0,2,24,10,RGB(0,50,255);DRAWRECT 8,0,8,8,RGB(0,255,0)
GRABSPRITE 0,0,0,24,24

ENDSUB




2
Bug Reports / BETA TEST section
« on: 2013-Aug-09 »
This bug relates to the forum.

Is it time the Beta Test thread was cleaned up / streamlined, as alot of the posts their offer links to dead webpages.  Not helpful and very dissapointing when wishing to try out someones work.  I cant be the only person here whose noticed this.

 

3
2D-snippets / Sprite patterns
« on: 2013-Aug-05 »
The code below displays patterns using zoomedsprites.  Might be halpful with demos or something as a few weeks back I was watching some progs created on the old ORIC computer.  One was a tunnel effect and it quickly came to me that my first attempt at swarming sprites (aka a galaxian/spacehawk Im coding) could duplicate this.  Its wierd how your coding always seems to tie into something else and the next day after a long sleep you nail the the idea and recreate a past effect.

Its just for fun. Press a key for a new pattern.

Code: (glbasic) [Select]
SETCURRENTDIR("Media")

LOADSPRITE "bob.png",0
LOADSPRITE "bob1.png",1

that=40 ; that_too=40 ; factor=.5

WHILE TRUE

xx=320 ; yy=220 ; rx=10 ; ry=10 ; zoom=1 // Start in the centre.

FOR b=0 TO 30 // 30 times per loop.

FOR a=0 TO 359 STEP that

INC ang,that_too // This dictates the change in angle for this rotosprite.

Sprite_Path(image,xx,yy,rx,ry,ang,1,zoom)

INC image ; IF image>1 THEN image=0 // Flip between sprite 0 and 1.

NEXT

INC ang,this_too // Alter the settings for the next part of the B Loop.
INC zoom,factor
INC rx,b*2
INC ry,b*2

NEXT

SHOWSCREEN

KEYWAIT

that=RND(100) // Create a new pattern with random settings.
that_too=RND(100)

WEND

/// Early curbed path function i coded . It can roto move a sprite around an oval shape but isnt perfect. 
/// Created originally to display a galaxian swarm type affect for my current project.  Have found its
/// better to use DrawSprite and follow a DATA path when moving swarms - then jump them into their x/y
/// positions smoothly.
/// It can be used though to create "crummy" looking tunnel/vortex displays - hence this post.

/// Sprite_Path : sprite image, xpos,ypos,radiusx,radiusy,angle,direction,zoomsize

FUNCTION Sprite_Path: im%,x%,y%,rx%,ry%,deg%,dir%,size%

SMOOTHSHADING FALSE

IF dir>0

ROTOZOOMSPRITE im,rx * -SIN(deg) + x, ry * -COS(deg) + y, deg,size

INC deg

ELSEIF dir=-1

ROTOZOOMSPRITE im,rx * SIN(deg) + x, ry * COS(deg) + y, deg,size

DEC deg

ENDIF

ENDFUNCTION



Add the sprites to your media folder.

Enjoy.

4
My first ever computer game.

Played throughout Christmas in the early 80s and now in progress as a code project.  Any ideas proposed to improve or update it welcome.

Cheers

Mark.

5
2D-snippets / 3D Chequerboard in 2D
« on: 2013-Apr-25 »
Its good to be back guys and here I present a Space Harrier style floor that moves.  Needs work but thats for you lot to deal with.

Cheers.

Mark

Code: (glbasic) [Select]
/////////////////////////////////////////////////////////////////////////
//
// 3D Chequerboard in 2D
// A 50p Production
// in association with
// Jelly Babies and some coffee
//

GLOBAL dir, grid, size, jump, scale, ypos, zpos, xpos, tilex[], tiley[], tilez[], polyx[], polyy[]
GLOBAL color, whichcolor, still_free_of_ESC, needsomemorecoffee, andsomemoresugar
GOSUB setup

/////////////////////////////////////////////////////////////////////////
//
// Loop
//
//

WHILE still_free_of_ESC

GOSUB updatethegrid

GOSUB drawthegrid

SHOWSCREEN

WEND

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


SUB drawthegrid:

whichcolor=1

FOR x = 0 TO grid-2

INC whichcolor

IF whichcolor>2
whichcolor=1
ENDIF

color = whichcolor

FOR z = 0 TO grid-2

INC color

IF color>2
color=1
ENDIF

tx = tilex[x][z] / tilez[x][z]
ty = tiley[x][z] / tilez[x][z]

polyx[0]=tx ; polyy[0]=ty

tx = tilex[x+1][z] / tilez[x+1][z]
ty = tiley[x+1][z] / tilez[x+1][z]

polyx[1]=tx ; polyy[1]=ty

tx = tilex[x+1][z+1] / tilez[x+1][z+1]
ty = tiley[x+1][z+1] / tilez[x+1][z+1]

polyx[2]=tx ; polyy[2]=ty

tx = tilex[x][z+1] / tilez[x][z+1]
ty = tiley[x][z+1] / tilez[x][z+1]

polyx[3]=tx ; polyy[3]=ty
//////////////////////////////////////////////////////////////////
// Calculate color depth

shade=(ty/2)

IF shade<0
shade=50
ENDIF

IF color = 1
newcol=RGB(shade,shade,shade)
ELSE
newcol=RGB( 0,shade,0)
ENDIF

///////////////////////////////////////////////////////////////////
// Draw Tile
// cx & cy IN place but NOT used here for manipulating the board - ascend,descend,tilt left/right etc
//

STARTPOLY 0

POLYVECTOR  polyx[0]+cx,polyy[0]+cy,  0, 0,newcol

POLYVECTOR  polyx[1]+cx,polyy[1]+cy,  0, 0,newcol

POLYVECTOR  polyx[2]+cx,polyy[2]+cy,  0, 0,newcol

POLYVECTOR  polyx[3]+cx,polyy[3]+cy,  0, 0,newcol

ENDPOLY

NEXT
NEXT

ENDSUB


SUB updatethegrid:

jump = size / grid

 zpos = 8

FOR z = 0 TO grid -1

xpos = scale

FOR x = 0 TO grid -1

tilex[x][z] = xpos
tiley[x][z] = ypos
tilez[x][z] = zpos

xpos = xpos + jump * scale

NEXT

INC zpos , -jump / 20

NEXT

INC size,dir

IF size<160 AND dir=0.1

INC size , 0.1 //....scrolls the board, erm sort of....cough

ELSE

dir=-0.1

ENDIF

IF size>150 AND dir=-0.1

DEC size , 0.1

ELSE

dir=0.1

ENDIF

ENDSUB


SUB setup:

dir=0.1 ; still_free_of_ESC=TRUE

grid = 30 ; size = 150

jump = size / grid ; scale = 25 ; ypos = 400 ; zpos = 8

DIM tilex[grid][grid] ; DIM tiley[grid][grid] ; DIM tilez[grid][grid] ; DIM polyx[9] ; DIM polyy[9]

ENDSUB


ark

Pages: [1]