Darkover

Darkover

Angelic
Jul 29, 2021
4,626
C:
include eugl.ew
include winbmp.ew
include misc.e

without warning
without type_check

integer keyboard_char
keyboard_char=0

--new modual
include texture.ew
include spritesheet.ew
include font.ew
include d3d.ew as d3d
include extra.ew


global integer font0,font1,font2

global atom camera_x,camera_y,camera_z,camera_yaw
camera_yaw=90
camera_x=0
camera_y=0
camera_z=61 --values from rotmg changred from 12


atom ttt
integer facedrawn,count
integer fps
fps=0
ttt=90
facedrawn=0 
count=0

integer mousex,mousey,mouse_button
mousex=0
mousey=0
mouse_button=0
integer frames,loop_id
constant VK_END= #23, VK_HOME= #24


sequence object_bitmaps
object_bitmaps={}

atom texture1
texture1=0


procedure init()
        integer tex,spr

        --disable vsyps
    if wgl_supportsExtension("WGL_EXT_swap_control") then
        wgl_enableExtension("WGL_EXT_swap_control")
        
            if wgl_swapIntervalEXT(0) then
             end if
    end if

        d3d_start()

        d3d_set_perspective(1)

        -- Generate texture IDs
    gl_genTextures(texNum, texID)
    
        texture1=texture_load("data\\lofiEnvironment.bmp")
        spr=spritesheet_new(texture_load("data\\lofiEnvironment.bmp"),8,8)
        object_bitmaps=append(object_bitmaps,{"lofiEnvironment", spr,spritesheet_list[spr][4],spritesheet_list[spr][5]})


        font0=font_load("font.txt","data\\bitmap2.bmp")
        font1=font_load("font2.txt","data\\font2.bmp")
        font2=font_load("font3.txt","data\\font3.bmp")


        gl_enable (GL_TEXTURE_2D)

        frames = 0
    euglTimerFunc(31,loop_id,0)

        gl_enable (GL_BLEND)
        gl_blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        gl_alphaFunc(GL_GREATER,0.5)
        gl_enable ( GL_ALPHA_TEST)
        
        --gl_polygonMode(GL_FRONT_AND_BACK,GL_LINE)
 
        ewShowCursor(1)
end procedure

global constant BLACK = {0,0,0},
     BLUE  = {0,0,255},
     GREEN = {0,255,0},
     CYAN =  {0,255,0},
     RED   = {0,255,0},
     MAGENTA = {0,255,0},
     BROWN = {0,255,0},
     WHITE = {0,255,0},
     GRAY  = {0,255,0},
     BRIGHT_BLUE = {0,255,0},
     BRIGHT_GREEN = {0,255,0},
     BRIGHT_CYAN = {0,255,0},
     BRIGHT_RED = {0,255,0},
     BRIGHT_MAGENTA = {0,255,0},
     YELLOW = {0,255,0},
     BRIGHT_WHITE = {0,255,0}


-- lines for a block E
constant E = {
{{.2, 1.1, 2}, {.2, -.5, 2}, BLUE},
{{.2, -.5, 2}, {.2, -.5, -2}, YELLOW},
{{.2, -.5, -2}, {.2, 1.1, -2}, GREEN},
{{.2, 1.1, -2}, {.2, 1.2, -1.6}, BRIGHT_RED},
{{.2, 1.2, -1.6}, {.2, 1, -1.8}, BRIGHT_RED},
{{.2, 1, -1.8}, {.2, 0, -1.8}, MAGENTA},
{{.2, 0, -1.8}, {.2, 0, -.1}, BRIGHT_CYAN},
{{.2, 0, -.1}, {.2, .5, -.1}, BLUE},
{{.2, .5, -.1}, {.2, .6, -.2}, BLUE},
{{.2, .6, -.2}, {.2, .6, .2}, BLACK},
{{.2, .6, .2}, {.2, .5, .1}, BLUE},
{{.2, .5, .1}, {.2, 0, .1}, BRIGHT_BLUE},
{{.2, 0, .1}, {.2, 0, 1.8}, BRIGHT_GREEN},
{{.2, 0, 1.8}, {.2, 1, 1.8}, BRIGHT_CYAN},
{{.2, 1, 1.8}, {.2, 1.2, 1.6}, BRIGHT_CYAN},
{{.2, 1.2, 1.6}, {.2, 1.1, 2}, BRIGHT_RED},

-- opposite side:
{{-.2, 1.1, 2}, {-.2, -.5, 2}, BLUE},
{{-.2, -.5, 2}, {-.2, -.5, -2}, YELLOW},
{{-.2, -.5, -2}, {-.2, 1.1, -2}, GREEN},
{{-.2, 1.1, -2}, {-.2, 1.2, -1.6}, BRIGHT_RED},
{{-.2, 1.2, -1.6}, {-.2, 1, -1.8}, BRIGHT_RED},
{{-.2, 1, -1.8}, {-.2, 0, -1.8}, MAGENTA},
{{-.2, 0, -1.8}, {-.2, 0, -.1}, BRIGHT_CYAN},
{{-.2, 0, -.1}, {-.2, .5, -.1}, BLUE},
{{-.2, .5, -.1}, {-.2, .6, -.2}, BLUE},
{{-.2, .6, -.2}, {-.2, .6, .2}, BLACK},
{{-.2, .6, .2}, {-.2, .5, .1}, BLUE},
{{-.2, .5, .1}, {-.2, 0, .1}, BRIGHT_BLUE},
{{-.2, 0, .1}, {-.2, 0, 1.8}, BRIGHT_GREEN},
{{-.2, 0, 1.8}, {-.2, 1, 1.8}, BRIGHT_CYAN},
{{-.2, 1, 1.8}, {-.2, 1.2, 1.6}, BRIGHT_CYAN},
{{-.2, 1.2, 1.6}, {-.2, 1.1, 2}, BRIGHT_RED},

-- cross pieces:
{{.2, 1.1, 2}, {-.2, 1.1, 2}, BLUE},
{{.2, -.5, 2}, {-.2, -.5, 2}, BLUE},
{{.2, -.5, -2}, {-.2, -.5, -2}, GREEN},
{{.2, 1.1, -2}, {-.2, 1.1, -2}, GREEN},
{{.2, 1.2, -1.6}, {-.2, 1.2, -1.6}, BRIGHT_GREEN},
{{.2, .6, -.2}, {-.2, .6, -.2}, BLACK},
{{.2, .6, .2}, {-.2, .6, .2}, BLACK},
{{.2, 1.2, 1.6}, {-.2, 1.2, 1.6}, BRIGHT_GREEN}
}


procedure draw()

atom frametime,deltatime ,xx,yy,zz,xx2,yy2,zz2
integer index


d3d_set_count(0)

    frametime =current_time()

    gl_clear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT)

    --normal projection
    --d3d_set_projection(camera_x,camera_y,camera_z, camera_x+cos(camera_yaw*PI/180), camera_y-sin(camera_yaw*PI/180), camera_z, 0,0,0)
    d3d_set_projection(camera_x,camera_y,camera_z, camera_x+cos(camera_yaw*PI/180), camera_y-sin(camera_yaw*PI/180), 0, 0,0,1)

   for x=0 to 1000 by 128 do
     for y=0 to 1000 by 128 do
       --draw_texture(x,y,texture1)
     end for
   end for
  
   for i=1 to length(E) do
   xx=E[i][1][1]
   yy=E[i][1][2]
  zz=E[i][1][3]
  xx2=E[i][2][1]
  yy2=E[i][2][2]
  zz2=E[i][2][3]
 
  draw_line3d(xx,yy,zz,xx2,yy2,zz2,255,255,255)
  end for
  d3d_set_projection_ortho(0,0,800,600,0)
  d3d_set_hidden(0)



  currentfont=font0
  draw_set_color(255,0,0)
  currentfont=font1
  draw_set_color(0,255,0)

 
  d3d_set_hidden(1)

    if ewSwapBuffers(glhDC) then   
    end if

    frames += 1

    deltatime=current_time()-frametime
    
       -- ?deltatime

    if deltatime <16 then
      usleep(16-deltatime)
      --?16-deltatime
      --?deltatime
    end if



end procedure

atom start_time
start_time=time()+1

atom frametime,deltatime
frametime =current_time()

constant camera_speed =0.05


procedure loop(integer timerID)
integer ret
deltatime=current_time()-frametime
frametime =current_time()
 

  if start_time<time() then
    fps=frames
    frames = 0
    start_time=time()+1
    euglSetWindowTitle( sprintf("%d fps.",fps)&sprintf(" %f ",camera_x)&sprintf(" %f ",camera_y)&sprintf(" %f ",camera_z)&sprintf(" %d ", d3d_get_count())&sprintf(" %d ",mousex)&sprintf(" %d ",mousey) )
 
  end if

 
  if key_check(VK_LEFT) then
    camera_yaw+=4
  end if
    
  if key_check(VK_RIGHT) then
   camera_yaw-=4
  end if
 
  if key_check(VK_UP) then
    camera_z+=4
  end if
    
  if key_check(VK_DOWN) then
   camera_z-=4
  end if

  if key_check('A') then
    camera_x = camera_x + (cos (degtorad(camera_yaw+90)) *  camera_speed*deltatime)
    camera_y = camera_y + -(sin (degtorad(camera_yaw+90)) * camera_speed*deltatime)
  end if
    
  if key_check('D') then
    
    camera_x = camera_x + (cos (degtorad(camera_yaw-90)) * camera_speed*deltatime)
    camera_y = camera_y + -(sin (degtorad(camera_yaw-90)) * camera_speed*deltatime)
  end if

  if key_check('W')  then
    camera_x = camera_x + (cos (degtorad(camera_yaw)) * camera_speed*deltatime)
    camera_y = camera_y + -(sin (degtorad(camera_yaw)) * camera_speed*deltatime)
  end if

  if key_check('S')  then
    camera_x = camera_x + (cos (degtorad(camera_yaw-180)) * camera_speed*deltatime)
    camera_y = camera_y + -(sin (degtorad(camera_yaw-180)) * camera_speed*deltatime)
  end if


        
  euglTimerFunc(30,loop_id,0)
end procedure
loop_id = routine_id("loop")



procedure key(integer keycode,integer mode,integer y)
     if keycode = VK_ESCAPE then
        ewPostQuitMessage(#10)
          abort(0)
      end if

        if mode=0 then
          keyboard_char=keycode
          key_add(keycode)
        else
         key_remove(keycode)
        end if
 
end procedure

procedure mouse(integer event,integer v1,integer v2,integer v3)
  if event=EUGL_LEFT_BUTTON and v1=EUGL_DOWN then
    --puts(1,"left mouse down\n")
    mouse_button=1
  elsif event=EUGL_LEFT_BUTTON and v1=EUGL_UP then
    --puts(1,"left mouse up\n")
    mouse_button=2
  end if

end procedure



procedure motion(integer x,integer y)

  mousex=x
  mousey=y
end procedure


procedure reshape(integer w,integer h)
    --gl_viewport(0,0,w,h)
end procedure


-- Tell EuGL to use double-buffering
euglFlags = PFD_DOUBLEBUFFER   

-- If you want fullscreen, uncomment the next two lines.
-- euglPFD[EUGL_COLORBITS] = 16
-- euglDisplayMode = EUGL_FULLSCREEN   

euglDisplayFunc(routine_id("draw"))
euglInitFunc(routine_id("init"))
euglReshapeFunc(routine_id("reshape"))
euglKeyboardFunc(routine_id("key"))
euglMouseFunc( routine_id("mouse") )
euglPassiveMotionFunc( routine_id("motion") )

EuGLMain(EUGL_HANDLE_EVENTS, "open world engine", 800+10, 600+30)
 

Attachments

  • Screenshot (43).png
    Screenshot (43).png
    161.2 KB · Views: 0
  • Screenshot (44).png
    Screenshot (44).png
    170.8 KB · Views: 0
  • Screenshot (45).png
    Screenshot (45).png
    164.9 KB · Views: 0
  • Screenshot (46).png
    Screenshot (46).png
    173.3 KB · Views: 0
  • Love
Reactions: Forever Sleep
F

Forever Sleep

Earned it we have...
May 4, 2022
9,419
Cool. You could tell me it was the meaning of life and I'd believe you.

My Dad used to have a go at writing computer games way back in the day on an old Atari. He made this really cool card game once. I'd be playing and it would come up with: 'Break in line 404.' Does it still do that when something goes wrong? That old Atari was great. Pictures of bombs would come up when it was struggling and it would make this irritated 'ding' sound. We got 5 bombs once. It was like- shit! Take cover- the thing's gonna blow!

Our flatmate had an Apple Mac that would actually speak: 'It's not my fault!' I don't know why they did that because, it would just piss you off even more- like: 'So, who's fault is it? Are you saying this is my fault or, some random act of God?' I don't think I'd have the patience for programming.
 
  • Like
Reactions: Darkover and GhostShell

Similar threads

Darkover
Replies
2
Views
147
Offtopic
Darkover
Darkover
todiefor
Replies
20
Views
7K
Recovery
Rhizomorph1
Rhizomorph1
Darkover
Replies
0
Views
287
Offtopic
Darkover
Darkover
Octavia
Replies
29
Views
4K
Suicide Discussion
vanillamilkshakes
vanillamilkshakes