Author Topic: Soviet Hunter  (Read 1922 times)

Goettsch

  • Newcomer
  • *
  • Posts: 8
    • View Profile
Soviet Hunter
« on: 18. June 2013, 14:26:11 »
A new shooter made with naalaa,the source is included,you can modify it and add new features if you want,probably there are some bugs and everything is a bit messed up


credits: Marcus for the tutorial and kevin for helping me adjust some big problems and the sounds are from Marcus tutorial I didn't change them

« Last Edit: 19. June 2013, 00:03:31 by Goettsch »

kevin

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Soviet Hunter
« Reply #1 on: 18. June 2013, 18:55:56 »
Well done for getting a game up so quickly.....seems to play fine here. First thing I would add is a display of the lives left:
Code: [Select]
set caret 100,5
set color 255,0,0
center "Lives left   ",lives
set color 255,255,255
This should be added to the bottom of the main loop.....
Modifying other peoples code is a great way to get started...other tips I was given and find really useful are to keep game logic, drawing routines and so on in their own sections....also to make use of procedures where possible.....both make it a lot easier to keep track of a program and to resolve the inevitable problems when they crop up.......
The forum is used by people that have a lot more knowledge than I and you will normally get quick answers from one of these people, so I would encourage you to use it.....
« Last Edit: 18. June 2013, 19:16:25 by kevin »

Goettsch

  • Newcomer
  • *
  • Posts: 8
    • View Profile
Re: Soviet Hunter
« Reply #2 on: 18. June 2013, 23:32:37 »
I added the code you said at the bottom of the main loop but it doesn't work

kevin

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Soviet Hunter
« Reply #3 on: 19. June 2013, 05:59:04 »
Probably added to the wrong place - check this attachment and place it there - note I needed to changed the screen resolution - I use an old laptop.......if it doesn't work, please let us know what error message you get......
« Last Edit: 19. June 2013, 06:01:06 by kevin »

Goettsch

  • Newcomer
  • *
  • Posts: 8
    • View Profile
Re: Soviet Hunter
« Reply #4 on: 19. June 2013, 12:46:02 »
yes,wrong place  :o

here is the version 1.1

Marcus

  • Globaler Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
    • NaaLaa
Re: Soviet Hunter
« Reply #5 on: 19. June 2013, 19:40:07 »
I had to change some things in the latest version to make it look ok here. The first thing I did was to scale down the game background image in GIMP with 50% so that it has the same size as the other screens (680x384). I then changed the window setup from

Code: [Select]
set window 1, 1, 1360, 768, true, 2
to

Code: [Select]
set window 1, 1, 680, 384
But that's just because I don't have a widescreen monitor. I suggest you try with both:

Code: [Select]
set window 1, 1, 680, 384, true
and

Code: [Select]
set window 1, 1, 680, 384, true, 2
I'd be very interested in hearing what sort of results those settings give :) This is actually a big bad in NaaLaa: you can't tell what the actual desktop resolution is to determine weather it's widescreen or not. I promise to add a fix for that  :)

Also, when drawing the background image your code looked like this:

Code: [Select]
draw image BACK_GROUND_IMAGE
It should be:

Code: [Select]
draw image BACK_GROUND_IMAGE, 0, 0
Because if you omitt the coordinates naalaa assumes you're using "image transformations" (translate/scale/rotate, like turtle graphics), and that's not needed here :) (When using your code, the image was drawn centered at the coordinates 0, 0).

This is the modified code. I've marked my changes with "EDIT" and attached the downscaled background image.

Code: [Select]
rem ==================================================================
rem---------------------------Soviet Hunter---------------------------
rem-------------------------------------------------------------------
rem-------------------------------------------------------------------
rem-----A shooting game by Goettsch using a tutorial by Marcus--------
rem ==================================================================


rem Import libraries.
import "Speed.lib"
import "Keycodes.lib"

constant:
rem Images.
BG_IMAGE 0
PLAYER_IMAGE 1
ENEMY_IMAGE 2
PLAYER_BULLET_IMAGE 3
ENEMY_BULLET_IMAGE 4
   BACK_GROUND_IMAGE    5
   END_IMAGE            6
   MENU_IMAGE           7

rem Sound effects.
PLAYER_SHOOT_SOUND 0
HIT_SOUND 1
ENEMY_SHOOT_SOUND 2
ENEMY_BOOM_SOUND 3


rem Enemy array fields.
ENM_ACTIVE 0
ENM_BULLET_X 1
ENM_BULLET_Y 2

hidden:

rem EDIT: Changed the window setup a little to work with my monitor.
set window 1, 1, 680, 384

set redraw off

rem Load enemies and set their color keys.
load image PLAYER_IMAGE, "data/player.bmp"
load image ENEMY_IMAGE, "data/enemies.bmp"
load image PLAYER_BULLET_IMAGE, "data/bullet.bmp"
load image ENEMY_BULLET_IMAGE, "data/enemy_bullet.bmp"
load image BACK_GROUND_IMAGE, "data/background.bmp"
load image END_IMAGE, "data/endscreen.bmp"
load image MENU_IMAGE, "data/menu.bmp"
set image colorkey PLAYER_IMAGE, 0, 0, 0
set image colorkey ENEMY_IMAGE, 0, 0 ,0
set image colorkey PLAYER_BULLET_IMAGE, 0, 0 ,0
set image colorkey ENEMY_BULLET_IMAGE, 0, 0 ,0
set image grid ENEMY_IMAGE, 0, 0

rem Load sound effects.
load sound PLAYER_SHOOT_SOUND, "data/player_shoot.wav"
load sound HIT_SOUND, "data/hit.wav"
load sound ENEMY_SHOOT_SOUND, "data/enemy_shoot.wav"
load sound ENEMY_BOOM_SOUND, "data/enemy_boom.wav"

rem small menu
do
set color 0,0,0
cls
set color 255,255,255
      draw image MENU_IMAGE,0,0
redraw

until keydown(VK_SPACE)


rem Enemy array:
rem enemies[x][y][ ENM_ACTIVE, ENM_BULLET_X, ENM_BULLET_Y]
enemies[21][3][3]

rem Init enemies.
for y = 0 to 2
for x = 1 to 20
enemies[x][y][ENM_ACTIVE] = true
enemies[x][y][ENM_BULLET_X] = -1
next
next

rem All enemies share a position and movement.
enemiesX = 0
enemiesY = 20
enemiesDX = 3
enemiesDropY = 0
enemyMoveTimer = 0
enemyFrame = 0
enemyShootTimer = 100

rem Player
playerX = (width(primary) - width(PLAYER_IMAGE))/2
playerY = 260
bulletX = -1
bulletY = 0
lives=3

 
do
 
rem Update logic.

rem Enemies.
if enemiesDropY = 0
enemyMoveTimer = (enemyMoveTimer + 1)%4
if enemyMoveTimer = 0
enemiesX = enemiesX + enemiesDX
if enemiesX > 400 or enemiesX < 1
enemiesDX = -enemiesDX
enemiesDropY = 6
endif
enemyFrame = 5 - enemyFrame
endif
else
enemiesY = enemiesY + 1
enemiesDropY = enemiesDropY - 1
endif

rem Enemy bullets.
enemyShootTimer = max(enemyShootTimer - 1, 0)
if enemyShootTimer = 0
rem Find possible shooters. Only the bottom enemies may shoot
possible[21][2]
possibleCount = 0
for x = 0 to 20
enmY = -1
for y = 0 to 2
if enemies[x][y][ENM_ACTIVE] and enemies[x][y][ENM_BULLET_X] = -1
enmY = y
endif
next
if enmY >= 0
possible[possibleCount][0] = x
possible[possibleCount][1] = enmY
possibleCount = possibleCount + 1
endif
next

if possibleCount > 0
rem Chose an enemy.
i = rnd(possibleCount)
enemies[possible[i][0]][possible[i][1]][ENM_BULLET_X] = enemiesX + possible[i][0]*10 + 4
enemies[possible[i][0]][possible[i][1]][ENM_BULLET_Y] = enemiesY + possible[i][1]*10 + 8
enemyShootTimer = 60 + rnd(60)
play sound ENEMY_SHOOT_SOUND
endif
endif

for y = 0 to 2
for x = 0 to 20
if enemies[x][y][ENM_BULLET_X] >= 0
enemies[x][y][ENM_BULLET_Y] = enemies[x][y][ENM_BULLET_Y] + 8
rem Out of the window.
if enemies[x][y][ENM_BULLET_Y] >= 450
enemies[x][y][ENM_BULLET_X] = -1
else
rem Check for collision with player.and end the game if lives <0
bx = enemies[x][y][ENM_BULLET_X] + 1
by = enemies[x][y][ENM_BULLET_Y] + height(ENEMY_BULLET_IMAGE)
if bx >= playerX and bx < playerX + width(PLAYER_IMAGE)
if by >= playerY and by < playerY + height(PLAYER_IMAGE)
enemies[x][y][ENM_BULLET_X] = -1
       play sound HIT_SOUND
                                      lives=lives-1
                                            if lives=0 then

do
set color 0,0,0
cls
set color 255,255,255
      draw image END_IMAGE,0,0
redraw
until keydown (VK_ESC)
                      endif
endif
endif
endif
endif
next
next

rem Player.
if keydown(VK_LEFT) then playerX = max(playerX - 2, 0)
if keydown(VK_RIGHT) then playerX = min(playerX + 2, 645)

rem Player bullet.
if bulletX >= 0
rem Move up.
bulletY = bulletY - 7
rem Check for collision with enemies.
x = ((bulletX + 1) - enemiesX)/10
y = (bulletY - enemiesY)/10
if x >= 0 and x < 21 and y >= 0 and y < 3
if enemies[x][y][ENM_ACTIVE]
enemies[x][y][ENM_ACTIVE] = false
bulletX = -1
play sound ENEMY_BOOM_SOUND       
endif
endif
rem Out of window?
if bulletY < -height(PLAYER_BULLET_IMAGE) then bulletX = -1
elseif keydown(VK_SPACE, true)
rem Shoot.
bulletX = playerX + 4
bulletY = playerY - 5
play sound PLAYER_SHOOT_SOUND
endif

rem Draw.

rem Background.
rem EDIT: You forgot the coordinates,
rem draw image BACK_GROUND_IMAGE
draw image BACK_GROUND_IMAGE, 0, 0

rem Enemies.
set color 255, 255, 255
for y = 0 to 2
for x = 0 to 20
if enemies[x][y][ENM_ACTIVE]
draw image ENEMY_IMAGE, enemiesX + x*10, enemiesY + y*10, y + enemyFrame
endif
if enemies[x][y][ENM_BULLET_X] > 0
draw image ENEMY_BULLET_IMAGE, enemies[x][y][ENM_BULLET_X], enemies[x][y][ENM_BULLET_Y]
endif
next
next

rem Player
draw image PLAYER_IMAGE, playerX, playerY

rem Player bullet.
if bulletX >= 0
draw image PLAYER_BULLET_IMAGE, bulletX, bulletY
endif

set caret 100,5
set color 255,0,0
center "Lives left   ",lives
set color 255,255,255

proc SPD_HoldFrame 30
redraw
until keydown(VK_ESC) or not running()
« Last Edit: 19. June 2013, 19:42:56 by Mopz »

cvirus

  • Regular Member
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Soviet Hunter
« Reply #6 on: 19. June 2013, 21:42:36 »
Hey Mopz, you could implement something like this in c.

Code: [Select]
#include "windows.h"

INT32 GetDeskTopHeight();
INT32 GetDeskTopWidth();

int main(int argc, const char* argv[])

{
printf("width = %i\n",GetDeskTopWidth());
  printf("height = %i\n",GetDeskTopHeight());
getchar();
return 0;
}

INT32 GetDeskTopHeight()
{
  INT32 width = GetSystemMetrics(SM_CXSCREEN);
  return width;
}

INT32 GetDeskTopWidth()
{
  INT32 height = GetSystemMetrics(SM_CYSCREEN);
  return height;
}

And then in NaaLaa something like

Code: [Select]
sytemwidth = GetDeskTopWidth()
systemheight = GetDeskTopHeight()


set window 1, 1, sytemwidth , systemheight

This way the fullscreen is allways like the screen resolution and nothing else i think :)
« Last Edit: 19. June 2013, 21:44:47 by cvirus »

Marcus

  • Globaler Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
    • NaaLaa
Re: Soviet Hunter
« Reply #7 on: 20. June 2013, 17:47:10 »
Thanks cvirus! Now I don't have to visit that darned msdn place :)

Goettsch

  • Newcomer
  • *
  • Posts: 8
    • View Profile
Re: Soviet Hunter
« Reply #8 on: 20. June 2013, 23:50:36 »
Thanks,

set window 1, 1, 680, 384, true, 2, the game become full screen
 
set window 1, 1, 680, 384, true, it remains a small window

JSM

  • Regular Member
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Eggplant on Wheels
Re: Soviet Hunter
« Reply #9 on: 22. June 2013, 11:14:29 »
glad to see someone posting a game :)
I certainly am an eggplant on wheels ...
http://www.eggplantonwheels.net